jeudi 25 juin 2015

Integration tests fails if run via maven, but passes if run via IDE

I have an acceptance test module that does an ejb call to another module. But for this acceptance test, I don't want it call the ejb directly as this may cause my tests to be very slow. So to over come that, I used SimpleNamingContextBuilder to mock the JNDI call. For my acceptance test, I am using Cucumberframework.

I created my own annotation @mockJNDIServices, the java method that does the JNDI looks like

@Before("@MockJndiEntityService")
public void mockJndiService() throws NamingException {
    final EjbServiceRemote ejbService = new EjbServiceRemoteStubImpl();
    final SimpleNamingContextBuilder contextBuilder = new SimpleNamingContextBuilder();

    contextBuilder.bind(EjbServiceRemote.EJB_NAME, ejbService);
    contextBuilder.activate();
}

EjbServiceRemoteStubImpl is a stub I would like tests to call instead of the service itself.

and the feature file has the heading

@MockJndiEntityService
@transaction
Feature: Lookups from library of policy

When I run this code via the IDE (Intellij), it works fine and everything passes. But when I run it through the build tool (Maven), I get the remote lookup failure

Caused by: javax.naming.NameNotFoundException: Name [ejb/EjbServiceEJB#ejb.service.EjbServiceRemote] not bound; 1 bindings: [ejb/EjbServiceEJB#ejb.service.EjbServiceRemote

It seems like the annotation is not being applied for each feature/scenarios.

Has anyone ever came across this? your help will be much appreciated.

Aucun commentaire:

Enregistrer un commentaire