1   /*
2    * $Id: TransactionCoordinationTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.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              // expected
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  }