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

    using embeeded container for testng in ejb 3.1

    nimo22

      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:

       

      <repository>
                <id>repository.jboss.org.nexus</id>
                <name>JBoss Repository 2</name>
                <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
      </repository>


      <dependency>
                 <groupId>org.jboss.spec</groupId>
                 <artifactId>jboss-javaee-6.0</artifactId>
                 <version>1.0.0.Beta6</version>
                 <type>pom</type>
                 <scope>test</scope>
      </dependency>

       

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

       

      <repository>
                <id>maven2-repository.dev.java.net</id>
                <name>Java.net Repository for Maven</name>
                <url>http://download.java.net/maven/2</url>
      </repository>


      <dependency>
               <groupId>com.sun.faces</groupId>
               <artifactId>jsf-api</artifactId>
               <version>2.0.2</version>
               <type>pom</type>
               <scope>test</scope>
      </dependency>

       

       

      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

       

      <dependency>
              <groupId>org.glassfish.embedded</groupId>
              <artifactId>glassfish-embedded-all</artifactId>
              <version>3.0</version>
              <scope>test</scope>
          </dependency>

       

       

      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;
          
            @BeforeClass
            public void setUp() {

                System.out.println(this.getClass().getSimpleName() + " test started:");
               
                ec = EJBContainer.createEJBContainer();
                ctx = ec.getContext();
            }
          
           @Test
           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:
        setUp(com.MyTest)

       

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

       

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