This discussion is archived
2 Replies Latest reply: Jul 17, 2012 3:33 AM by Justin James RSS

Embedded EJBContainer  // No EJBContainer provider available

Justin James Newbie
Currently Being Moderated
Hello Friends

Environment :
Weblogic12c
JUnit4
JRockit1.6

Can you please share with me the EJBContainer.PROVIDER value while using weblogic12c.
I created an EJB3.1 stateless session bean, now I'm trying to use embedded ejb container for JUnit test class within the same EJB project.

I'm already followed this link - http://docs.oracle.com/javaee/6/tutorial/doc/gkcrr.html
but no luck.While running JUnit test class, getting following exception you can find at the bottom this post.

I'm using these packages from javax.ejb_3.1.0.jar
import javax.ejb.embeddable.EJBContainer;
import javax.ejb.spi.EJBContainerProvider;

Note : The same test project is running well in glassfish server.

Thanks in advance,
Have more fun with Java.
Justin.

Exception :
javax.ejb.EJBException: No EJBContainer provider available for requested provider: 
        javax.ejb.spi.EJBContainerProvider: no provider names had been found.
     at javax.ejb.embeddable.EJBContainer.reportError(EJBContainer.java:186)
     at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:121)
     at com.justin.math.ejb.test.CalculatorEJBJUTest.init(CalculatorEJBJUTest.java:31)
     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.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:684)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:391)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Test Class :
package com.justin.math.ejb.test;

import static org.junit.Assert.*;

import java.util.Properties;
import javax.ejb.embeddable.EJBContainer;
//import javax.ejb.spi.EJBContainerProvider;
import javax.naming.NamingException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.justin.math.ejb.CalculatorEJB;

public class CalculatorEJBJUTest {
     
     static EJBContainer ejbContainer; 
     static CalculatorEJB calculatorEJB;
     
     @BeforeClass
     public static void init() {          
          String globalJndiName = "java:global/classes/CalculatorEJB";
          //String localJndiName = "java:module/CalculatorEJB";
          Properties properties = new Properties();
          try {
               properties.setProperty(EJBContainer.MODULES, "CalculatorEJB");
               properties.setProperty(EJBContainer.PROVIDER, "javax.ejb.spi.EJBContainerProvider");
                        //Also tried without setting properties in WLS12c. Glassfish was fine without properties.
               ejbContainer = EJBContainer.createEJBContainer(properties);
                        //Just trying both global and local jndi names
               //calculatorEJB = (CalculatorEJB) ejbContainer.getContext().lookup(localJndiName);
               calculatorEJB = (CalculatorEJB) ejbContainer.getContext().lookup(globalJndiName);
               
          } catch (NamingException e) {
               e.printStackTrace();
          }
     }
     
     @AfterClass
     public static void release() {
          if(ejbContainer != null)
               ejbContainer.close();
     }
     
     @Test
     public void testAdd() {
          int result = calculatorEJB.add(1, 2);
          assertNotNull(result);
          assertEquals(3, result);
     }
     
     @Test
     public void testMultiply() {
          int result = calculatorEJB.multiply(1, 2);
          assertNotNull(result);
          assertEquals(2, result);
     }
}