How to configure the JUnit component of Demoiselle 2.4.2 to inject EJB dependencies

1

I have a Demoiselle 2.4.2 / JSF / Hibernate application that presents several fully functioning test cases. The BCs operated by these test cases undergo several injections of dependence without any problem. Now I needed the injection of an EJB client, as shown in the code below:

@BusinessController
public class MeuBC implements Serializable {
    private static final long serialVersionUID = 1L;

    @Inject
    private SecurityServices securityServices;
    @Inject
    private TipoVinculoBC tipoVinculoBC;

    @EJB(lookup=Constantes.EXTERNAL_SERVICE_JNDI)
    private ExternalService EXTERNALService; // <=== Preciso desta injeção!!!

    // Restante da classe
}

In the example, we have TipoVinculoBC being injected without problem. However, during tests only (runs on running the application) ExternalService is not injected, remaining with null at runtime, resulting in error.

I stress that is not integration testing , ExternalService is not in test , it's just a service that MeuBC depends on any other API), so it is a unit test of MeuBC .

What is missing so that DemoiselleRunner or other participant can enable the client injection of ExternalService ?

    
asked by anonymous 24.05.2017 / 15:55

1 answer

1

Alex, the CDI, who does the injecting of @Inject , even in the unit test, does not support annotations specific EJB .

The suggestion is you create a Producer that gets your object from the EJB context in order to use @Inject in classes that need this dependency.

Note that this is not a limitation of DemoiselleRunner , but of CDI itself.

    
25.05.2017 / 14:37