KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cache > test > local > NoTxUnitTestCase


1 /*
2  *
3  * JBoss, the OpenSource J2EE webOS
4  *
5  * Distributable under LGPL license.
6  * See terms of license at gnu.org.
7  */

8 package org.jboss.test.cache.test.local;
9
10 import junit.framework.Test;
11 import junit.framework.TestCase;
12 import junit.framework.TestSuite;
13 import org.jboss.cache.TreeCache;
14 import org.jboss.cache.lock.IsolationLevel;
15
16 /**
17  * Unit test for local TreeCache with no tx.
18  *
19  * @version $Revision: 1.6 $
20  */

21 public class NoTxUnitTestCase extends TestCase
22 {
23    TreeCache cache;
24
25    public NoTxUnitTestCase(String JavaDoc name)
26    {
27       super(name);
28    }
29
30    public void setUp() throws Exception JavaDoc
31    {
32       super.setUp();
33       cache = new TreeCache();
34       cache.setCacheMode(TreeCache.LOCAL);
35       cache.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
36       cache.createService();
37       cache.startService();
38    }
39
40    public void tearDown() throws Exception JavaDoc
41    {
42       super.tearDown();
43       cache.stopService();
44    }
45
46
47    public void testPut()
48    {
49       try {
50          cache.put("/a/b/c", "age", new Integer JavaDoc(38));
51          assertEquals(cache.get("/a/b/c", "age"), new Integer JavaDoc(38));
52          assertNotNull(cache.get("/a/b/c"));
53       } catch (Exception JavaDoc e) {
54          e.printStackTrace();
55          fail(e.toString());
56       }
57    }
58
59    public void testPutKeys()
60    {
61       try {
62          cache.put("/a/b/c", "age", new Integer JavaDoc(38));
63          cache.put("/a/b/c", "name", "Bela");
64          assertEquals(cache.get("/a/b/c", "age"), new Integer JavaDoc(38));
65          assertNotNull(cache.get("/a/b/c"));
66          assertEquals(cache.getKeys("/a/b/c").size(), 2);
67          assertEquals(cache.exists("/a/b/c"), true);
68       } catch (Exception JavaDoc e) {
69          e.printStackTrace();
70          fail(e.toString());
71       }
72    }
73
74
75    public static Test suite()
76    {
77       return new TestSuite(NoTxUnitTestCase.class);
78    }
79
80    public static void main(String JavaDoc[] args)
81    {
82       junit.textui.TestRunner.run(suite());
83    }
84
85
86 }
87
Popular Tags