运行集成测试 EJB 时出现问题
代码来自 Enterprise JavaBeans 3.1 第 4 章。如果您需要更多代码或信息,请询问!
public class SimpleCalculatorIntegrationTest {
private static SimpleCalculatorBean calc;
private static Context namingContext;
private static final String JNDI_NAME_CALC = "java:global/SimpleCalculatorEJB/SimpleCalculatorBean";
@BeforeClass
public static void obtainProxyReferences() throws NamingException {
namingContext = new InitialContext();
calc = (SimpleCalculatorBean) namingContext.lookup(JNDI_NAME_CALC);
}
@Test
public void testAddition() {
int expectedSum = 1 + 2 + 3 + 4; // 10
assertEquals(expectedSum, calc.add(1, 2, 3, 4));
}
}
堆栈跟踪:
11.okt.2011 20:41:28 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient 信息:找不到 javadb 客户端 jar 文件,derby jdbc 默认情况下驱动程序不可用。 java.lang.RuntimeException: Orb 初始化错误 org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:180) 在 com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365) 在 com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372) 在 com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402) 在 com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347) 在 com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504) 在 com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455) 在 javax.naming.InitialContext.lookup(InitialContext.java:392) 处 no.breakpoint.ejbbook.calculator.test.SimpleCalculatorIntegrationTest.obtainProxyReferences(SimpleCalculatorIntegrationTest.java:24) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 处 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在 java.lang.reflect.Method.invoke(Method.java:597) 处 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 在 org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 在 org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) 在 org.junit.runners.ParentRunner.run(ParentRunner.java:236) 处 org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 在 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 导致:java.lang.NullPointerException at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152) ... 23 更多
Code from Enterprise JavaBeans 3.1 chapter 4. If you need more code or information just ask!
public class SimpleCalculatorIntegrationTest {
private static SimpleCalculatorBean calc;
private static Context namingContext;
private static final String JNDI_NAME_CALC = "java:global/SimpleCalculatorEJB/SimpleCalculatorBean";
@BeforeClass
public static void obtainProxyReferences() throws NamingException {
namingContext = new InitialContext();
calc = (SimpleCalculatorBean) namingContext.lookup(JNDI_NAME_CALC);
}
@Test
public void testAddition() {
int expectedSum = 1 + 2 + 3 + 4; // 10
assertEquals(expectedSum, calc.add(1, 2, 3, 4));
}
}
Stacktrace:
11.okt.2011 20:41:28 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl
findDerbyClient INFO: Cannot find javadb client jar file, derby jdbc
driver will not be available by default. java.lang.RuntimeException:
Orb initialization erorr at
org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:180)
at
com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
at
com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
at
com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
at
com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
at
com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
at
com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:392) at
no.breakpoint.ejbbook.calculator.test.SimpleCalculatorIntegrationTest.obtainProxyReferences(SimpleCalculatorIntegrationTest.java:24)
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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 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
org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)
... 23 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
总结一下我们与其他感兴趣的用户的聊天对话:
您可以通过两种方式编写适用于您的 EJB 的测试:
然后,您将能够通过调用与此类似的代码来定位 EJB 的远程接口:
2. 测试容器内部。这意味着您的测试是在容器内执行的,并且很可能与您的应用程序一起执行。这允许您使用依赖项注入、EntityManager、本地/无接口 EJB 的视图等。使用JBoss Arquillian,您编写测试时假设所有服务都为您提供。
EJB 3.1 新的无接口视图就像本地视图一样,因此它不能用于驻留在应用程序外部的客户端。
Just to sum up our chat conversation for other interested users:
You can write tests that works on your EJB's in two ways:
Then you will be able to locate your EJB's remote interface by invoking code somewhat similar to this:
2. Testing inside-of-the-container. It means that your tests are executed within the container and, very likely, together with your application. This allows you to use dependency injection, EntityManagers, local/no-interface EJB's view and so on. With JBoss Arquillian, you write your tests just assuming that all the services are provided for you.
The EJB 3.1 new no-interface view is just like local view, so it cannot be used for clients residing outside of the application.