6 Replies Latest reply on Oct 19, 2014 5:51 AM by Tibor Digana

    Wildfly TransactionManager implementation

    Miroslav Ivaniš Newbie

      Heloo,

       

      I am developing web application which runs on Wildfly 8.1.0. In my JUnit tests I want to test my service classes. These service classes are using javax.inject.Inject and javax.transaction.Transactional annotations. I use  Deltapike Weld and Wildfly-Weld to enable these annotations. My dependecies are:

       

       

              <dependency>

                  <groupId>junit</groupId>

                  <artifactId>junit</artifactId>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.easytesting</groupId>

                  <artifactId>fest-assert-core</artifactId>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.apache.deltaspike.cdictrl</groupId>

                  <artifactId>deltaspike-cdictrl-weld</artifactId>

                  <version>1.0.1</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.jboss.weld.se</groupId>

                  <artifactId>weld-se</artifactId>

                  <version>2.1.2.Final</version>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.wildfly</groupId>

                  <artifactId>wildfly-weld</artifactId>

                  <version>8.1.0.Final</version>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>sun.jdk</groupId>

                          <artifactId>jconsole</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <groupId>org.apache.deltaspike.modules</groupId>

                  <artifactId>deltaspike-test-control-module-impl</artifactId>

                  <scope>test</scope>

              </dependency>

              <dependency>

                  <groupId>org.apache.deltaspike.modules</groupId>

                  <artifactId>deltaspike-jpa-module-impl</artifactId>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>org.apache.geronimo.specs</groupId>

                          <artifactId>*</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <groupId>org.apache.deltaspike.modules</groupId>

                  <artifactId>deltaspike-jsf-module-impl</artifactId>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>org.apache.geronimo.specs</groupId>

                          <artifactId>*</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <!--&lt;!&ndash; Deltaspike 1.0.1 workaround, see the unitests BOM. &ndash;&gt;-->

                  <groupId>org.apache.myfaces.test</groupId>

                  <artifactId>myfaces-test20</artifactId>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>junit</groupId>

                          <artifactId>junit</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <!-- &lt;!&ndash; Deltaspike 1.0.1 workaround, see the unitests BOM. &ndash;&gt;-->

                  <groupId>org.apache.myfaces.core</groupId>

                  <artifactId>myfaces-impl-test</artifactId>

                  <scope>test</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>org.apache.geronimo.specs</groupId>

                          <artifactId>*</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

       

      My simple Junit test class is:

       

      @RunWith(CdiTestRunner.class)

      public class MyTest {

       

          @Inject

          TenantService tenantService;

       

          @Before

          public void before() {

              assertNotNull(tenantService);

          }

       

          @Test

          public void storeAndLoad() {

       

              TenantViewData tenantViewData = new TenantViewData();

              Tenant tenant = new Tenant(new TenantName("simple-tenant"));

              tenant.setTenantURL(new TenantURL("localhost:8080"));

              tenantViewData.setTenant(tenant);

       

               /* on this line i got the exception */

              tenantService.saveTenant(tenantViewData);

          }

      }

       

      Method saveTenant is annotated with @Transactional. My JUnit test throwas exception before it goes into this method. The exception is:

       

      javax.enterprise.context.ContextNotActiveException: ARJUNA016105: Could not lookup the TransactionManager

        at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.getTransactionManager(TransactionalInterceptorBase.java:169)

        at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:45)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

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

        at org.jboss.weld.interceptor.proxy.SimpleMethodInvocation.invoke(SimpleMethodInvocation.java:30)

        at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNext(AbstractInterceptionChain.java:103)

        at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNextInterceptor(AbstractInterceptionChain.java:81)

        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:48)

        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:41)

        at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:53)

        at com.scheidtbachmann.shared.tenant.crud.business.service.TenantServiceImpl$Proxy$_$$_WeldSubclass.saveTenant(Unknown Source)

        at com.scheidtbachmann.shared.tenant.crud.business.service.TenantServiceImpl$Proxy$_$$_WeldClientProxy.saveTenant(Unknown Source)

        at com.scheidtbachmann.shared.tenant.crud.MyTest.storeAndLoad(MyTest.java:76)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

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

        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.invokeMethod(CdiTestRunner.java:335)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.evaluate(CdiTestRunner.java:307)

        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:169)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:67)

        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$BeforeClassStatement.evaluate(CdiTestRunner.java:361)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$AfterClassStatement.evaluate(CdiTestRunner.java:387)

        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

        at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.run(CdiTestRunner.java:136)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:160)

        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)

        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)

        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

      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 com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.getTransactionManager(TransactionalInterceptorBase.java:167)

        ... 46 more

       

      It crashes in com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase on line:


      transactionManager = (TransactionManager) initialContext.lookup("java:jboss/TransactionManager");

       

      I tried to find an implementation of TransactionManager in Wildfly 8.1.0 project but I did not find any implementation, so I think Wildfly uses some implementation from external library. I would like to know which library (dependency) should I add to my maven project to get this implementation of Transactional manager. Thanks