1 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 ; 15 import java.io.ObjectOutputStream ; 16 import java.util.Set ; 17 18 19 23 public class GetKeysTest extends TestCase 24 { 25 CacheImpl cache; 26 27 public GetKeysTest(String s) 28 { 29 super(s); 30 } 31 32 public void setUp() throws Exception 33 { 34 super.setUp(); 35 } 36 37 public void tearDown() throws Exception 38 { 39 super.tearDown(); 40 } 41 42 public void testGetKeys() throws Exception 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 keys = cache.getKeys("/a/b/c"); 52 log("keys are " + keys); 53 assertNotNull(keys); 54 assertEquals(3, keys.size()); 55 56 ByteArrayOutputStream outstream = new ByteArrayOutputStream (20); 57 ObjectOutputStream out = new ObjectOutputStream (outstream); 58 out.writeObject(keys); } 60 61 public void testGetChildren() throws Exception 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 children = cache.getChildrenNames("/a/b/c"); 72 log("children are " + children); 73 assertNotNull(children); 74 assertEquals(3, children.size()); 75 76 ByteArrayOutputStream outstream = new ByteArrayOutputStream (20); 77 ObjectOutputStream out = new ObjectOutputStream (outstream); 78 out.writeObject(children); } 80 81 82 void log(String 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 [] args) 93 { 94 junit.textui.TestRunner.run(suite()); 95 } 96 97 } 98 | Popular Tags |