1   /*
2    * $Id: SpringTransactionFactoryTestCase.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.extras.spring.transaction;
12  
13  import org.mule.tck.AbstractMuleTestCase;
14  import org.mule.transaction.TransactionCoordination;
15  import org.mule.umo.UMOTransaction;
16  
17  import com.mockobjects.dynamic.C;
18  import com.mockobjects.dynamic.Mock;
19  
20  import org.springframework.transaction.PlatformTransactionManager;
21  import org.springframework.transaction.TransactionStatus;
22  
23  public class SpringTransactionFactoryTestCase extends AbstractMuleTestCase
24  {
25  
26      public void testCommit() throws Exception
27      {
28          Mock mockPTM = new Mock(PlatformTransactionManager.class);
29          Mock mockTS = new Mock(TransactionStatus.class);
30          mockPTM.expectAndReturn("getTransaction", C.same(null), mockTS.proxy());
31          mockPTM.expect("commit", C.same(mockTS.proxy()));
32  
33          SpringTransactionFactory factory = new SpringTransactionFactory();
34          factory.setManager((PlatformTransactionManager)mockPTM.proxy());
35  
36          UMOTransaction tx = factory.beginTransaction();
37          TransactionCoordination.getInstance().bindTransaction(tx);
38          tx.commit();
39      }
40  
41      public void testRollback() throws Exception
42      {
43          Mock mockPTM = new Mock(PlatformTransactionManager.class);
44          Mock mockTS = new Mock(TransactionStatus.class);
45          mockPTM.expectAndReturn("getTransaction", C.same(null), mockTS.proxy());
46          mockPTM.expect("rollback", C.same(mockTS.proxy()));
47          mockTS.expect("setRollbackOnly");
48  
49          SpringTransactionFactory factory = new SpringTransactionFactory();
50          factory.setManager((PlatformTransactionManager)mockPTM.proxy());
51  
52          UMOTransaction tx = factory.beginTransaction();
53          TransactionCoordination.getInstance().bindTransaction(tx);
54          tx.rollback();
55      }
56  
57  }