1 17 18 package org.apache.geronimo.transaction.manager; 19 20 import javax.transaction.Status ; 21 import javax.transaction.Transaction ; 22 import javax.transaction.TransactionManager ; 23 import javax.transaction.xa.XAResource ; 24 25 import junit.framework.TestCase; 26 27 32 public class TestTransactionManager extends TestCase { 33 TransactionManager tm; 34 MockResourceManager rm1, rm2, rm3; 35 36 public void testNoTransaction() throws Exception { 37 assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus()); 38 assertNull(tm.getTransaction()); 39 } 40 41 public void testNoResource() throws Exception { 42 Transaction tx; 43 assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus()); 44 tm.begin(); 45 assertEquals(Status.STATUS_ACTIVE, tm.getStatus()); 46 tx = tm.getTransaction(); 47 assertNotNull(tx); 48 assertEquals(Status.STATUS_ACTIVE, tx.getStatus()); 49 tm.rollback(); 50 assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus()); 51 assertNull(tm.getTransaction()); 52 assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus()); 53 54 tm.begin(); 55 assertEquals(Status.STATUS_ACTIVE, tm.getStatus()); 56 tm.rollback(); 57 assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus()); 58 } 59 60 public void testTxOp() throws Exception { 61 Transaction tx; 62 tm.begin(); 63 tx = tm.getTransaction(); 64 tx.rollback(); 65 assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus()); 66 assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus()); 67 68 tm.begin(); 69 assertFalse(tx.equals(tm.getTransaction())); 70 tm.rollback(); 71 } 72 73 public void testSuspend() throws Exception { 74 Transaction tx; 75 assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus()); 76 tm.begin(); 77 assertEquals(Status.STATUS_ACTIVE, tm.getStatus()); 78 tx = tm.getTransaction(); 79 assertNotNull(tx); 80 assertEquals(Status.STATUS_ACTIVE, tx.getStatus()); 81 82 tx = tm.suspend(); 83 assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus()); 84 assertNull(tm.getTransaction()); 85 86 tm.resume(tx); 87 assertEquals(Status.STATUS_ACTIVE, tm.getStatus()); 88 assertEquals(tx, tm.getTransaction()); 89 90 tm.rollback(); 91 assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus()); 92 assertNull(tm.getTransaction()); 93 } 94 95 public void testOneResource() throws Exception { 96 Transaction tx; 97 MockResource res1 = rm1.getResource("rm1"); 98 tm.begin(); 99 tx = tm.getTransaction(); 100 assertNull(res1.getCurrentXid()); 101 assertTrue(tx.enlistResource(res1)); 102 assertNotNull(res1.getCurrentXid()); 103 assertTrue(tx.delistResource(res1, XAResource.TMFAIL)); 104 assertNull(res1.getCurrentXid()); 105 tm.rollback(); 106 107 tm.begin(); 108 tx = tm.getTransaction(); 109 assertTrue(tx.enlistResource(res1)); 110 tm.rollback(); 111 assertNull(res1.getCurrentXid()); 112 } 113 114 protected void setUp() throws Exception { 115 tm = new TransactionManagerImpl(); 116 rm1 = new MockResourceManager(true); 117 rm2 = new MockResourceManager(true); 118 rm3 = new MockResourceManager(false); 119 } 120 } 121 | Popular Tags |