KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > TreeCacheFunctionalTest


1 package org.jboss.cache;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import org.jboss.cache.config.Configuration;
7 import org.jboss.cache.lock.IsolationLevel;
8
9 import javax.transaction.Transaction JavaDoc;
10 import java.util.HashMap JavaDoc;
11
12 /**
13  * Simple functional tests for CacheImpl
14  *
15  * @author Bela Ban
16  * @version $Id: TreeCacheFunctionalTest.java,v 1.7 2006/12/30 19:48:46 msurtani Exp $
17  */

18 public class TreeCacheFunctionalTest extends TestCase
19 {
20    CacheImpl cache = null;
21    Transaction JavaDoc tx = null;
22    final Fqn FQN = Fqn.fromString("/myNode");
23    final String JavaDoc KEY = "key";
24    final String JavaDoc VALUE = "value";
25    Exception JavaDoc ex;
26
27
28    protected void setUp() throws Exception JavaDoc
29    {
30       super.setUp();
31       cache = new CacheImpl();
32       cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
33       cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
34       cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
35       cache.create();
36       cache.start();
37       ex = null;
38    }
39
40    protected void tearDown() throws Exception JavaDoc
41    {
42       super.tearDown();
43       if (cache != null)
44       {
45          cache.stop();
46          cache.destroy();
47          cache = null;
48       }
49       if (ex != null)
50          throw ex;
51    }
52
53
54    public void testPut() throws CacheException
55    {
56       cache.put("/a/b/c", "age", 38);
57       assertEquals(cache.get("/a/b/c", "age"), 38);
58       assertNotNull(cache.get("/a/b/c"));
59       assertEquals(0, cache.getNumberOfLocksHeld());
60       assertEquals(0, cache.getLockTable().size());
61    }
62
63
64    public void testPutNullKey() throws CacheException
65    {
66       Object JavaDoc key = null;
67       cache.put("/a/b/c", key, "val");
68       System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
69    }
70
71    public void testPutNullValue() throws CacheException
72    {
73       Object JavaDoc val = null;
74       cache.put("/a/b/c", "key", val);
75       System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
76    }
77
78    public void testPutNullKeyAndValues() throws CacheException
79    {
80       Object JavaDoc key = null, val = null;
81       cache.put("/a/b/c", key, val);
82       System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
83    }
84
85    public void testPutMapsWithNullValues() throws CacheException
86    {
87       HashMap JavaDoc map = new HashMap JavaDoc();
88       map.put("key", null);
89       map.put(null, "val");
90       map.put("a", "b");
91       map.put(null, null);
92       cache.put("/a/b/c", map);
93       System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
94    }
95
96    public void testPutKeys() throws CacheException
97    {
98       cache.put("/a/b/c", "age", 38);
99       cache.put("/a/b/c", "name", "Bela");
100       assertEquals(cache.get("/a/b/c", "age"), 38);
101       assertNotNull(cache.get("/a/b/c"));
102       assertEquals(cache.getKeys("/a/b/c").size(), 2);
103       assertEquals(cache.exists("/a/b/c"), true);
104       assertEquals(0, cache.getNumberOfLocksHeld());
105       assertEquals(0, cache.getLockTable().size());
106    }
107
108    public void testRemove() throws CacheException
109    {
110       cache.put("/a/b/c", null);
111       cache.put("/a/b/c/1", null);
112       cache.put("/a/b/c/2", null);
113       cache.put("/a/b/c/3", null);
114       cache.put("/a/b/c/3/a/b/c", null);
115
116       cache.remove("/a/b/c");
117       assertEquals(0, cache.getNumberOfLocksHeld());
118       assertEquals(0, cache.getLockTable().size());
119    }
120
121    public static Test suite()
122    {
123       return new TestSuite(TreeCacheFunctionalTest.class);
124    }
125
126 }
127
Popular Tags