users@glassfish.java.net

Embedded GlassFish - No EJBContainer available with multiple JUnit tests

From: Antonio Goncalves <antonio.mailing_at_gmail.com>
Date: Mon, 27 Sep 2010 09:59:10 +0200

Hi,

I have several JUnit test classes to test my EJBs. Taken one by one, each
test passes (they use JPA, Derby and so on). But when I run all the tests
(either with my IDE, Maven
or @RunWith(Suite.class) @Suite.SuiteClasses({...})) I have a No
EJBContainer provider available (see stack trace below). In fact, the first
test passes and all the following don't. I think it could be because I'm not
cleaning the embbed container correctly between tests. Here is what I do on
each test class :


public class ItemEJB01Test {

    private static EJBContainer ec;
    private static Context ctx;


    @BeforeClass
    public static void initContainer() throws Exception {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(EJBContainer.MODULES, new File("target/classes"));
        *ec = EJBContainer.createEJBContainer(properties); <---- This is
where is breaks*
        ctx = ec.getContext();
    }

    @AfterClass
    public static void closeContainer() throws Exception {
        if (ctx != null)
            ctx.close();
        if (ec != null)
            ec.close();
    }
...
...
}


I'm using :

 <dependency>
            <groupId>org.glassfish.extras</groupId>
            <artifactId>glassfish-embedded-all</artifactId>
            <version>*3.0.1-b20*</version>
        </dependency>
</dependencies>


Any idea ?
Thanks,
Antonio


javax.ejb.EJBException: No EJBContainer provider available
The following providers:
org.glassfish.ejb.embedded.EJBContainerProviderImpl
Returned null from createEJBContainer call.

at javax.ejb.embeddable.EJBContainer.reportError(EJBContainer.java:186)
at
javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:121)
at
org.beginningee6.book.chapter07.ex03.ShoppingCartEJB03Test.initContainer(ShoppingCartEJB03Test.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
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.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:94)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)