1 2 Previous Next 16 Replies Latest reply on Nov 27, 2010 9:01 AM by Aslak Knutsen

    arquillian EJB unit testing, JBoss 5.0.1 CR2 EAP, EJB JNDI lookup fails

    Jitendra Kumar Newbie

      Hi All,

       

      I have set up Arquillian in my Eclipse. I have all the JARs (ALPHA4) required to run the test. I am using the below code to test Session Bean method.

       

      I am using @Run(RunModeType.IN_CONTAINER) and arquillian.xml file in classpath. Arquillian starts JBoss properly but not sure whether it deploys correctly. The code is something like this:

       

       

      package com.sonymusic;
      import java.util.ArrayList;
      import java.util.Collection;
      import javax.ejb.EJB;
      import org.jboss.arquillian.api.Deployment;
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.arquillian.api.Run;
      import org.jboss.arquillian.api.RunModeType;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.spec.JavaArchive;
      import org.junit.Assert;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      import com.sonymusic.dx.ejb.interceptors.NullParameterInterceptor;
      import com.sonymusic.dx.ejb.utility.facades.MasterFacadeLocal;
      import com.sonymusic.dx.ejb.utility.facades.impl.MasterFacade;
      import com.sonymusic.dx.jpa.dx.enums.AssetPreviewType;
      @RunWith(Arquillian.class)
      @Run(RunModeType.IN_CONTAINER)
      public class TestMasterFacade {
           @Deployment
           public static JavaArchive createTestArchive() {
              return ShrinkWrap.create(JavaArchive.class, "test.jar")
                 .addClasses(MasterFacade.class, NullParameterInterceptor.class, MasterFacadeLocal.class,
                     AssetPreviewType.class).addManifestResource("persistence.xml");
           }
           @EJB
           private MasterFacadeLocal masterFacade;
           @Test
           public void shouldBeAbleToInjectEJB() throws Exception {
              Collection<String> masterIds = new ArrayList<String>();
              masterIds.add("");
              Assert.assertNotNull(masterFacade.getIconPreviewsForMasterIds(masterIds));
           }
      }

       

           @Deployment

           public static JavaArchive createTestArchive() {

              return ShrinkWrap.create(JavaArchive.class, "test.jar")

                 .addClasses(MasterFacade.class, NullParameterInterceptor.class, MasterFacadeLocal.class,

                     AssetPreviewType.class).addManifestResource("persistence.xml");

           }

       

       

           @EJB

           private MasterFacadeLocal masterFacade;

       

           @Test

           public void shouldBeAbleToInjectEJB() throws Exception {

              Collection<String> masterIds = new ArrayList<String>();

              masterIds.add("");

              Assert.assertNotNull(masterFacade.getIconPreviewsForMasterIds(masterIds));

           }

      }

      I get exception stack trace when running the test:
      org.jboss.arquillian.impl.event.FiredEventException: java.lang.RuntimeException: Could not inject members
      at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:68)
      at org.jboss.arquillian.impl.context.AbstractEventContext.fire(AbstractEventContext.java:115)
      at org.jboss.arquillian.impl.EventTestRunnerAdaptor.before(EventTestRunnerAdaptor.java:127)
      at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:206)
      at org.jboss.arquillian.junit.Arquillian$5$1.evaluate(Arquillian.java:225)
      at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:297)
      at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:221)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:163)
      at org.jboss.arquillian.junit.Arquillian$3$1.evaluate(Arquillian.java:186)
      at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:297)
      at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:182)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:127)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
      at org.jboss.arquillian.junit.JUnitTestRunner.execute(JUnitTestRunner.java:69)
      at org.jboss.arquillian.protocol.servlet_2_5.ServletTestRunner.doGet(ServletTestRunner.java:84)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.RuntimeException: Could not inject members
      at org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher.injectClass(EJBInjectionEnricher.java:128)
      at org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher.enrich(EJBInjectionEnricher.java:50)
      at org.jboss.arquillian.impl.handler.TestCaseEnricher.callback(TestCaseEnricher.java:42)
      at org.jboss.arquillian.impl.handler.TestCaseEnricher.callback(TestCaseEnricher.java:32)
      at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)
      ... 45 more
      Caused by: javax.naming.NamingException: No EJB found in JNDI, tried the following names: java:global/test.ear/test/MasterFacadeLocalBean, java:global/test.ear/test/MasterFacadeLocal, java:global/test/MasterFacadeLocal, java:global/test/MasterFacadeLocalBean, java:global/test/MasterFacadeLocal/no-interface, test/MasterFacadeLocalBean/local, test/MasterFacadeLocalBean/remote, test/MasterFacadeLocal/no-interface, MasterFacadeLocalBean/local, MasterFacadeLocalBean/remote, MasterFacadeLocal/no-interface,
      at org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher.lookupEJB(EJBInjectionEnricher.java:162)
      at org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher.injectClass(EJBInjectionEnricher.java:102)
      ... 49 more
      In same setting I am able to run Arquillian demo example GreetingManager session bean without any problem. Not sure what is missing in the above scenario where it is unable to do JNDI lookup. My guess is that it is not deploying EJB properly and that is why it is not able to inject. Any help will be appreciated.
      Regards,
      Jitendra

        1 2 Previous Next