You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Marco Mistroni <mm...@gmail.com> on 2006/05/26 10:14:55 UTC

Re: Problems wtih TestNG / JBossSeam / surefire plugin / partially OT / Solved

Hello all,
 i thought i might let the list know that i solved my problem and it had
nothing to do with
either TestNG or Maven.

i was using embeddable-alpha6 in my tests.... and i had one missing line in
the code .. so
that everything was screwed up.

I know i have sent around a sample M2 J2EE app which involved EJB3 with
TestNG....
that code won't work anymore embeddable alpha6.
Here's a sample base test class that will work with embeddable alpha6

*****  CODE *******************

package example1;




import org.jboss.ejb3.embedded.*;
import org.testng.annotations.Configuration;
import org.testng.annotations.ExpectedExceptions;
import org.testng.annotations.Test;
import junit.framework.*;
import junit.extensions.*;


import javax.naming.*;

/**
 * Boots the JBoss Microcontainer with an EJB3 configuration.
 * <p>
 * You can also use this class to lookup managed beans from JNDI.
 *
 * @author christian.bauer@jboss.com
 */
public class EJB3ContainerTestNG extends TestCase{

    private static InitialContext initialContext;
    private EJB3StandaloneDeployer deployer;


    @Configuration(groups = "integration.ejb3", beforeTest = true)
    public void startup() {
        try {

        System.err.println("---- bootstrapping EJB3 container....");

        // Boot the JBoss Microcontainer with EJB3 settings, loads
ejb3-interceptors-aop.xml
        EJB3StandaloneBootstrap.boot(null);
        System.err.println("...... deploying embedded-jboss-beans....");
        EJB3StandaloneBootstrap.scanClasspath();

        System.err.println("...... embedded-jboss-beans deployed....");
        // Add all EJBs found in the archive that has this file
        deployer = new EJB3StandaloneDeployer();

        System.err.println("...... deploying MM ejb3.....");
        System.err.println("...... ejb3 deployed....");

         // Deploy everything we got


         deployer.setKernel(EJB3StandaloneBootstrap.getKernel());  // THIS
WAS THE MISSING LINE

         deployer.create();
         System.err.println("...... deployer created....");

         deployer.start();
         System.err.println("...... deployer started....");

          // Create InitialContext from jndi.properties
         initialContext = new InitialContext();
         System.err.println("---- end of bootstrapping EJB3
container....InitialContext is:");

        } catch (Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }




    @Configuration(groups = "integration.ejb3", afterTest = true)
    public void shutdown() {
        try {
            System.err.println("---- Invoking EJB3.shutdown..");
            deployer.stop();
            deployer.destroy();
            EJB3StandaloneBootstrap.shutdown();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }


    public void testMethod1() {
        System.err.println("EJB3CONTAINER.....  TESTING1");
    }

    public static Object lookup(String beanName) {
        try {

            return initialContext.lookup(beanName);
        } catch (NamingException ex) {
            throw new RuntimeException("Couldn't lookup: " + beanName, ex);
        }
    }

}

********* END OF CODE  *********


HTH
  marco