1 Reply Latest reply on Sep 11, 2009 4:40 PM by alesj

    Using JBoss Microcontainer for JUnit Tests

    tbar0711

      Hello,

      I'd like to use the JBoss Microcontainer for JUnit Tests of Session Beans without a running JBoss 4.2.3. I read a lot about this. But I still don't know what exactly I have to download and where. There are different projects:

      • aop-mc-int - the aop integration
      • classloader - new classloader model, prepared to handle OSGi CL style
      • container - general metadata utilities, and virtual file system usuable across projects
      • dependency - a generic dependency state machine
      • deployers - the virtual deployment framework (VDF) spi and abstractions.
      • guice-int - guice integration
      • kernel - the microcontainer adding xml deployment and "javabeans" to the above two projects
      • managed
      • metatype
      • osgi-int - osgi integration
      • reliance-identity - define identity as a MC POJO service
      • reliance-rules - define your dependencies with Drools
      • reliance-jbpm - define your dependencies with jBPM
      • spring-int - spring integration

      But what of them do I need and how I have to configure it?

      Here is an example for one of my Testclasses:


      package de.myapplication.business.SomethingDaoImplTest;
      
      import junit.framework.*;ork.TestCase;
      
      import org.apache.log4j.Level;
      import org.apache.log4j.Logger;
      
      import de.myapplication.exception.PersistenceException;
      import de.myapplication.persistence.Something;
      import de.myapplication.persistence.SomethingPK;
      import de.myapplication.session.persistence.dao.LocalStatelessAccessor;
      import de.myapplication.session.persistence.dao.interfaces.SomethingDAO;
      
      public class SomethingDaoImplTest extends TestCase {
      
       private static final Logger LOGGER = Logger
       .getLogger(SomethingDaoImplTest.class.getName());
      
      
       public void testLoad() throws PersistenceException {
      
       // Testdaten
       String somethingnr = "12345566";
       String sap_system = "asdf2";
       String sap_mandant = "000";
       String sprache = "DE";
      
       Something something = null;
      
       LOGGER
       .log(Level.INFO,
       "***** SomethingDaoImplTest: testLoad() *****");
      
       SomethingDAO somethingDAO = LocalStatelessAccessor
       .provideBean(SomethingDAO.class);
       something = somethingDAO.load(new SomethingPK(somethingnr, sap_system,
       sap_mandant), sprache);
      
       LOGGER.log(Level.INFO, "S_nr: "
       + something.getId().getSomethingnr());
      
       if (something.getId().equals(
       new SomethingPK(somethingnr, sap_system, sap_mandant))) {
       assertTrue("Object gleich", true);
       } else {
       assertTrue("Object nicht gleich", false);
       }
       }
      
       public void testLoadSomethingTexte() throws PersistenceException {
      
       String somethingnr = "12345566";
       String sap_system = "asdf44";
       String sap_mandant = "000";
       String sprache = "DE";
      
       Something something = null;
      
       LOGGER.log(Level.INFO,
       "***** SomethingDaoImplTest: testLoadSomethingTexte() *****");
      
       SomethingDAO somethingDAO = LocalStatelessAccessor
       .provideBean(SomethingDAO.class);
       something = SomethingDAO.load(new SomethingPK(somethingnr, sap_system,
       sap_mandant), sprache);
      
       LOGGER.log(Level.INFO, "S_nr: "
       + something.getId().getSomethingnr());
      
       assertEquals(sprache, something.getSomethingText().getId().getSprache());
      
       }
      
      }


      SomethingDaoImpl is a Session Bean which implements the interface SomethingDAO. The LocalStatelessAccessor handles the JNDI Lookup.

      Thanks in advance.