1
2
3
4
5
6
7
8
9
10
11 package org.mule.transaction;
12
13 import org.mule.tck.AbstractMuleTestCase;
14 import org.mule.umo.UMOTransaction;
15
16 import com.mockobjects.dynamic.Mock;
17
18 public class TransactionCoordinationTestCase extends AbstractMuleTestCase
19 {
20 volatile TransactionCoordination tc;
21
22 protected void doSetUp() throws Exception
23 {
24 tc = TransactionCoordination.getInstance();
25 }
26
27 protected void doTearDown() throws Exception
28 {
29 tc.unbindTransaction(tc.getTransaction());
30 }
31
32 public void testBindTransaction() throws Exception
33 {
34 assertNull(tc.getTransaction());
35 Mock mockTx = new Mock(UMOTransaction.class, "trans");
36 UMOTransaction tx = (UMOTransaction)mockTx.proxy();
37
38 tc.bindTransaction(tx);
39 assertEquals(tx, tc.getTransaction());
40 tc.unbindTransaction(tx);
41 }
42
43 public void testBindTransactionWithAlreadyBound() throws Exception
44 {
45 assertNull(tc.getTransaction());
46 Mock mockTx = new Mock(UMOTransaction.class, "trans");
47 UMOTransaction tx = (UMOTransaction)mockTx.proxy();
48
49 tc.bindTransaction(tx);
50 assertEquals(tx, tc.getTransaction());
51
52 try
53 {
54 UMOTransaction tx2 = (UMOTransaction)new Mock(UMOTransaction.class, "trans").proxy();
55 tc.bindTransaction(tx2);
56 fail();
57 }
58 catch (IllegalTransactionStateException e)
59 {
60
61 }
62
63 tc.unbindTransaction(tx);
64 }
65
66 public void testUnbindTransactionWithoutBound() throws Exception
67 {
68 assertNull(tc.getTransaction());
69 Mock mockTx = new Mock(UMOTransaction.class, "trans");
70 UMOTransaction tx = (UMOTransaction)mockTx.proxy();
71 tc.unbindTransaction(tx);
72 }
73
74 public void testSetInstanceWithBound() throws Exception
75 {
76 assertNull(tc.getTransaction());
77 Mock mockTx = new Mock(UMOTransaction.class, "trans");
78 UMOTransaction tx = (UMOTransaction)mockTx.proxy();
79
80 tc.bindTransaction(tx);
81
82 tc.unbindTransaction(tx);
83 }
84
85 }