KickJava   Java API By Example, From Geeks To Geeks.

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


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

7 package org.jboss.cache;
8
9
10 import junit.framework.Test;
11 import junit.framework.TestCase;
12 import junit.framework.TestSuite;
13
14 import java.io.ByteArrayOutputStream JavaDoc;
15 import java.io.ObjectOutputStream JavaDoc;
16 import java.util.Set JavaDoc;
17
18
19 /**
20  * @author <a HREF="mailto:bela@jboss.org">Bela Ban</a>
21  * @version $Id: GetKeysTest.java,v 1.4 2006/12/30 19:48:46 msurtani Exp $
22  */

23 public class GetKeysTest extends TestCase
24 {
25    CacheImpl cache;
26
27    public GetKeysTest(String JavaDoc s)
28    {
29       super(s);
30    }
31
32    public void setUp() throws Exception JavaDoc
33    {
34       super.setUp();
35    }
36
37    public void tearDown() throws Exception JavaDoc
38    {
39       super.tearDown();
40    }
41
42    public void testGetKeys() throws Exception JavaDoc
43    {
44       cache = new CacheImpl();
45       cache.create();
46       cache.start();
47       cache.put("/a/b/c", "name", "Bela Ban");
48       cache.put("/a/b/c", "age", 40);
49       cache.put("/a/b/c", "city", "Kreuzlingen");
50
51       Set JavaDoc keys = cache.getKeys("/a/b/c");
52       log("keys are " + keys);
53       assertNotNull(keys);
54       assertEquals(3, keys.size());
55
56       ByteArrayOutputStream JavaDoc outstream = new ByteArrayOutputStream JavaDoc(20);
57       ObjectOutputStream JavaDoc out = new ObjectOutputStream JavaDoc(outstream);
58       out.writeObject(keys); // must be serializable
59
}
60
61    public void testGetChildren() throws Exception JavaDoc
62    {
63       cache = new CacheImpl();
64       cache.create();
65       cache.start();
66       cache.put("/a/b/c", null);
67       cache.put("/a/b/c/1", null);
68       cache.put("/a/b/c/2", null);
69       cache.put("/a/b/c/3", null);
70
71       Set JavaDoc children = cache.getChildrenNames("/a/b/c");
72       log("children are " + children);
73       assertNotNull(children);
74       assertEquals(3, children.size());
75
76       ByteArrayOutputStream JavaDoc outstream = new ByteArrayOutputStream JavaDoc(20);
77       ObjectOutputStream JavaDoc out = new ObjectOutputStream JavaDoc(outstream);
78       out.writeObject(children); // must be serializable
79
}
80
81
82    void log(String JavaDoc msg)
83    {
84       System.out.println("-- " + msg);
85    }
86
87    public static Test suite()
88    {
89       return new TestSuite(GetKeysTest.class);
90    }
91
92    public static void main(String JavaDoc[] args)
93    {
94       junit.textui.TestRunner.run(suite());
95    }
96
97 }
98
Popular Tags