I have this scenario:
- Enterprise Application. Runs ok. --> contains MyFacade
- Client application. Runs ok.
- Ejb module. Runs ok, but can't test --> contains MyClass.java
- DomainLibrary. --> contains entities and remote interfaces.
I want to run test file of point 3. (ejb module). Ok, first of all I put the Enterprise Application running. On second place I run the test file of the point 3. The problem is that the remote interface ejb contained on Enterprise Application can't be found.
Error 1: It end up with an endless loop of the following output
WARNING: AS-CDI-005 Okt 22, 2013 4:49:23 PM org.glassfish.weld.BeanDeploymentArchiveImpl handleEntry
Error 1: Solved Running JUnit Tests on embedded glassfish 4 causing WARNING: AS-CDI-005
Error 2!!!:
javax.naming.NamingException: Lookup failed for [...] (MyFacade)
Ejb module: MyClass.java
@Singleton
public class MyClass implements MyClassLocal {
@EJB(lookup = "java:global/EnterpriseApplication-ejb/MyFacade!com.mydomain.repository.MyFacadeRemote")
private MyFacadeRemote myFacade;
public MyClass() {
}
public void bussinesMethod(){
System.out.println("Hello stackOverWorld! ");
myFacade.findAll();
}
}
Test method:
@Test
public void testBusinessMethod() throws Exception {
System.out.println("businessMethod");
Map<Object, Object> properties = new HashMap<Object, Object>();
properties.put(EJBContainer.APP_NAME, "MyEjbModule");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
EJBContainer container = EJBContainer.createEJBContainer(properties);
MyClassLocal instance = (MyClassLocal)container.getContext().lookup("java:global/MyEjbModule/classes/MyClass!com.mydomain.MyClassLocal");
//EJBContainer container = javax.ejb.embeddable.EJBContainer.createEJBContainer();
//MyClassLocal instance = (MyClassLocal)container.getContext().lookup("java:global/classes/MyClass");
instance.businessMethod();
container.close();
}