1 Reply Latest reply on Dec 1, 2009 3:15 PM by Konstantin Larionov

    Seam Testing with Database Access

    Sidharta Surya Kusnanto Newbie

      Hi all,
      I've been struggling with Seam Integration testing for the past few weeks with no luck. The testing guide in the reference offer very little clues on Seam testing best practices.
      I was trying to test an action class that injects entityManager in it, everything works perfectly on the dev environment, but when I run the test, the console complains:


      [testng] java.lang.AssertionError: javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:/entityManager
         [testng]      at org.jboss.seam.mock.AbstractSeamTest$Request.onException(AbstractSeamTest.java:455)
         [testng]      at org.jboss.seam.mock.AbstractSeamTest$Request$2.doFilter(AbstractSeamTest.java:504)
         [testng]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
         [testng]      at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
         [testng]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         [testng]      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
         [testng]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         [testng]      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
         [testng]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         [testng]      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
         [testng]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         [testng]      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
         [testng]      at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
         [testng]      at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
         [testng]      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
         [testng]      at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
         [testng]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         [testng]      at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
         [testng]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         [testng]      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
         [testng]      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
         [testng]      at org.jboss.seam.mock.AbstractSeamTest$Request.run(AbstractSeamTest.java:491)
         [testng]      at com.mavenlab.apolloscranberry.test.SMSValidationIntegrationTest.TestSMSValidSMS(SMSValidationIntegrationTest.java:33)
         [testng] Caused by: javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:/entityManager
         [testng]      at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339)
         [testng]      at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:280)
         [testng]      at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
         [testng]      at org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65)
         [testng]      at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
         [testng]      at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
         [testng]      at org.jboss.seam.mock.AbstractSeamTest$Request.invokeMethod(AbstractSeamTest.java:463)
         [testng]      at com.mavenlab.apolloscranberry.test.SMSValidationIntegrationTest$1.invokeApplication(SMSValidationIntegrationTest.java:29)
         [testng]      at org.jboss.seam.mock.AbstractSeamTest$Request.invokeApplicationPhase(AbstractSeamTest.java:646)
         [testng]      at org.jboss.seam.mock.AbstractSeamTest$Request.emulateJsfLifecycle(AbstractSeamTest.java:595)
         [testng]      at org.jboss.seam.mock.AbstractSeamTest$Request.access$100(AbstractSeamTest.java:177)
         [testng]      at org.jboss.seam.mock.AbstractSeamTest$Request$2.doFilter(AbstractSeamTest.java:497)
         [testng]      ... 43 more
         [testng] Caused by: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:/entityManager
         [testng]      at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:91)
         [testng]      at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
         [testng]      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:64)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:166)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:249)
         [testng]      at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
         [testng]      at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:86)
         [testng]      at $Proxy78.process(Unknown Source)
         [testng]      at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
         [testng]      at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
         [testng]      at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
         [testng]      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
         [testng]      at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
         [testng]      at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
         [testng]      at org.javassist.tmp.java.lang.Object_$$_javassist_seam_2.process(Object_$$_javassist_seam_2.java)
         [testng]      at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
         [testng]      ... 54 more
         [testng] Caused by: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:/entityManager
         [testng]      at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:245)
         [testng]      at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:78)
         [testng]      at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:107)
         [testng]      at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
         [testng]      at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
         [testng]      at org.jboss.seam.Component.callComponentMethod(Component.java:2249)
         [testng]      at org.jboss.seam.Component.unwrap(Component.java:2275)
         [testng]      at org.jboss.seam.Component.getInstance(Component.java:2041)
         [testng]      at org.jboss.seam.Component.getInstance(Component.java:1983)
         [testng]      at org.jboss.seam.Component.getInstance(Component.java:1977)
         [testng]      at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
         [testng]      at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
         [testng]      at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148)
         [testng]      at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51)
         [testng]      at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
         [testng]      at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
         [testng]      at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
         [testng]      at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
         [testng]      at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:112)
         [testng]      at org.jboss.seam.Component.getValueToInject(Component.java:2292)
         [testng]      at org.jboss.seam.Component.injectAttributes(Component.java:1736)
         [testng]      at org.jboss.seam.Component.inject(Component.java:1554)
         [testng]      at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
         [testng]      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         [testng]      at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
         [testng]      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         [testng]      at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
         [testng]      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         [testng]      at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
         [testng]      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         [testng]      at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
         [testng]      at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
         [testng]      at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
         [testng]      at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
         [testng]      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         [testng]      at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
         [testng]      ... 88 more
         [testng] Caused by: javax.naming.NameNotFoundException: entityManager not bound
         [testng]      at org.jnp.server.NamingServer.getBinding(NamingServer.java:542)
         [testng]      at org.jnp.server.NamingServer.getBinding(NamingServer.java:550)
         [testng]      at org.jnp.server.NamingServer.getObject(NamingServer.java:556)
         [testng]      at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
         [testng]      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669)
         [testng]      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
         [testng]      at javax.naming.InitialContext.lookup(InitialContext.java:392)
         [testng]      at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:241)
         [testng]      ... 135 more



      This is my components-test.prop


      jndiPattern=#{ejbName}/local
      debug=true
      seamBootstrapsPu=true
      seamEmfRef=#{entityManagerFactory}
      puJndiName=#{null}



      This is my persistence-test.xml


      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for tests -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
                   version="1.0">
                   
         <persistence-unit name="ApollosCranberry">
            <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="jboss.entity.manager.factory.jndi.name" value="java:/ApollosCranberryEntityManagerFactory"/>
            </properties>
         </persistence-unit>
          
      </persistence>



      Am I missing something? FYI, I generated the project through seam-gen but still the testing part doesn't work right out the box. Can someone explains what're the best practices for doing integration testing in Seam, especially those who are using entityManagers. I've searched the forum for similar issues, which there are, but there aren't any satisfying answers regarding this issue yet. Thanks in advance.

        • 1. Re: Seam Testing with Database Access
          Konstantin Larionov Newbie

          Seam tests work fine in our environment.


          We have only


          jndiPattern=\#{ejbName}/local
          embeddedEjb=true



          in /my-test/test-src/components.properties and have no special persistence-test.xml
          In /my-test/bootstrap/deploy/ we have my-test-ds.xml which is configured to use HSQL instead of production database:


          <?xml version="1.0" encoding="UTF-8"?>
          <datasources>
          
              <local-tx-datasource>
          
                  <jndi-name>MyDs</jndi-name>
                  <connection-url>jdbc:hsqldb:.</connection-url>
                  <driver-class>org.hsqldb.jdbcDriver</driver-class>
                  <user-name>sa</user-name>
                  <password></password>
                  <min-pool-size>0</min-pool-size>
                  <max-pool-size>20</max-pool-size>
                  <idle-timeout-minutes>0</idle-timeout-minutes>
                  <track-statements />
                  <security-domain>HsqlDbRealm</security-domain>
                  <prepared-statement-cache-size>32</prepared-statement-cache-size>
                  <depends>jboss:service=Hypersonic,database=localDB</depends>
          
              </local-tx-datasource>
          
          </datasources>