View Javadoc

1   /*
2    * $Id: XAResourceManagerTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.test.integration.transaction;
12  
13  import org.mule.module.jboss.transaction.JBossArjunaTransactionManagerFactory;
14  import org.mule.tck.AbstractMuleTestCase;
15  import org.mule.util.xa.AbstractTransactionContext;
16  import org.mule.util.xa.AbstractXAResourceManager;
17  import org.mule.util.xa.DefaultXASession;
18  import org.mule.util.xa.ResourceManagerException;
19  
20  import javax.transaction.Transaction;
21  import javax.transaction.TransactionManager;
22  import javax.transaction.xa.XAResource;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  public class XAResourceManagerTestCase extends AbstractMuleTestCase
28  {
29      private TransactionManager tm;
30  
31      protected void doSetUp() throws Exception
32      {
33          tm = new JBossArjunaTransactionManagerFactory().create(muleContext.getConfiguration());
34      }
35  
36      protected void doTearDown() throws Exception
37      {
38          tm = null;
39      }
40  
41      public void testTxBehaviour() throws Exception
42      {
43          TestXAResourceManager rm = new TestXAResourceManager();
44          rm.start();
45          DefaultXASession s = rm.createSession();
46  
47          tm.begin();
48          Transaction tx = tm.getTransaction();
49          tx.enlistResource(s);
50  
51          tx.delistResource(s, XAResource.TMSUCCESS);
52          tx.commit();
53  
54      }
55  
56      protected static class TestXAResourceManager extends AbstractXAResourceManager
57      {
58  
59          private static Log logger = LogFactory.getLog(TestXAResourceManager.class);
60  
61          public DefaultXASession createSession()
62          {
63              return new DefaultXASession(this);
64          }
65  
66          protected Log getLogger()
67          {
68              return logger;
69          }
70  
71          protected AbstractTransactionContext createTransactionContext(Object session)
72          {
73              return new AbstractTransactionContext() 
74              {
75              };
76          }
77  
78          protected void doBegin(AbstractTransactionContext context)
79          {
80              // template method
81          }
82  
83          protected int doPrepare(AbstractTransactionContext context)
84          {
85              // template method
86              return 0;
87          }
88  
89          protected void doCommit(AbstractTransactionContext context) throws ResourceManagerException
90          {
91              // template method
92          }
93  
94          protected void doRollback(AbstractTransactionContext context) throws ResourceManagerException
95          {
96              // template method
97          }
98      }
99  }