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