1   /*
2    * $Id: XaTransactionTestCase.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.MuleManager;
14  import org.mule.tck.AbstractMuleTestCase;
15  import org.mule.umo.UMOTransaction;
16  
17  import com.mockobjects.dynamic.Mock;
18  
19  import javax.transaction.Transaction;
20  import javax.transaction.TransactionManager;
21  
22  public class XaTransactionTestCase extends AbstractMuleTestCase
23  {
24      protected Mock mockTm = new Mock(TransactionManager.class);
25  
26      protected void doSetUp() throws Exception
27      {
28          TransactionManager tm = (TransactionManager)mockTm.proxy();
29          MuleManager.getInstance().setTransactionManager(tm);
30      }
31  
32      public void testBeginCommit() throws Exception
33      {
34          Mock mockTx = new Mock(Transaction.class);
35          mockTm.expect("begin");
36          mockTm.expectAndReturn("getTransaction", mockTx.proxy());
37  
38          XaTransaction tx = new XaTransaction();
39          assertFalse(tx.isBegun());
40          assertEquals(UMOTransaction.STATUS_NO_TRANSACTION, tx.getStatus());
41          tx.begin();
42  
43          mockTx.expectAndReturn("getStatus", UMOTransaction.STATUS_ACTIVE);
44          assertTrue(tx.isBegun());
45  
46          mockTx.expectAndReturn("getStatus", UMOTransaction.STATUS_ACTIVE);
47          mockTx.expect("commit");
48          tx.commit();
49  
50          mockTx.expectAndReturn("getStatus", UMOTransaction.STATUS_COMMITTED);
51          assertTrue(tx.isCommitted());
52      }
53  
54  }