1 7 8 package org.jboss.cache.pojo.rollback; 9 10 import junit.framework.TestCase; 11 import junit.framework.Test; 12 import junit.framework.TestSuite; 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.jboss.cache.pojo.PojoCache; 16 import org.jboss.cache.pojo.PojoCacheFactory; 17 import org.jboss.cache.pojo.test.Person; 18 import org.jboss.cache.transaction.DummyTransactionManager; 19 import org.jboss.aop.proxy.ClassProxy; 20 21 import javax.transaction.TransactionManager ; 22 import java.util.ArrayList ; 23 24 29 30 public class ListTxUndoTest extends TestCase 31 { 32 Log log_ = LogFactory.getLog(ListTxUndoTest.class); 33 PojoCache cache_; 34 TransactionManager tx_mgr; 35 36 public ListTxUndoTest(String name) 37 { 38 super(name); 39 } 40 41 protected void setUp() throws Exception 42 { 43 super.setUp(); 44 log_.info("setUp() ...."); 45 String configFile = "META-INF/local-service.xml"; 46 boolean toStart = false; 47 cache_ = PojoCacheFactory.createCache(configFile, toStart); 48 cache_.start(); 49 tx_mgr = DummyTransactionManager.getInstance(); 50 51 } 52 53 protected void tearDown() throws Exception 54 { 55 super.tearDown(); 56 cache_.stop(); 57 } 58 59 61 public void testSimple() throws Exception 62 { 63 ArrayList list = new ArrayList (); 64 list.add("test1"); 65 66 tx_mgr.begin(); 67 cache_.attach("/a", list); 68 tx_mgr.getTransaction().rollback(); 69 assertFalse("Should not have cache interceptor ", isProxy(list)); 70 71 cache_.attach("/a", list); 72 } 73 74 public void testSimpleTxWithRollback1() throws Exception 75 { 76 log_.info("testSimpleTxWithRollback1() ...."); 77 Person test = new Person(); 78 test.setName("Ben"); 79 test.setAge(10); 80 ArrayList list = new ArrayList (); 81 list.add("English"); 82 test.setLanguages(list); 83 84 tx_mgr.begin(); 85 cache_.attach("/a", test); 86 tx_mgr.getTransaction().rollback(); 87 assertFalse("Should not have cache interceptor ", isProxy(test.getLanguages())); 88 89 cache_.attach("/a", test); 90 } 91 92 private boolean isProxy(Object pojo) 93 { 94 if(pojo instanceof ClassProxy) return true; 95 return false; 96 } 97 98 public void testSimpleTxWithRollback2() throws Exception 99 { 100 log_.info("testSimpleTxWithRollback1() ...."); 101 Person test = new Person(); 102 test.setName("Ben"); 103 test.setAge(10); 104 ArrayList list = new ArrayList (); 105 list.add("English"); 106 test.setLanguages(list); 107 108 cache_.attach("/a", test); 109 110 tx_mgr.begin(); 111 cache_.detach("/a"); 112 tx_mgr.getTransaction().rollback(); 113 114 assertTrue("Should still have cache interceptor ", isProxy(test.getLanguages())); 115 cache_.detach("/a"); 116 } 117 118 public void testSimpleTxWithRollback3() throws Exception 119 { 120 log_.info("testSimpleTxWithRollback1() ...."); 121 Person test = new Person(); 122 test.setName("Ben"); 123 test.setAge(10); 124 ArrayList list = new ArrayList (); 125 list.add("English"); 126 test.setLanguages(list); 127 tx_mgr.begin(); 128 cache_.attach("/a", test); 129 cache_.detach("/a"); 130 tx_mgr.getTransaction().rollback(); 131 132 assertFalse("Should not have cache interceptor ", isProxy(test.getLanguages())); 133 } 134 135 public static Test suite() throws Exception 136 { 137 return new TestSuite(ListTxUndoTest.class); 138 } 139 140 141 public static void main(String [] args) throws Exception 142 { 143 junit.textui.TestRunner.run(ListTxUndoTest.suite()); 144 } 145 146 } 147 | Popular Tags |