0 Replies Latest reply on Sep 16, 2010 3:54 AM by nimo stephan

    using embeeded container for testng in ejb 3.1

    nimo stephan Master

      I use EJB 3.1, JBOSS 6M4 and MAVEN, and I want to use the embeeded container for TestNG.



      Jboss has splitted all these these jars and so my maven-dependeny libs shows me a lot of libs which is provided by:


                <name>JBoss Repository 2</name>



      However, running the test throws a maven error as it needs also jsf 2. So we have to provide this to pom:


                <name>Java.net Repository for Maven</name>




      Note: with glassfish-embeeded, all these jars are included in ONE jar-file (which is very comfortable in compare to jboss-embeeded) so we only have to use this





      However, I use jboss-embeeded.


      My TestNG-Class:


      import java.util.List


      import javax.ejb.embeddable.EJBContainer;
      import javax.naming.Context;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;


      import org.testng.annotations.AfterClass;
      import org.testng.annotations.BeforeClass;
      import org.testng.annotations.Test;


      import com.MyBeanLocal;


      import static org.testng.Assert.assertEquals;


      public class MyTest
           @PersistenceContext EntityManager entityManager;

           private static EJBContainer ec;
           private static Context ctx;
            public void setUp() {

                System.out.println(this.getClass().getSimpleName() + " test started:");
                ec = EJBContainer.createEJBContainer();
                ctx = ec.getContext();
           public void testGetUsers() throws Exception{

               MyBeanLocal ejb = (MyBeanLocal) ctx.lookup("java:global/MyBeanLocal ");
               System.out.println("users: ");

             // I want to invoke a database operation within my test-ng
               List<Users> e = ejb.getUsers();


             System.out.println("users: "+e.size);



      So you see, I have all the needed dependencies and want to run a little test to retrieve users from the database with jboss-embeeded ejb3.1 - but: it does not work, because my setup (EJBContainer.createEJBContainer()) is not working !


      I get this error from maven:


      Running MyTest
      MyTest test started:
      Tests run: 3, Failures: 1, Errors: 0, Skipped: 2, Time elapsed: 0.312 sec <<< FAILURE!


      Results :


      Failed tests:


      Tests run: 3, Failures: 1, Errors: 0, Skipped: 2


      So you see, my setup is not working. Why?