2012-03-12 1 views
3

Я хотел бы протестировать EJB, и я хочу протестировать его с помощью Weld EE Embedded, поскольку я не хочу развертывать для этого сервер приложений.Как протестировать вызов метода EJB с помощью Arquillian Weld EE Embedded

Вот мой класс:

@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()); 
    } 
} 

А вот мои pom.xml зависимости:

<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> 

Хотя тестирование мой класс, я получил 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 

Does у кого-то есть решение?

ответ

0

попробуйте использовать @EJB вместо @Inject.

+0

Нет, такая же проблема ... NPE –

0

вместо «arquillian-weld-ee-embedded-1.1», попробуйте использовать «arquillian-weld-se-embedded-1.1». Это действительно ошибка, и это должно исправить это.

Редактировать: видеть, что вы уже решили, мои плохие :)

Смежные вопросы