2012-03-12 13 views
3

EJB를 테스트하고 싶습니다. 응용 프로그램 서버를 배포하고 싶지 않기 때문에 Weld EE Embedded로 테스트하고 싶습니다. 여기Arquillian Weld EE Embedded로 EJB 메소드 호출을 테스트하는 방법

@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 의존성은 다음과 같습니다 : 여기

내 클래스입니다

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 

않습니다

<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있어 누군가 해결책이 있습니까?

답변

0

@Inject 대신 @EJB를 사용해보십시오.

+0

아니요, 같은 문제 ... NPE –

0

'arquillian-weld-ee-embedded-1.1'대신 'arquillian-weld-se-embedded-1.1'을 사용해보세요. 이것은 실제로 버그이며이를 수정해야합니다.

편집 : 이미 해결 했어. 내 나쁜 :)