0 Replies Latest reply on May 25, 2007 8:08 PM by jcruise

    Testing without EJB

    jcruise

      Hi

      Does anybody know how to bootstrap the microcontainer in a test class or console app? I am using pojo/hibernate/tomcat so I don't want to use the embedded ejb-3. I tried simply extending SeamTest, using code a bit like this:

      public class Administration extends SeamTest {
      
       EntityManager em() {
       EntityManagerFactory emf = Persistence
       .createEntityManagerFactory("myDatabase");
       EntityManager em = emf.createEntityManager();
       return em;
       }
      
       public static void main(String[] args) throws Exception {
       Administration app = new Administration();
       app.execute();
       }
      
       private void execute() throws Exception {
      
       EntityManager em = em();
      
       em.getTransaction().begin();
      
       Log log = (Log) getInstance("log");
       log.info("Starting Administration Console");
      
      
      ... stuff with my components ...
      
      
       em.getTransaction().commit();
       }
      


      but I get the following error:

      15:55:15,967 ERROR [NamingHelper] Could not obtain initial context
      javax.naming.NamingException: Local server is not initialized
       at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:30)
       at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
       at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
       at javax.naming.InitialContext.init(Unknown Source)
       at javax.naming.InitialContext.<init>(Unknown Source)
       at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
      


      Any ideas?

      Cheers
      J