4 Replies Latest reply on Nov 9, 2012 6:37 AM by Aslak Knutsen

    Lookup of EJBContext via JNDI with Arquillian possible?

    Thomas T Newbie

      Hi,

       

      I downloaded the arquillian-tutorial example project from here:

       

      https://github.com/arquillian/arquillian-examples/tree/master/arquillian-tutorial

       

      In a project where I try to use Arquillian for persistence/container testing there is an EntityListener that looks up a EJBContext via JNDI.

      Therefore I added the following test method to the arquillian-tutorial project in the {code}GreeterTest.java{code} to simulate the production code:

       

      import javax.ejb.EJBContext;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      ...
      
      @Test
      public void testEJBContext() throws NamingException {
           final InitialContext initialContext = new InitialContext();
           final EJBContext context = (EJBContext) initialContext.lookup("java:comp/EJBContext");
           assertNotNull(context);
       }
      
      

       

      With every maven profile that is defined (arquillian-weld-ee-embedded, arquillian-glassfish-embedded and arquillian-jboss-managed) I get the following errors when I run

      mvn clean test
      

       

      with arquillian-weld-ee-embedded:

       

      javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
                at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
                at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
                at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
                at javax.naming.InitialContext.lookup(InitialContext.java:411)
                at org.arquillian.example.GreeterTest.testEJBContext(GreeterTest.java:65)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
                at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)
                at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
                at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
                at org.jboss.arquillian.container.test.impl.client.protocol.local.LocalContainerMethodExecutor.invoke(LocalContainerMethodExecutor.java:50)
                at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:120)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
                at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
                at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:57)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)
                at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:129)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)
                at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)
                at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)
                at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)
                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:185)
                at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
                at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
                at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      
      
      

       

      with arquillian-glassfish-embedded:

       

      javax.naming.NamingException: Lookup failed for 'java:comp/EJBContext' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: No object bound for java:comp/EJBContext [Root exception is java.lang.IllegalStateException: Illegal invocation type for EJB Context : SERVLET_INVOCATION]]
                at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
                at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
                at javax.naming.InitialContext.lookup(InitialContext.java:411)
                at javax.naming.InitialContext.lookup(InitialContext.java:411)
                at org.arquillian.example.GreeterTest.testEJBContext(GreeterTest.java:65)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
                at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)
                at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
                at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
                at org.jboss.arquillian.container.test.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
                at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)
                at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)
                at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)
                at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)
                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:185)
                at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
                at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
                at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
                at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
                at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65)
                at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:160)
                at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126)
                at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
                at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
                at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
                at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
                at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
                at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
                at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
                at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
                at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
                at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
                at java.lang.Thread.run(Thread.java:722)
      Caused by: javax.naming.NameNotFoundException: No object bound for java:comp/EJBContext [Root exception is java.lang.IllegalStateException: Illegal invocation type for EJB Context : SERVLET_INVOCATION]
                at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:239)
                at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
                ... 103 more
      Caused by: java.lang.IllegalStateException: Illegal invocation type for EJB Context : SERVLET_INVOCATION
                at com.sun.ejb.containers.EJBContextNamingProxy.getEJBContextObject(EJBContextNamingProxy.java:89)
                at com.sun.ejb.containers.EJBContextNamingProxy.handle(EJBContextNamingProxy.java:70)
                at com.sun.enterprise.naming.impl.NamedNamingObjectManager.tryNamedProxies(NamedNamingObjectManager.java:89)
                at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:174)
                ... 104 more
      
      
      

       

       

      with arquillian-jboss-managed:

       

      javax.naming.NameNotFoundException: EJBContext -- service jboss.naming.context.java.module.9baebee6-c21e-4dc8-ba2c-f3ee7842bdf1.9baebee6-c21e-4dc8-ba2c-f3ee7842bdf1.EJBContext
                at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
                at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
                at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)
                at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
                at javax.naming.InitialContext.lookup(InitialContext.java:411)
                at org.arquillian.example.GreeterTest.testEJBContext(GreeterTest.java:64)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
                at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)
                at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
                at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
                at org.jboss.arquillian.container.test.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)
                at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)
                at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)
                at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)
                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:185)
                at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
                at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
                at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
                at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
                at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65)
                at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethodInternal(JMXTestRunner.java:128)
                at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethod(JMXTestRunner.java:107)
                at org.jboss.as.arquillian.service.ArquillianService$ExtendedJMXTestRunner.runTestMethod(ArquillianService.java:226)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:601)
                at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:111)
                at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:45)
                at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:235)
                at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:138)
                at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:250)
                at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
                at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:791)
                at org.jboss.as.jmx.PluggableMBeanServerImpl$TcclMBeanServer.invoke(PluggableMBeanServerImpl.java:498)
                at org.jboss.as.jmx.PluggableMBeanServerImpl.invoke(PluggableMBeanServerImpl.java:246)
                at org.jboss.remotingjmx.protocol.v1.ServerProxy$InvokeHandler.handle(ServerProxy.java:1034)
                at org.jboss.remotingjmx.protocol.v1.ServerProxy$MessageReciever$1.run(ServerProxy.java:215)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                at java.lang.Thread.run(Thread.java:722)
      
      

       

      Is is possible with Arquillian to lookup the EJBContext via JNDI?

       

      Kind regards

      Thomas

        • 1. Re: Lookup of EJBContext via JNDI with Arquillian possible?
          Thomas T Newbie

          So I guess nobody but me encountered this issue yet?

          I wonder if it really relates to arquillian or is a problem of the embedded glassfish.

           

          Unfortunately when I can not resolve this problem then I see no chance to use arquillian since all my entities rely on the same entity listener that uses the EJBContext.

          (This really would be a pity because arquillian looks quite promising to me for having an easy way of testing.)

          • 2. Re: Lookup of EJBContext via JNDI with Arquillian possible?
            Aslak Knutsen Master

            The problem is that the TestCase is not executed within a EJB, so there is no EJBContext to lookup.

             

            A possible workaround would be to create a small EJB that expose the Context and lookup that bean instead.

             

             

            @Stateless
            public class EJBContextLocator {
            
            
              @Resource
              private EJBContext context;
              
              public EJBContext getContext() {
                      return context;
              }
            }
            
               
            @RunWith(Arquillian.class)
            public class MyTest {
            
            
             ..
            
              @EJB
              private EJBContextLocator locator;
              
              
              @Test
              public void shouldBeAbleToLookupContext() {
                Assert.assertNotNull(locator.getContext());
              }
            }
            
            

             

             

            Not sure where your EntityListener kicks in, but even tho you can't lookup the Context from the TestClass, doesn't mean that the Listener can't.

            • 3. Re: Lookup of EJBContext via JNDI with Arquillian possible?
              Thomas T Newbie

              Thank you for your response, Aslak.

               

              Injecting the EJBContext in a stateless bean which is then used in the test case works.

               

              But what I actually wanted to test is the following:

               

              Given this JPA-Entity...

               

              @Entity
              @EntityListeners(MyListener.class)
              public class Employee {
              ... // fields omitted
              }
              

               

              ...and this entity listener

               

               

              import javax.ejb.EJBContext;
              import javax.naming.InitialContext;
              import javax.persistence.PrePersist;
              
              public class MyListener {
              
                        // Unfortunately injecting of resources like
                        // @Resource
                        // EJBContext context
                        // is not possible in entity listener with JPA 2.0
              
                        @PrePersist
                        public void doSomethingUsingEJBContext(final Employee employee) throws Exception {
                                  final InitialContext initialContext = new InitialContext();
                                  final EJBContext context = (EJBContext) initialContext.lookup("java:comp/EJBContext");
                                  final String username = context.getCallerPrincipal().getName();
                                  // do sth. with the username...
                        }
              }
              
              

               

              I want to persist an entity in a test case

               

               

              import org.jboss.arquillian.container.test.api.Deployment;
              import org.jboss.arquillian.junit.Arquillian;
              import org.jboss.arquillian.persistence.PersistenceTest;
              ...
              
              @RunWith(Arquillian.class)
              @PersistenceTest
              public class EmployeeTest {
              
              
               @PersistenceContext
               private EntityManager em;
              
               @Deployment 
               public static Archive<?> createDeploymentPackage() {
                 return ShrinkWrap.create(JavaArchive.class, "test.jar").addPackage(Employee.class.getPackage()).addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml").addAsManifestResource("test-persistence.xml", "persistence.xml");
               }
              
               @Test
               public void testPersistEmployee() {
                em.persist(new Employee);
               }
              
              }
              

               

              In production (glassfish server) the lookup in the entitiy listener works fine. But running the test gives the following error:

               

               

              INFO: test was successfully deployed in 5.203 milliseconds.
              09.11.2012 08:06:41 com.sun.ejb.containers.EjbContainerUtilImpl createThreadPoolExecutor
              INFO: Created EjbThreadPoolExecutor with thread-core-pool-size 16 thread-max-pool-size 32 thread-keep-alive-seconds 60 thread-queue-capacity 2147483647 allow-core-thread-timeout false 
              09.11.2012 08:06:41 com.sun.ejb.containers.EjbContainerUtilImpl getInstance
              WARNUNG: Internal error: EJBContainerUtilImpl was null
              java.lang.Throwable
                        at com.sun.ejb.containers.EjbContainerUtilImpl.getInstance(EjbContainerUtilImpl.java:263)
                        at com.sun.ejb.containers.EJBContextNamingProxy.getEJBContextObject(EJBContextNamingProxy.java:82)
                        at com.sun.ejb.containers.EJBContextNamingProxy.handle(EJBContextNamingProxy.java:70)
                        at com.sun.enterprise.naming.impl.NamedNamingObjectManager.tryNamedProxies(NamedNamingObjectManager.java:89)
                        at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:174)
                        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
                        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
                        at javax.naming.InitialContext.lookup(InitialContext.java:392)
                        at javax.naming.InitialContext.lookup(InitialContext.java:392)
                        at de.company.entities.MyListener.doSomethingUsingEJBContext(MyListener.java:17)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.invokeMethod(PrivilegedAccessHelper.java:376)
                        at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.invokeMethod(EntityListener.java:247)
                        at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.invokeMethod(EntityListener.java:272)
                        at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.prePersist(EntityListener.java:365)
                        at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:698)
                        at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyEJB30Listeners(DescriptorEventManager.java:624)
                        at org.eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.java:200)
                        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectClone(UnitOfWorkImpl.java:4216)
                        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:4193)
                        at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:493)
                        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4135)
                        at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:406)
                        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:269)
                        at de.lwv.server.dao.impl.EmployeeTest.testPersistEmployee(EmployeeTest.java:114)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
                        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
                        at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)
                        at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
                        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
                        at org.jboss.arquillian.container.test.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                        at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                        at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)
                        at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)
                        at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)
                        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                        at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)
                        at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
                        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:185)
                        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
                        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
                        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
                        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
                        at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
                        at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65)
                        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:160)
                        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126)
                        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90)
                        at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
                        at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
                        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
                        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
                        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
                        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
                        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
                        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
                        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
                        at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
                        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
                        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
                        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
                        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
                        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
                        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
                        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
                        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
                        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
                        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
                        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
                        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
                        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
                        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
                        at java.lang.Thread.run(Thread.java:662)
              09.11.2012 08:06:41 org.eclipse.persistence.session.file:/C:/Temp/gfembed1447586352969745970tmp/applications/test/WEB-INF/lib/test.jar_LwvCommon
              INFO: file:/C:/Temp/gfembed1447586352969745970tmp/applications/test/WEB-INF/lib/test.jar_LwvCommon logout successful
              classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)
              SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@69ae9f
              PlainTextActionReporterSUCCESSNo monitoring data to report.
              Tests run: 4, Failures: 0, Errors: 1, Skipped: 3, Time elapsed: 11.313 sec <<< FAILURE!
              testPersistEmployee(de.lwv.server.dao.impl.EmployeeTest)  Time elapsed: 0.687 sec  <<< ERROR!
              java.lang.ClassCastException: javax.naming.NamingException cannot be cast to java.lang.Error
                        at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.invokeMethod(EntityListener.java:257)
                        at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.invokeMethod(EntityListener.java:272)
                        at org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.prePersist(EntityListener.java:365)
                        at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:698)
                        at org.eclipse.persistence.descriptors.DescriptorEventManager.notifyEJB30Listeners(DescriptorEventManager.java:624)
                        at org.eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.java:200)
                        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectClone(UnitOfWorkImpl.java:4216)
                        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:4193)
                        at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:493)
                        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4135)
                        at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:406)
                        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:269)
                        at de.lwv.server.dao.impl.EmployeeTest.testPersistEmployee(EmployeeTest.java:114)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
                        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
                        at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)
                        at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
                        at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
                        at org.jboss.arquillian.container.test.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                        at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                        at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                        at java.lang.reflect.Method.invoke(Method.java:597)
                        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
                        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)
                        at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)
                        at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)
                        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                        at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)
                        at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
                        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:185)
                        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
                        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
                        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
                        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
                        at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
                        at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65)
                        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:160)
                        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126)
                        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90)
                        at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
                        at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
                        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
                        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
                        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
                        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
                        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
                        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
                        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
                        at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
                        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
                        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
                        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
                        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
                        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
                        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
                        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
                        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
                        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
                        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
                        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
                        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
                        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
                        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
                        at java.lang.Thread.run(Thread.java:662)
              
              ...
              Results :
              
              
              Tests in error: 
                testPersistEmployee(de.lwv.server.dao.impl.EmployeeTest): javax.naming.NamingException cannot be cast to java.lang.Error
              
              
              • 4. Re: Lookup of EJBContext via JNDI with Arquillian possible?
                Aslak Knutsen Master

                You have EntityManager calls from the TestCase, I'm not sure you're within a EJBContext at this point at all.

                 

                In your production code, it probably have a EJB that does the EntityManager injection and calls, in which case you're within the context of the calling EJB.