0 Replies Latest reply: Jan 10, 2011 9:52 AM by Hans-Michael Rupp RSS

    JUnit Testing EJBs in Eclipse

    Hans-Michael Rupp Novice

      Hallo I am trying to port my application from JEE5 (Unit Tests with OpenEJB) to JEE6 using JBoss (M5).

      I have read that a JEE6 compliant container must support an embeddable Container.

      I have the jars from the client dir in my classpath

       

      The following code compiles but does not run:

       

      package fencing.control.test;

       

      import static org.junit.Assert.assertNotNull;

       

      import java.util.ArrayList;

      import java.util.Calendar;

      import java.util.List;

       

      import javax.ejb.embeddable.EJBContainer;

      import javax.naming.NamingException;

       

      import org.junit.AfterClass;

      import org.junit.BeforeClass;

      import org.junit.Test;

       

      import fencing.control.FechterDAO;

      import fencing.entity.Adresse;

      import fencing.entity.Fechter;

      import fencing.entity.Waffe;

       

      public class FechterDAOTestJEE6 {

       

          public static EJBContainer ejbC;

       

          @BeforeClass

          public static void setup() {

              ejbC = EJBContainer.createEJBContainer();

          }

       

          @AfterClass

          public static void tearDown() {

              ejbC.close();

          }

       

          @Test

          public void testNeuerFechter() throws NamingException {

              Fechter fechter = new Fechter();

              fechter.setVorname("bla");

              fechter.setNachname("bla");

       

              //...

              FechterDAO fechterDAO = (FechterDAO) ejbC.getContext().lookup("FechterDAOBean/local");

              assertNotNull(fechterDAO);

              fechter = fechterDAO.addFechter(fechter);

              assertNotNull(fechter);

              assertNotNull(fechter.getId());

          }

       

      }

       

       

      javax.ejb.EJBException: Unable to instantiate container with factories []

          at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:101)

          at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:79)

          at fencing.control.test.FechterDAOTestJEE6.setup(FechterDAOTestJEE6.java:27)

          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:46)

          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)

       

      java.lang.NullPointerException

          at fencing.control.test.FechterDAOTestJEE6.tearDown(FechterDAOTestJEE6.java:32)

          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.RunAfters.evaluate(RunAfters.java:37)

          at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

          at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

          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)

       

       

       

      What am I missing?

       

      Thanks,

       

      Hans