001 package com.mockrunner.mock.connector.cci;
002
003 import javax.resource.ResourceException;
004 import javax.resource.cci.LocalTransaction;
005
006 /**
007 * Mock implementation of <code>LocalTransaction</code>.
008 */
009 public class MockLocalTransaction implements LocalTransaction
010 {
011 private boolean beginCalled;
012 private boolean commitCalled;
013 private boolean rollbackCalled;
014 private int beginCalls;
015 private int commitCalls;
016 private int rollbackCalls;
017
018 public MockLocalTransaction()
019 {
020 reset();
021 }
022
023 /**
024 * Resets the transaction state. Sets the number of overall
025 * begin, commit and rollback calls to <code>0</code>.
026 */
027 public void reset()
028 {
029 beginCalled = false;
030 commitCalled = false;
031 rollbackCalled = false;
032 beginCalls = 0;
033 commitCalls = 0;
034 rollbackCalls = 0;
035 }
036
037 /**
038 * Starts the transaction. The flags <code>wasCommitCalled</code>
039 * and <code>wasRollbackCalled</code> are reset to <code>false</code>.
040 * This method does not reset the number of overall calls.
041 */
042 public void begin() throws ResourceException
043 {
044 beginCalled = true;
045 commitCalled = false;
046 rollbackCalled = false;
047 beginCalls++;
048 }
049
050 /**
051 * Commits the transaction.
052 */
053 public void commit() throws ResourceException
054 {
055 commitCalled = true;
056 commitCalls++;
057 }
058
059 /**
060 * Rolls back the transaction.
061 */
062 public void rollback() throws ResourceException
063 {
064 rollbackCalled = true;
065 rollbackCalls++;
066 }
067
068 /**
069 * Returns if {@link #begin} was called.
070 * @return was {@link #begin} called
071 */
072 public boolean wasBeginCalled()
073 {
074 return beginCalled;
075 }
076
077 /**
078 * Returns if {@link #commit} was called.
079 * @return was {@link #commit} called
080 */
081 public boolean wasCommitCalled()
082 {
083 return commitCalled;
084 }
085
086 /**
087 * Returns if {@link #rollback} was called.
088 * @return was {@link #rollback} called
089 */
090 public boolean wasRollbackCalled()
091 {
092 return rollbackCalled;
093 }
094
095 /**
096 * Returns the number of overall {@link #begin} calls.
097 * @return the number of overall {@link #begin} calls
098 */
099 public int getNumberBeginCalls()
100 {
101 return beginCalls;
102 }
103
104 /**
105 * Returns the number of overall {@link #commit} calls.
106 * @return the number of overall {@link #commit} calls
107 */
108 public int getNumberCommitCalls()
109 {
110 return commitCalls;
111 }
112
113 /**
114 * Returns the number of overall {@link #rollback} calls.
115 * @return the number of overall {@link #rollback} calls
116 */
117 public int getNumberRollbackCalls()
118 {
119 return rollbackCalls;
120 }
121 }