0 Replies Latest reply on Aug 1, 2013 10:07 AM by mblasi

    Arquillian JBoss managed and TomEE embedded tests transaction management

    mblasi

      I have a ejb project, with Arquillian unit tests working perfectly with both embedded TomEE and managed JBoss AS 7.1.1.Final

       

      Up to now, the transaction management is handled manually, asking for a UserTransaction injection to the container. begining, commiting and rolling back in each test manually.

       

      After some research I added the transaction-extension to my project:

       

      ...

       



      <dependency>



      <groupId>org.jboss.arquillian.extension</groupId>



      <artifactId>arquillian-transaction-jta</artifactId>



      <version>1.0.0.Alpha3</version>



      <scope>test</scope>


      </dependency>

       

      ...

       

      Now, my tests are marked with @Transactional, and I removed every begin()/commit()/rollback() from everywhere. Everything worked as expected in TomEE, but JBoss throws:

       

      Caused by: java.lang.RuntimeException: Failed obtaining transaction.

              at org.jboss.arquillian.transaction.jta.provider.JtaTransactionProvider.getUserTransaction(JtaTransactionProvider.java:118)

              at org.jboss.arquillian.transaction.jta.provider.JtaTransactionProvider.beginTransaction(JtaTransactionProvider.java:56)

              ... 68 more

      Caused by: javax.naming.NameNotFoundException: UserTransaction -- service jboss.naming.context.java.module.mercury.mercury-ejbs.UserTransaction

              at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)

              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)

              at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)

              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)

              at javax.naming.InitialContext.lookup(InitialContext.java:411)

              at org.jboss.arquillian.transaction.jta.provider.JtaTransactionProvider.getUserTransaction(JtaTransactionProvider.java:115)

              ... 69 more

       

       

      Then, I found overthere, that I have to configure the transaction extension in my arquillian.xml to work with JBoss container:

       

       





      <extension qualifier="transaction">


      <property name="manager">java:jboss/UserTransaction</property>

      </extension>



       

       

      After that, JBoss managed mode started working perfectly!

      But now, TomEE is failing:

       

      Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

              at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)

              at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)

              at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)

              at javax.naming.InitialContext.lookup(InitialContext.java:411)

              at org.apache.openejb.arquillian.transaction.OpenEJBTransactionProvider.lookup(OpenEJBTransactionProvider.java:60)

              at org.apache.openejb.arquillian.transaction.OpenEJBTransactionProvider.beginTransaction(OpenEJBTransactionProvider.java:32)

              ... 64 more

      testFindByEmail(com.collabnet.ctf.ejb.JPAUserRepositoryTest)  Time elapsed: 0.007 sec  <<< ERROR!

      java.lang.NullPointerException

              at org.jboss.arquillian.transaction.impl.lifecycle.TransactionHandler.testRequiresRollbackDueToFailure(TransactionHandler.java:150)

              at org.jboss.arquillian.transaction.impl.lifecycle.TransactionHandler.rollbackRequired(TransactionHandler.java:140)

              at org.jboss.arquillian.transaction.impl.lifecycle.TransactionHandler.endTransactionAfterTest(TransactionHandler.java:108)

              at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

              at java.lang.reflect.Method.invoke(Method.java:601)

              at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

              at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

              at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

              at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)

              at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createAfterContext(ContainerEventController.java:134)

              at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

              at java.lang.reflect.Method.invoke(Method.java:601)

       

       

      Then, I tried by configuring arquillian.xml as follows:

       

      <extension qualifier="transaction">

      <property name="manager"></property>
      </extension>




       

      Obviously, JBoss is failing again, but TomEE is working, so, my last try was to configure the extension thru a system property:

       

      <extension qualifier="transaction">

      <property name="manager">${arquillian.transaction.manager}</property>
      </extension>




       

      JBoss profile in pom.xml:

       

      ...








      <systemPropertyVariables>








      <arquillian.transaction.manager>java:jboss/UserTransaction</arquillian.transaction.manager>

       






      </systemPropertyVariables>

      ...

       

       

      And TomEE profile in pom.xml:

       

      ...

       






      <systemPropertyVariables>








      <arquillian.transaction.manager></arquillian.transaction.manager>

       






      </systemPropertyVariables>

      ...

       

      That does't work, JBoss is working, but TomEE is still failing in the same way...

       

      First of all, I don't understand WHY TomEE is starting to fail with "javax.naming.NoInitialContextException" when I add <extension qualifier="transaction"> configuration in my arquillian.xml

      By other hand, it has no sense to work correctly in TomEE with empty <property name="manager"></property> and fail with <property name="manager">${unexistant.property}</property>

       

      It seems to be something tricky, or buggy...

       

      I attach pom.xml, arquillian.xml and one of my tests.

       

      Either if you see something missing in my configuration or it is a bug, please let me know how could I make both containers run my tests with Container Managed Transactions (using @Transactional or something)

      Obviously, if it is a bug, I'll be filing it.

       

      Best regards,

      Matías.