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