Hi you probably don't use org.apache.openejb:javaee-api as ejb api and the implementation you use is maybe not compatible, just put it first in your maven deps (scope provided)
*Romain Manni-Bucau* *Twitter: @rmannibucau <https://twitter.com/rmannibucau>* *Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau* *Github: https://github.com/rmannibucau* 2013/7/23 Drekorian <[email protected]> > Hi, guys,I'm pretty new to Enterprise Java, Maven, and this kind of > development whatsover, so it's pretty possible that I'm just making some > kind of beginner's mistake, so bear with me, please.What I'm trying to do: > I'm developing a J2EE application, that will eventually run on RedHat's > OpenShift (therefore JBoss AS 7.1, Hibernate, MySQL). I would like to write > some tests for my EJBs and from googling the topic I've figured out, that > OpenEJB could help me.I've added following Maven dependency: > <dependency> > <groupId>org.apache.openejb</groupId> > <artifactId>openejb-core</artifactId> > <version>4.5.2</version> > <scope>test</scope> > </dependency> > Now I have this dummy Stateless EJB called Foo: > package cz.drekorian.ffmap;import javax.ejb.Stateless;@Statelesspublicclass > Foo { public int bar() { return 1; }} > And to test whether things are working or not, I've written a JUnit 4 test: > package cz.drekorian.ffmap.test.entities;import > javax.ejb.embeddable.EJBContainer;import > javax.naming.NamingException;import > junit.framework.Assert;import org.junit.AfterClass;import > org.junit.Before;import org.junit.BeforeClass;import org.junit.Test;import > cz.drekorian.ffmap.Foo;public class FooTest { private static > EJBContainer > ejbContainer; private Foo foo; public FooTest() { } > @BeforeClass public static void setUpClass() { ejbContainer = > EJBContainer.createEJBContainer(); } @AfterClass public static > void tearDownClass() { if (ejbContainer != null) { > ejbContainer.close(); } } @Before public void setUp() > throws NamingException { foo = (Foo) > ejbContainer.getContext().lookup("java:global/ffmap/Foo"); } @Test > public void testBar() { Assert.assertEquals(1, foo.bar()); }} > The JUnit test fails on java.lang.NullPointerException. Here's the trace: > java.lang.NullPointerException at > > org.apache.openejb.OpenEjbContainer$Provider.isOtherProvider(OpenEjbContainer.java:595) > at > > org.apache.openejb.OpenEjbContainer$Provider.createEJBContainer(OpenEjbContainer.java:282) > at > javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:93) > at > javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:75) > at cz.drekorian.ffmap.test.entities.FooTest.setUpClass(FooTest.java:26) at > sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at > sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at > sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at > java.lang.reflect.Method.invoke(Unknown Source) 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.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) > 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) > Any help or advice would be greatly appreciated.Thanks. > > > > -- > View this message in context: > http://openejb.979440.n4.nabble.com/Testing-with-OpenEJB-tp4664319.html > Sent from the OpenEJB User mailing list archive at Nabble.com.
