Explicite Local EJB not introduced with Arkillian

I use Arquillian to test a non-bean session that has an explicit local and remote interface. But in the test, Arkillian does not "inject" anything into a field that has the type of a local interface, but works for a remote interface.

@Stateless public class TestServiceImpl implements TestServiceLocal, TestServiceRemote { public String greet() { return "hallo"; } } 

Remote Interface:

 @Remote public interface TestServiceRemote { public String greet(); } 

Locale Interface:

 @Local public interface TestServiceLocal { public String greet(); } 

And this is the test:

 @RunWith(Arquillian.class) public class GenericEntityDaoEjbIntegrationTest { @Deployment public static JavaArchive createTestArchive() throws UnsupportedEncodingException { return ShrinkWrap.create(JavaArchive.class, "test.jar") .addClasses( TestServiceLocal.class, TestServiceRemote.class, TestServiceImpl.class); } @EJB private TestServiceLocal testServiceLocal; @EJB private TestServiceRemote testServiceRemote; //Will Fail @Test public void testTestServiceLocal() { assertNotNull(this.testServiceLocal); } //Success @Test public void testTestServiceRemote() { assertNotNull(this.testServiceRemote); } } 

I am using arquillian-glassfish-embedded 1.0.0.CR2, glassfish-embedded-all 3.1 and arquillian-junit-container 1.0.0.CR5. Relevant part of my pom:

  <!-- arquillian test --> <dependency> <groupId>org.jboss.arquillian.junit</groupId> <artifactId>arquillian-junit-container</artifactId> <version>1.0.0.CR5</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-container-spi</artifactId> <version>1.0.0.CR5</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-glassfish-embedded-3.1</artifactId> <version>1.0.0.CR2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.glassfish.extras</groupId> <artifactId>glassfish-embedded-all</artifactId> <version>3.1</version> <scope>test</scope> </dependency> 

This is the corresponding part of the log file (it does not contain any exceptions):

 10.04.2012 15:38:16 com.sun.ejb.containers.BaseContainer initializeHome INFO: Portable JNDI names for EJB TestServiceImpl : [java:global/test/TestServiceImpl!de.test.service.TestServiceRemote, java:global/test/TestServiceImpl!de.test.service.TestServiceLocal] 10.04.2012 15:38:16 com.sun.ejb.containers.BaseContainer initializeHome INFO: Glassfish-specific (Non-portable) JNDI names for EJB TestServiceImpl : [de.test.service.TestServiceRemote, de.test.service.TestServiceRemote#de.test.service.TestServiceRemote] 10.04.2012 15:38:16 com.sun.enterprise.web.WebApplication start INFO: WEB0671: Loading application [test] at [/test] 10.04.2012 15:38:16 org.glassfish.deployment.admin.DeployCommand execute INFO: test was successfully deployed in 11.844 milliseconds. 

What's my mistake? What do I need to change to get the instance entered for the locale interface?

+6
source share
3 answers

You can use one of the following actions:

  • Add the beans.xml file to the beans.xml :

     return ShrinkWrap.create(JavaArchive.class, "test.jar") .addClasses( TestServiceLocal.class, TestServiceRemote.class, TestServiceImpl.class) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); 

    This allows Arquillian's CDITestEnricher, which is much more efficient than EJBTestEnricher. It can handle @Inject annotations (obviously), as well as @Resource and @EJB (see "Entering Resources in the CDI Specification"). The container then processes both the annotated @EJB fields in your instance of the test class and the injection points and inserts the dependencies.

  • Specify the mappedName property for the mappedName annotation for the field with the portable JNDI name of the expanded bean. In your case, it will look something like this:

     @EJB(mappedName="java:global/test/TestServiceImpl!com.acme.TestServiceLocal") private TestServiceLocal testServiceLocal; 

    You need to make sure that the portable JNDI name matches the name generated for deployment. I just pointed out the one that was created for my interface "com.acme.TestServiceLocal".

+12
source

In addition to the answers, you should also make sure that you are using the correct @Deployment setting. To add locally, you need to make sure you have @Deployment(testable=true) (note that this is the default value).

From Aquilan documents :

Container Mode: @Deployment (testable = true)

As we mentioned above, we need to repackage your @Deployment by adding some Arquillian support classes to run in the container. This gives us the ability to communicate with the test, enrich the test and run the test remotely. In this mode, the test is performed on the remote control container; Arkiljan uses this mode by default.

See the full protocol protocol for an overview of the expected output of the packaging process when you provide @Deployment.

Client mode: @Deployment (testable = false)

Now this mode is the easy part. Unlike the intra-container mode, which repackages and redefines the execution of the test, the as-client mode does as little as possible. It does not repackage your @Deployment, nor does it redirect test execution to a remote server. Your test case is working in your JVM, as expected, and you can test the container from the side, as your clients see. The only thing Arkillian is is to control the life cycle of your @Deployment.

Here is an example of calling a servlet using client mode.

This does not help the OP (they had the correct settings), but I hope that it helps those who come from Google, like me.

+5
source

Try changing TestServiceImpl-> TestServiceBean it looks like the built-in glass fish have special bean name requirements

+1
source

Source: https://habr.com/ru/post/912853/


All Articles