4 Replies Latest reply on Oct 22, 2007 10:07 PM by Norman Richards

    TestNG , EntityHome , No application context active

    Laurence Kirk Newbie

      I am trying to use TestNG to test persist operations in classes extended from EntityHome. I create an Entity Manager and use this to set the entity Manger in Entity Home. I use the persist method from EntityHome , but when i try to commit the transaction i get

      java.lang.IllegalStateException: No application context active

      [testng] Hibernate: insert into X2USER (name, id) values (?, ?)
      [testng] 31-May-2007 16:43:49 org.hibernate.impl.SessionFactoryImpl close
      [testng] INFO: closing
      [testng] 31-May-2007 16:43:49 org.hibernate.connection.DriverManagerConnectionProvider close
      [testng] INFO: cleaning up connection pool: jdbc:oracle:thin:@********
      [testng] Creating C:\dev\workspace\testp1\test-report\Currency Test.html
      [testng] FAILED: test.RegisterActionTest.testRegisterAction()
      [testng] java.lang.IllegalStateException: No application context active


      I don't get this problem if I just use entity manager outside of EntityHome.
      Is this a feasible thing to try to do ?



        • 1. Re: TestNG , EntityHome , No application context active
          Matt Drees Master

          I think you'd have to post more code and the stacktrace for people to be able to help.

          • 2. Re: TestNG , EntityHome , No application context active
            Laurence Kirk Newbie

            this is the test code

            The persist does succeed, and I get a row in the db, so I'm assuming its something about TestNG that I havent get set up correctly.

             @Test
             public final void testCreate()
             {
            
             EntityManagerFactory emf = Persistence.createEntityManagerFactory("entityManager");
             System.out.println("created emf "+ emf);
             EntityManager em = emf.createEntityManager();
             TestEntityHome teh = new TestEntityHome();
            
             teh.setEntityManager(em);
             em.getTransaction().begin();
             TestEntity te = teh.createInstance();
             te.setId(12);
             teh.setInstance(te);
             teh.getInstance();
             teh.persist();
             em.getTransaction().commit();
            
            
             }
            


            TestEntityHome is a sublcass of Entity Home as follows

            public class TestEntityHome<E> extends EntityHome
            {
            
             @Override
             public TestEntity createInstance()
             {
            
             TestEntity te = new TestEntity();
             return te;
             }
            
            }
            






            [testng] 20:07:10,359 INFO [SchemaUpdate] schema update complete
            [testng] created emf org.hibernate.ejb.EntityManagerFactoryImpl@186d484
            [testng] 20:07:10,625 INFO [DriverManagerConnectionProvider] cleaning up connection pool: jdbc:mysql://*********
            [testng] 20:07:10,640 INFO [DriverManagerConnectionProvider] cleaning up connection pool: jdbc:mysql://***********
            [testng] 20:07:10,843 WARN [AbstractEntityManagerImpl] Calling joinTransaction() on a non JTA EntityManager
            [testng] Hibernate: insert into XTEST (name, id) values (?, ?)
            [testng] Creating E:\jbossseam\dev\testp1\test-report\Entity Home Test.html
            [testng] FAILED: org.jboss.seam.mock.SeamTest.end()
            [testng] java.lang.NullPointerException
            [testng] at org.jboss.seam.contexts.WebApplicationContext.get(WebApplicationContext.java:48)
            [testng] at org.jboss.seam.Component.forName(Component.java:1579)
            [testng] at org.jboss.seam.Component.getInstance(Component.java:1627)
            [testng] at org.jboss.seam.Component.getInstance(Component.java:1622)
            [testng] at org.jboss.seam.Component.getInstance(Component.java:1599)
            [testng] at org.jboss.seam.Component.getInstance(Component.java:1594)
            [testng] at org.jboss.seam.core.ConversationEntries.instance(ConversationEntries.java:91)
            [testng] at org.jboss.seam.contexts.Lifecycle.endSession(Lifecycle.java:284)
            [testng] at org.jboss.seam.mock.SeamTest.end(SeamTest.java:676)
            [testng] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            [testng] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            [testng] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            [testng] at java.lang.reflect.Method.invoke(Method.java:585)
            [testng] at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:529)
            [testng] at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:311)
            [testng] at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:149)
            [testng] at org.testng.internal.Invoker.invokeMethod(Invoker.java:467)
            [testng] at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:625)
            [testng] at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:88)
            [testng] at org.testng.TestRunner.privateRun(TestRunner.java:614)
            [testng] at org.testng.TestRunner.run(TestRunner.java:505)
            [testng] at org.testng.SuiteRunner.privateRun(SuiteRunner.java:221)
            [testng] at org.testng.SuiteRunner.run(SuiteRunner.java:147)
            [testng] at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:576)
            [testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:539)
            [testng] at org.testng.TestNG.run(TestNG.java:316)
            [testng] at org.testng.TestNG.privateMain(TestNG.java:666)
            [testng] at org.testng.TestNG.main(TestNG.java:608)
            [testng] FAILED: test.ActualTestClass.testCreate()
            [testng] java.lang.IllegalStateException: No application context active
            [testng] at org.jboss.seam.Component.forName(Component.java:1577)
            [testng] at org.jboss.seam.Component.getInstance(Component.java:1627)
            [testng] at org.jboss.seam.Component.getInstance(Component.java:1622)
            [testng] at org.jboss.seam.Component.getInstance(Component.java:1599)
            [testng] at org.jboss.seam.Component.getInstance(Component.java:1594)
            [testng] at org.jboss.seam.persistence.PersistenceProvider.instance(PersistenceProvider.java:56)
            [testng] at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:50)
            [testng] at test.ActualTestClass.testCreate(ActualTestClass.java:63)
            [testng] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            [testng] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            [testng] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            [testng] at java.lang.reflect.Method.invoke(Method.java:585)
            [testng] at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:529)
            [testng] at org.testng.internal.Invoker.invokeMethod(Invoker.java:398)
            [testng] at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:625)
            [testng] at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:88)
            [testng] at org.testng.TestRunner.privateRun(TestRunner.java:614)
            [testng] at org.testng.TestRunner.run(TestRunner.java:505)
            [testng] at org.testng.SuiteRunner.privateRun(SuiteRunner.java:221)
            [testng] at org.testng.SuiteRunner.run(SuiteRunner.java:147)
            [testng] at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:576)
            [testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:539)
            [testng] at org.testng.TestNG.run(TestNG.java:316)
            [testng] at org.testng.TestNG.privateMain(TestNG.java:666)
            [testng] at org.testng.TestNG.main(TestNG.java:608)
            [testng] SKIPPED: destroy
            [testng] SKIPPED: cleanup
            [testng] ===============================================
            [testng] Entity Home Test
            [testng] Tests run: 4, Failures: 2, Skips: 2
            [testng] ===============================================
            [testng] Creating E:\jbossseam\dev\testp1\test-report\testng-failed.xml
            [testng] ===============================================
            [testng] Entity Home
            [testng] Total tests run: 4, Failures: 2, Skips: 2
            [testng] ===============================================
            [testng] Creating E:\jbossseam\dev\testp1\test-report\toc.html
            [testng] Creating E:\jbossseam\dev\testp1\test-report\Entity Home Test.properties
            [testng] Creating E:\jbossseam\dev\testp1\test-report\index.html
            [testng] Creating E:\jbossseam\dev\testp1\test-report\main.html
            [testng] Creating E:\jbossseam\dev\testp1\test-report\groups.html
            [testng] Creating E:\jbossseam\dev\testp1\test-report\methods.html
            [testng] Creating E:\jbossseam\dev\testp1\test-report\classes.html
            BUILD SUCCESSFUL
            Total time: 21 seco


            • 3. Re: TestNG , EntityHome , No application context active
              Nade Andrews Newbie

              I'm having the exact same issue. Anyone know how to get around this?

              Defeats the point of the unit test if you have to duplicate the CRUD code in the unit test as you're not actually testing the code that runs normally.

              • 4. Re: TestNG , EntityHome , No application context active
                Norman Richards Master

                If you need the contexts available, try running this inside of a ComponentTest.