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