10 Replies Latest reply: Mar 14, 2012 5:54 AM by Anthony O. RSS

NullPointerException while calling an EJB method with arquillian-weld-ee-embedded-1.1

Anthony O. Newbie

(copied from my question on stackoverflow)

 

I would like to test an EJB, and I want to test it with Weld EE Embedded as I don't want to deploy an applicatoin server for that.

Here is my class :

@RunWith(Arquillian.class)
public class EJBTest {
   
@Deployment
   
public static JavaArchive createTestArchive() {
       
return ShrinkWrap
               
.create(JavaArchive.class, "test.jar")
               
.addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
   
}

   
@Stateless
   
public static class SomeService {
       
public String someMethod() {
           
return "test";
       
}
   
}

   
@Inject
   
SomeService someService;

   
@Test
   
public void testStatelessCall() {
       
Assert.assertEquals("test", someService.someMethod());
   
}
}

And here are my pom.xml dependencies :

<dependency>
   
<groupId>junit</groupId>
   
<artifactId>junit</artifactId>
   
<version>4.10</version>
   
<scope>test</scope>
</dependency>
<dependency>
   
<groupId>org.jboss.arquillian.junit</groupId>
   
<artifactId>arquillian-junit-container</artifactId>
   
<version>1.0.0.CR6</version>
   
<scope>test</scope>
</dependency>
<dependency>
   
<groupId>org.jboss.arquillian.container</groupId>
   
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
   
<version>1.0.0.CR3</version>
   
<scope>test</scope>
</dependency>
<dependency>
   
<groupId>org.jboss.weld</groupId>
   
<artifactId>weld-core</artifactId>
   
<version>1.1.2.Final</version>
   
<scope>test</scope>
</dependency>
<dependency>
   
<groupId>org.jboss.weld</groupId>
   
<artifactId>weld-api</artifactId>
   
<version>1.1.2.Final</version>
   
<scope>test</scope>
</dependency>
<dependency>
   
<groupId>org.jboss.weld</groupId>
   
<artifactId>weld-spi</artifactId>
   
<scope>test</scope>
   
<version>1.1.2.Final</version>
</dependency>
<dependency>
   
<groupId>org.slf4j</groupId>
   
<artifactId>slf4j-simple</artifactId>
   
<!-- version imported with org.jboss.weld:weld-core-bom:1.1.2.Final -->
   
<scope>test</scope>
</dependency>
<dependency>
   
<groupId>org.jboss.arquillian.container</groupId>
   
<artifactId>arquillian-container-test-spi</artifactId>
   
<version>1.0.0.CR6</version>
   
<scope>test</scope>
</dependency>
<dependency>
   
<groupId>org.jboss.arquillian.container</groupId>
   
<artifactId>arquillian-container-spi</artifactId>
   
<version>1.0.0.CR6</version>
   
<scope>test</scope>
</dependency>

While testing my class, I've got a NPE :

     java.lang.RuntimeException: java.lang.NullPointerException
          at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:195)
          at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299)
          at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:125)
          at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62)
          at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125)
          at com.mycompany.SomeService$Proxy$_$$_Weld$Proxy$.someMethod(SomeService$Proxy$_$$_Weld$Proxy$.java)
          at com.mycompany.EJBTest.testStatelessCall(EJBTest.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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
          at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
          at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
          at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:267)
          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: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:134)
          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
          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: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: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:134)
          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
          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: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: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: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: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: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: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: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: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: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:90)
          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)
          at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)
          at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:260)
          at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:223)
          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:311)
          at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
          at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:237)
          at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
          at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:182)
          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:311)
          at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
          at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:196)
          at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
          at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:144)
          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)
     Caused by: java.lang.NullPointerException
          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.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305)
          at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
          at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
          ... 101 more

It is linked toorg.jboss.arquillian.container.weld.ee.embedded_1_1.mock.MockEjBServices which return a SessionObjectReference wich return null when calling getBusinessObject method.

 

Did I do the things wrong ? Is this an Arquillian bug ? Does somebody have a solution ?