1 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 ; 16 import java.io.ObjectOutputStream ; 17 import java.util.Set ; 18 19 20 24 public class GetKeysTest extends TestCase { 25 TreeCache cache; 26 27 public GetKeysTest(String s) { 28 super(s); 29 } 30 31 public void setUp() throws Exception { 32 super.setUp(); 33 } 34 35 public void tearDown() throws Exception { 36 super.tearDown(); 37 } 38 39 public void testGetKeys() throws Exception { 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 (40)); 45 cache.put("/a/b/c", "city", "Kreuzlingen"); 46 47 Set keys=cache.getKeys("/a/b/c"); 48 log("keys are " + keys); 49 assertNotNull(keys); 50 assertEquals(3, keys.size()); 51 52 ByteArrayOutputStream outstream=new ByteArrayOutputStream (20); 53 ObjectOutputStream out=new ObjectOutputStream (outstream); 54 out.writeObject(keys); } 56 57 public void testGetChildren() throws Exception { 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 children=cache.getChildrenNames("/a/b/c"); 67 log("children are " + children); 68 assertNotNull(children); 69 assertEquals(3, children.size()); 70 71 ByteArrayOutputStream outstream=new ByteArrayOutputStream (20); 72 ObjectOutputStream out=new ObjectOutputStream (outstream); 73 out.writeObject(children); } 75 76 77 void log(String 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 [] args) { 86 junit.textui.TestRunner.run(suite()); 87 } 88 89 } 90 | Popular Tags |