View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.tck.testmodels.mule;
8   
9   import org.mule.api.MuleContext;
10  import org.mule.api.transaction.TransactionException;
11  import org.mule.transaction.AbstractSingleResourceTransaction;
12  
13  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
14  
15  /**
16   * A test transaction that does nothing on commit or rollback. The transaction does retain a status so that
17   * developers can determine if the the transaction was rolled back or committed.
18   */
19  public class TestTransaction extends AbstractSingleResourceTransaction
20  {
21      private AtomicBoolean committed = new AtomicBoolean(false);
22      private AtomicBoolean rolledBack = new AtomicBoolean(false);
23  
24      private String testProperty;
25  
26      public TestTransaction(MuleContext muleContext)
27      {
28          super(muleContext);
29      }
30  
31      /**
32       * Really begin the transaction. Note that resources are enlisted yet.
33       *
34       * @throws org.mule.api.transaction.TransactionException
35       *
36       */
37      protected void doBegin() throws TransactionException
38      {
39          //do nothing
40      }
41  
42      /**
43       * Commit the transaction on the underlying resource
44       *
45       * @throws org.mule.api.transaction.TransactionException
46       *
47       */
48      protected void doCommit() throws TransactionException
49      {
50          committed.set(true);
51      }
52  
53      /**
54       * Rollback the transaction on the underlying resource
55       *
56       * @throws org.mule.api.transaction.TransactionException
57       *
58       */
59      protected void doRollback() throws TransactionException
60      {
61          rolledBack.set(true);
62      }
63  
64      public String getTestProperty()
65      {
66          return testProperty;
67      }
68  
69      public void setTestProperty(String testProperty)
70      {
71          this.testProperty = testProperty;
72      }
73  }