KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > basic > 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.tests.basic;
8
9
10 import junit.framework.Test;
11 import junit.framework.TestCase;
12 import junit.framework.TestSuite;
13 import org.jboss.cache.TreeCache;
14
15 import java.io.ByteArrayOutputStream JavaDoc;
16 import java.io.ObjectOutputStream JavaDoc;
17 import java.util.Set JavaDoc;
18
19
20 /**
21  * @author <a HREF="mailto:bela@jboss.org">Bela Ban</a>
22  * @version $Id: GetKeysTest.java,v 1.1.1.1 2005/03/31 10:15:08 belaban Exp $
23  */

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