KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jboss.cache;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6
7 /**
8  * Tests restart (stop-destroy-create-start) of CacheImpl
9  *
10  * @author Bela Ban
11  * @version $Id: TreeNodeTest.java,v 1.5 2006/12/30 19:48:46 msurtani Exp $
12  */

13 public class TreeNodeTest extends TestCase
14 {
15    CacheImpl cache;
16
17    protected void setUp() throws Exception JavaDoc
18    {
19       super.setUp();
20       cache = new CacheImpl();
21       startCache(cache);
22    }
23
24    protected void tearDown() throws Exception JavaDoc
25    {
26       super.tearDown();
27       stopCache(cache);
28    }
29
30    public void testChildExist() throws Exception JavaDoc
31    {
32       Object JavaDoc key = 1;
33       cache.put("/a/b/c", key, "test");
34       Node node;
35       node = cache.get("/a/b");
36       assertFalse(node.getChildren().isEmpty());
37       assertTrue(node.getChild(new Fqn("c")) != null);
38
39       Fqn fqn = Fqn.fromString("/e/f");
40       cache.put(fqn, "1", "1");
41       node = cache.get("/e");
42       assertFalse(node.getChildren().isEmpty());
43       assertTrue(node.getChild(new Fqn("f")) != null);
44
45    }
46
47    /**
48     * public void testRelocate() throws Exception
49     * {
50     * Object key = new Integer(1);
51     * cache.put("/a/b/c", key, "test");
52     * cache.put("/a/b/c/d", key, "test1");
53     * cache.put("/relocate", "1", "1");
54     * <p/>
55     * DataNode node = cache.get("/a/b/c");
56     * DataNode newParentNode = cache.get("/relocate");
57     * assertFalse(newParentNode.hasChildren());
58     * <p/>
59     * Fqn newFqn = Fqn.fromString("/relocate/c");
60     * <p/>
61     * cache.put("/relocate/c", "1", "1");
62     * <p/>
63     * node.relocate(newParentNode, newFqn);
64     * assertNotNull("/relocat/c should not be null", cache.get(newFqn));
65     * <p/>
66     * node = cache.get("/a/b");
67     * assertTrue(!node.hasChildren());
68     * assertTrue(!node.childExists("c"));
69     * <p/>
70     * node = cache.get("/relocate");
71     * assertTrue(node.hasChildren());
72     * assertTrue(node.childExists(newFqn.get(1)));
73     * <p/>
74     * node = cache.get(newFqn);
75     * assertEquals(newFqn, node.getFqn());
76     * assertTrue(node.hasChildren());
77     * assertTrue(node.childExists("d"));
78     * <p/>
79     * node = cache.get("/relocate/c/d");
80     * assertNotNull(node);
81     * assertEquals("test1", cache.get("/relocate/c/d", key));
82     * <p/>
83     * assertNull(cache.get("/relocate/c/","1"));
84     * }
85     */

86
87    void startCache(CacheImpl c) throws Exception JavaDoc
88    {
89       c.create();
90       c.start();
91    }
92
93    void stopCache(CacheImpl c)
94    {
95       c.stop();
96       c.destroy();
97    }
98
99    public static Test suite()
100    {
101       return new TestSuite(TreeNodeTest.class);
102    }
103
104    public static void main(String JavaDoc[] args)
105    {
106       junit.textui.TestRunner.run(suite());
107    }
108
109 }
110
Popular Tags