4 Replies Latest reply on Oct 1, 2009 12:22 PM by Bartek Wasko

    SeamTest NoInitialContextException

    Bartek Wasko Newbie

      Hi, I am a seam greenhorn so it is very likely that the following is rather a trivial problem, if so sorry for this, but still I am unable to figure it out looking at seam examples. I am trying to write an integration test using SeamTest embedded jboss mode. Project is built using maven, seam version 2.2.0.GA, tests use testng. Test itself does not contain any logic at the moment, it is just:
       




      @Test
          public void testNothing() throws Exception {
      
              new FacesRequest("/category.xhtml") {
      
                  @Override
                  protected void updateModelValues() {
      
                  }
      
                  @Override
                  protected void invokeApplication() {
      
                  }
      
                  @Override
                  protected void renderResponse() throws Exception {
                      
                  }
              }.run();
          }





      View category.xhtml is a home view for component CategoryHome managing simple entity called Category, containg only one simple string field.
      Project consists of 4 modules, ear, ejb, war and model. Above test is placed in war module. No special configuration files (in context of tests) have been added besides of persistence.xml (model module, src/test/META-INF/persistence.xml):



      <persistence-unit name="invoices-PersistenceUnit">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/DefaultDS</jta-data-source>
            <properties>
               <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.cache.use_second_level_cache" value="false"/>
               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
            </properties>
         </persistence-unit>




      After test is executed, following stacktrace can be obeserved:


      ...........................



      2009-09-30 10:18:11 org.jboss.seam.Component init
      INFO: Component: passwordGenerator, scope: STATELESS, type: STATELESS_SESSION_BEAN, class: com.consol.invoices.logic.mod
      el.PasswordGeneratorAction, JNDI: ${ear.artifactId}-${version}/PasswordGeneratorAction/local
      2009-09-30 10:18:11 org.jboss.seam.Component init
      INFO: Component: productCriteria, scope: CONVERSATION, type: JAVA_BEAN, class: com.consol.invoices.model.ProductCriteria
      
      2009-09-30 10:18:11 org.jboss.seam.Component init
      INFO: Component: productHome, scope: CONVERSATION, type: JAVA_BEAN, class: com.consol.invoices.logic.model.ProductHome
      2009-09-30 10:18:11 org.jboss.seam.Component init
      INFO: Component: productList, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.framework.EntityQuery
      2009-09-30 10:18:11 org.jboss.seam.Component init
      INFO: Component: register, scope: EVENT, type: STATEFUL_SESSION_BEAN, class: com.consol.invoices.logic.security.Register
      Action, JNDI: ${ear.artifactId}-${version}/RegisterAction/local
      2009-09-30 10:18:11 org.jboss.seam.Component init
      INFO: Component: user, scope: CONVERSATION, type: ENTITY_BEAN, class: com.consol.invoices.model.User
      2009-09-30 10:18:11 org.jboss.seam.security.permission.PersistentPermissionResolver initPermissionStore
      WARNING: no permission store available - please install a PermissionStore with the name 'org.jboss.seam.security.jpaPerm
      issionStore' if persistent permissions are required.
      2009-09-30 10:18:11 org.jboss.seam.servlet.SeamFilter init
      INFO: Initializing filter: org.jboss.seam.web.ajax4jsfFilter
      2009-09-30 10:18:11 org.ajax4jsf.cache.CacheManager getCacheFactory
      INFO: Selected [org.ajax4jsf.cache.LRUMapCacheFactory] cache factory
      2009-09-30 10:18:11 org.ajax4jsf.cache.LRUMapCacheFactory createCache
      INFO: Creating LRUMap cache instance using parameters: {org.richfaces.CONTROL_SKINNING_CLASSES=disable, org.richfaces.SK
      IN=glassX, org.richfaces.LoadStyleStrategy=ALL, org.richfaces.CONTROL_SKINNING=disable, facelets.DEVELOPMENT=@debug@, ja
      vax.faces.DEFAULT_SUFFIX=.xhtml, org.richfaces.LoadScriptStrategy=ALL}
      2009-09-30 10:18:11 org.ajax4jsf.cache.LRUMapCacheFactory createCache
      INFO: Creating LRUMap cache instance of default capacity
      2009-09-30 10:18:11 org.ajax4jsf.cache.CacheManager getCacheFactory
      INFO: Selected [org.ajax4jsf.cache.LRUMapCacheFactory] cache factory
      2009-09-30 10:18:11 org.ajax4jsf.cache.LRUMapCacheFactory createCache
      INFO: Creating LRUMap cache instance using parameters: {org.richfaces.CONTROL_SKINNING_CLASSES=disable, org.richfaces.SK
      IN=glassX, org.richfaces.LoadStyleStrategy=ALL, org.richfaces.CONTROL_SKINNING=disable, facelets.DEVELOPMENT=@debug@, ja
      vax.faces.DEFAULT_SUFFIX=.xhtml, org.richfaces.LoadScriptStrategy=ALL}
      2009-09-30 10:18:11 org.ajax4jsf.cache.LRUMapCacheFactory createCache
      INFO: Creating LRUMap cache instance of default capacity
      2009-09-30 10:18:11 org.jboss.seam.servlet.SeamFilter init
      INFO: Initializing filter: org.jboss.seam.web.redirectFilter
      2009-09-30 10:18:11 org.jboss.seam.servlet.SeamFilter init
      INFO: Initializing filter: org.jboss.seam.web.exceptionFilter
      2009-09-30 10:18:11 org.jboss.seam.servlet.SeamFilter init
      INFO: Initializing filter: org.jboss.seam.web.multipartFilter
      2009-09-30 10:18:11 org.jboss.seam.servlet.SeamFilter init
      INFO: Initializing filter: org.jboss.seam.web.identityFilter
      2009-09-30 10:18:11 org.jboss.seam.jsf.SeamPhaseListener beforePhase
      SEVERE: swallowing exception
      java.lang.RuntimeException: exception invoking: getTransaction
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:154)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2249)
              at org.jboss.seam.Component.unwrap(Component.java:2275)
              at org.jboss.seam.Component.getInstance(Component.java:2041)
              at org.jboss.seam.Component.getInstance(Component.java:2000)
              at org.jboss.seam.Component.getInstance(Component.java:1994)
              at org.jboss.seam.Component.getInstance(Component.java:1967)
              at org.jboss.seam.Component.getInstance(Component.java:1962)
              at org.jboss.seam.transaction.Transaction.instance(Transaction.java:39)
              at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsBeforePhase(SeamPhaseListener.java:321)
              at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:144)
              at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:118)
              at org.jboss.seam.mock.AbstractSeamTest$Request.restoreViewPhase(AbstractSeamTest.java:721)
              at org.jboss.seam.mock.AbstractSeamTest$Request.emulateJsfLifecycle(AbstractSeamTest.java:583)
              at org.jboss.seam.mock.AbstractSeamTest$Request.access$100(AbstractSeamTest.java:177)
              at org.jboss.seam.mock.AbstractSeamTest$Request$2.doFilter(AbstractSeamTest.java:497)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      ............................
      
              at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
              at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
      Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as a
      n applet parameter, or in an application resource file:  java.naming.factory.initial
              at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
              at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
              at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
              at javax.naming.InitialContext.lookup(InitialContext.java:351)
              at org.jboss.seam.transaction.Transaction.getUserTransaction(Transaction.java:82)
              at org.jboss.seam.transaction.Transaction.createUTTransaction(Transaction.java:74)
              at org.jboss.seam.transaction.Transaction.getTransaction(Transaction.java:47)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              ... 62 more
      2009-09-30 10:18:11 org.jboss.seam.jsf.SeamPhaseListener afterPhase
      WARNING: uncaught exception, passing to exception handler
      java.lang.IllegalStateException: Could not commit transaction
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:625)
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:604)
              at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:345)
              at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:245)
              at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
              at org.jboss.seam.mock.AbstractSeamTest$Request.restoreViewPhase(AbstractSeamTest.java:756)
              at org.jboss.seam.mock.AbstractSeamTest$Request.emulateJsfLifecycle(AbstractSeamTest.java:583)
              at org.jboss.seam.mock.AbstractSeamTest$Request.access$100(AbstractSeamTest.java:177)
              at org.jboss.seam.mock.AbstractSeamTest$Request$2.doFilter(AbstractSeamTest.java:497)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
      ...................
      
      Caused by: java.lang.RuntimeException: exception invoking: getTransaction
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:154)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2249)
              at org.jboss.seam.Component.unwrap(Component.java:2275)
              at org.jboss.seam.Component.getInstance(Component.java:2041)
              at org.jboss.seam.Component.getInstance(Component.java:2000)
              at org.jboss.seam.Component.getInstance(Component.java:1994)
              at org.jboss.seam.Component.getInstance(Component.java:1967)
              at org.jboss.seam.Component.getInstance(Component.java:1962)
              at org.jboss.seam.transaction.Transaction.instance(Transaction.java:39)
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:610)
              ... 55 more
      Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as a
      n applet parameter, or in an application resource file:  java.naming.factory.initial
              at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
              at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
              at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
              at javax.naming.InitialContext.lookup(InitialContext.java:351)
              at org.jboss.seam.transaction.Transaction.getUserTransaction(Transaction.java:82)
              at org.jboss.seam.transaction.Transaction.createUTTransaction(Transaction.java:74)
              at org.jboss.seam.transaction.Transaction.getTransaction(Transaction.java:47)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
      



      appreciate any help


      thanks


      Bartek



        • 1. Re: SeamTest NoInitialContextException
          Jean Luc Apprentice

          Might be a problem with your components.xml and its settings relevant to transactions and JNDI. Post that file.


          Also, put a breakpoint where it fails and dig around.

          • 2. Re: SeamTest NoInitialContextException
            Bartek Wasko Newbie

            Jean Luc , thanks for your reply, here is my components.xml :


            <component name="org.jboss.seam.core.init">
                <property name="debug">${seam.debug}</property>
                <property name="jndiPattern">${ear.artifactId}-${version}/#{ejbName}/local
                </property>
              </component>
            
              <core:manager concurrent-request-timeout="500"
                  conversation-timeout="120000"
                  conversation-id-parameter="cid"
                  parent-conversation-id-parameter="pid"/>
            
              <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
              <web:hot-deploy-filter url-pattern="*.seam"/>
            
              <persistence:managed-persistence-context name="entityManager" auto-create="true"
                  persistence-unit-jndi-name="java:/invoices-EntityManagerFactory"/>
            
              <mail:mail-session host="dns.consol.pl" port="25" username="rafal2" password="consol"/>
            
              <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
            
            .......
            here some standard home components declarations etc
            
            



            • 3. Re: SeamTest NoInitialContextException
              Jean Luc Apprentice

              Hmm.. similar to mine but not identical... for the embedded server try #{ejbName}/local only, IIRC there is something different about it with regards to JNDI lookups. That's what I use for the test server.


              Another minor difference which I don't believe makes a difference is that I use <core:init ...> instead of <component name="org.jboss.seam.core.init">...

              • 4. Re: SeamTest NoInitialContextException
                Bartek Wasko Newbie

                Ok, my fault, sorry for bothering, I had jboss-embedded dependencies messed up, I rewrite them and all works like a charm.


                Thanks for help :)


                bartek