1
2
3
4
5
6
7
8
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();
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
81 }
82
83 protected int doPrepare(AbstractTransactionContext context)
84 {
85
86 return 0;
87 }
88
89 protected void doCommit(AbstractTransactionContext context) throws ResourceManagerException
90 {
91
92 }
93
94 protected void doRollback(AbstractTransactionContext context) throws ResourceManagerException
95 {
96
97 }
98 }
99 }