Not sure if I understand your concern correctly, but to perform integration tests with EJBs you need both things:
1. At first you need to make OpenEJB aware of any EJBs it can provide in the forthcoming test. That's what the ejbJar.addEnterpriseBean(new StatelessBean(MyService.class));
part is for.
2. Secondly, you specify all the EJB injections used by your test directly, just in the same manner, as you would do in your normal code. Remember that, if the EJB you are invoking in your test is dependent on any other EJBs, you need to specify all of them using the .addEnterpriseBean()
method. Example:
public class SomeProcessingServiceIntegrationTest extends AbstractOpenEJBTestNG {
@EJB
SomeProcessingServiceLocal processingService;
@Module
public EjbModule beans() {
EjbJar ejbJar = new EjbJar("processing");
OpenejbJar openejbJar = new OpenejbJar();
ejbJar.addEnterpriseBean(new StatelessBean(SomeProcessingService.class));
ejbJar.addEnterpriseBean(new StatelessBean(DatabaseLookupService.class));
}
@Test
public void testProcessingService(){
// Should return true for example
assertTrue(processingService.process());
}
}
@Stateless
@Local(SomeProcessingServiceLocal.class)
public class SomeProcessingService {
@EJB
DatabaseLookupServiceLocal databaseLookupService;
public boolean process(){
return databaseLookupService.existsInDB();
}
}