KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > pojo > rollback > ListTxUndoTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
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 JavaDoc;
22 import java.util.ArrayList JavaDoc;
23
24 /**
25  * Additional basic tests
26  *
27  * @author Ben Wang
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    public ListTxUndoTest(String JavaDoc name)
37    {
38       super(name);
39    }
40
41    protected void setUp() throws Exception JavaDoc
42    {
43       super.setUp();
44       log_.info("setUp() ....");
45       String JavaDoc 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 JavaDoc
54    {
55       super.tearDown();
56       cache_.stop();
57    }
58
59 // public void testDummy() {}
60

61    public void testSimple() throws Exception JavaDoc
62    {
63       ArrayList JavaDoc list = new ArrayList JavaDoc();
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 JavaDoc
75    {
76       log_.info("testSimpleTxWithRollback1() ....");
77       Person test = new Person();
78       test.setName("Ben");
79       test.setAge(10);
80       ArrayList JavaDoc list = new ArrayList JavaDoc();
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 JavaDoc pojo)
93    {
94       if(pojo instanceof ClassProxy) return true;
95       return false;
96    }
97
98    public void testSimpleTxWithRollback2() throws Exception JavaDoc
99    {
100       log_.info("testSimpleTxWithRollback1() ....");
101       Person test = new Person();
102       test.setName("Ben");
103       test.setAge(10);
104       ArrayList JavaDoc list = new ArrayList JavaDoc();
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 JavaDoc
119    {
120       log_.info("testSimpleTxWithRollback1() ....");
121       Person test = new Person();
122       test.setName("Ben");
123       test.setAge(10);
124       ArrayList JavaDoc list = new ArrayList JavaDoc();
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 JavaDoc
136    {
137       return new TestSuite(ListTxUndoTest.class);
138    }
139
140
141    public static void main(String JavaDoc[] args) throws Exception JavaDoc
142    {
143       junit.textui.TestRunner.run(ListTxUndoTest.suite());
144    }
145
146 }
147
Popular Tags