01: package com.mockrunner.test.ejb;
02:
03: import javax.transaction.Status;
04:
05: import com.mockrunner.mock.ejb.MockUserTransaction;
06:
07: import junit.framework.TestCase;
08:
09: public class MockUserTransactionTest extends TestCase {
10: public void testBegin() throws Exception {
11: MockUserTransaction transaction = new MockUserTransaction();
12: transaction.commit();
13: transaction.setRollbackOnly();
14: transaction.setTransactionTimeout(10);
15: assertFalse(transaction.wasBeginCalled());
16: transaction.begin();
17: assertTrue(transaction.wasBeginCalled());
18: assertFalse(transaction.wasCommitCalled());
19: assertFalse(transaction.wasRollbackCalled());
20: assertFalse(transaction.wasRollbackOnlyCalled());
21: }
22:
23: public void testNumberCalls() throws Exception {
24: MockUserTransaction transaction = new MockUserTransaction();
25: transaction.begin();
26: transaction.commit();
27: transaction.begin();
28: transaction.setRollbackOnly();
29: transaction.begin();
30: transaction.rollback();
31: transaction.begin();
32: transaction.commit();
33: assertEquals(4, transaction.getNumberBeginCalls());
34: assertEquals(2, transaction.getNumberCommitCalls());
35: assertEquals(1, transaction.getNumberRollbackCalls());
36: assertEquals(1, transaction.getNumberRollbackOnlyCalls());
37: }
38:
39: public void testReset() throws Exception {
40: MockUserTransaction transaction = new MockUserTransaction();
41: transaction.begin();
42: transaction.commit();
43: transaction.begin();
44: transaction.setRollbackOnly();
45: transaction.begin();
46: transaction.rollback();
47: transaction.begin();
48: transaction.commit();
49: transaction.reset();
50: assertFalse(transaction.wasBeginCalled());
51: assertFalse(transaction.wasCommitCalled());
52: assertFalse(transaction.wasRollbackCalled());
53: assertFalse(transaction.wasRollbackOnlyCalled());
54: assertEquals(0, transaction.getTransactionTimeout());
55: assertEquals(0, transaction.getNumberBeginCalls());
56: assertEquals(0, transaction.getNumberCommitCalls());
57: assertEquals(0, transaction.getNumberRollbackCalls());
58: assertEquals(0, transaction.getNumberRollbackOnlyCalls());
59: }
60:
61: public void testGetStatus() throws Exception {
62: MockUserTransaction transaction = new MockUserTransaction();
63: assertEquals(Status.STATUS_NO_TRANSACTION, transaction
64: .getStatus());
65: transaction.begin();
66: assertEquals(Status.STATUS_ACTIVE, transaction.getStatus());
67: transaction.commit();
68: assertEquals(Status.STATUS_COMMITTED, transaction.getStatus());
69: transaction.begin();
70: assertEquals(Status.STATUS_ACTIVE, transaction.getStatus());
71: transaction.rollback();
72: assertEquals(Status.STATUS_ROLLEDBACK, transaction.getStatus());
73: transaction.begin();
74: assertEquals(Status.STATUS_ACTIVE, transaction.getStatus());
75: transaction.setRollbackOnly();
76: assertEquals(Status.STATUS_MARKED_ROLLBACK, transaction
77: .getStatus());
78: transaction.rollback();
79: assertEquals(Status.STATUS_ROLLEDBACK, transaction.getStatus());
80: }
81: }
|