View Javadoc

1   /*
2    * $Id: TransactionCoordinationTestCase.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.transaction;
12  
13  import org.mule.api.transaction.Transaction;
14  import org.mule.tck.AbstractMuleTestCase;
15  
16  import org.mockito.Mockito;
17  
18  public class TransactionCoordinationTestCase extends AbstractMuleTestCase
19  {
20      private TransactionCoordination tc;
21  
22      @Override
23      protected void doSetUp() throws Exception
24      {
25          tc = TransactionCoordination.getInstance();
26      }
27  
28      @Override
29      protected void doTearDown() throws Exception
30      {
31          tc.unbindTransaction(tc.getTransaction());
32      }
33  
34      public void testBindTransaction() throws Exception
35      {
36          assertNull(tc.getTransaction());
37          Transaction tx = Mockito.mock(Transaction.class);
38  
39          tc.bindTransaction(tx);
40          assertEquals(tx, tc.getTransaction());
41          tc.unbindTransaction(tx);
42      }
43  
44      public void testBindTransactionWithAlreadyBound() throws Exception
45      {
46          assertNull(tc.getTransaction());
47          Transaction tx = Mockito.mock(Transaction.class);
48  
49          tc.bindTransaction(tx);
50          assertEquals(tx, tc.getTransaction());
51  
52          try
53          {
54              Transaction tx2 = Mockito.mock(Transaction.class);
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          Transaction tx = Mockito.mock(Transaction.class);
70  
71          tc.unbindTransaction(tx);
72      }
73  
74      public void testSetInstanceWithBound() throws Exception
75      {
76          assertNull(tc.getTransaction());
77          Transaction tx = Mockito.mock(Transaction.class);
78  
79          tc.bindTransaction(tx);
80  
81          tc.unbindTransaction(tx);
82      }
83  }