3 Replies Latest reply on May 15, 2008 12:29 PM by Pete Muir

    EntityQuery and TestNG

    jfrankman Novice

      I am trying to write a test against an EntityQuery class I have written.


      
           @Test
      
           public void lenderListQueryTest()
      
           {
      
                EntityManager em = getEntityManagerFactory().createEntityManager();
      
                //em.getTransaction().begin();
      
                LenderListQuery q = new LenderListQuery();
      
                q.setPersistenceContext(em);
      
                q.setEntityManager(em);
      
                q.getLenderVO().setSearch("US BANK");
      
                List<LenderVO> lenderList=q.getResultList();
      
                System.out.println("lenderList count:" + lenderList.size());
      
                assert(lenderList.size()>0);
      
                
      
                em.close();
      
           }
      
      
      



      However, I get the following error:




      
      FAILED: lenderListQueryTest
      
      java.lang.IllegalStateException: No application context active
      
           at org.jboss.seam.ScopeType.getContext(ScopeType.java:139)
      
           at org.jboss.seam.Component.getInstance(Component.java:1621)
      
           at org.jboss.seam.Component.getInstance(Component.java:1599)
      
           at org.jboss.seam.Component.getInstance(Component.java:1594)
      
           at org.jboss.seam.core.Expressions.instance(Expressions.java:265)
      
           at org.jboss.seam.persistence.QueryParser.<init>(QueryParser.java:60)
      
           at org.jboss.seam.framework.Query.parseEjbql(Query.java:142)
      
           at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:100)
      
           at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:41)
      
           at com.idfbins.nexus.business.LenderListQuery.getResultList(LenderListQuery.java:177)
      
           at com.idfbins.nexus.business.test.LenderLookupTests.lenderListQueryTest(LenderLookupTests.java:99)
      
      ... Removed 22 stack frames
      
      



      ...
      How can I set the application context from my TestNG test?