1 package org.jboss.cache.pojo.util; 2 3 import junit.framework.Test; 4 import junit.framework.TestCase; 5 import junit.framework.TestSuite; 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.jboss.cache.pojo.PojoCache; 9 import org.jboss.cache.pojo.PojoCacheFactory; 10 import org.jboss.cache.pojo.impl.PojoCacheImpl; 11 import org.jboss.cache.pojo.test.NodeManager; 12 import org.jboss.cache.pojo.test.TestNode; 13 14 15 20 21 public class ObjectUtilTest extends TestCase 22 { 23 Log log_ = LogFactory.getLog(ObjectUtilTest.class); 24 PojoCache cache_; 25 26 public ObjectUtilTest(String name) 27 { 28 super(name); 29 } 30 31 protected void setUp() throws Exception 32 { 33 super.setUp(); 34 log_.info("setUp() ...."); 35 String configFile = "META-INF/local-service.xml"; 36 boolean toStart = false; 37 cache_ = PojoCacheFactory.createCache(configFile, toStart); 38 cache_.start(); 39 } 40 41 protected void tearDown() throws Exception 42 { 43 super.tearDown(); 44 cache_.stop(); 45 } 46 47 49 public void testIsReachable() throws Exception 50 { 51 log_.info("testIsReachable() ...."); 52 NodeManager pm_ = new NodeManager(); 53 54 pm_.setRootNode("root"); 55 pm_.addNode("root", "kanto"); 56 pm_.addNode("root.kanto", "tokyo"); 57 pm_.addNode("root.kanto", "yakahoma"); 58 pm_.addNode("root.kanto.tokyo", "handanshita"); 59 60 TestNode kanto = pm_.findNode("root.kanto"); 61 TestNode yakahoma = pm_.findNode("root.kanto.yakahoma"); 62 TestNode hadanshita = pm_.findNode("root.kanto.tokyo.handanshita"); 63 64 pm_ = new NodeManager(); 65 pm_.setRootNode("rt"); 66 pm_.addNode("rt", "test"); 67 TestNode test = pm_.findNode("rt.test"); 68 69 71 assertTrue("Hadanshita should be reachable from Kanto ", 72 ObjectUtil.isReachable((PojoCacheImpl)cache_, kanto, hadanshita)); 73 assertTrue("Hadanshita should also be reachable from Yakahoma! ", 74 ObjectUtil.isReachable((PojoCacheImpl) cache_, yakahoma, hadanshita)); 75 assertFalse("Kanto should not be reachable from test! ", 76 ObjectUtil.isReachable((PojoCacheImpl) cache_, kanto, test)); 77 } 78 79 public static Test suite() throws Exception 80 { 81 return new TestSuite(ObjectUtilTest.class); 82 } 83 84 85 public static void main(String [] args) throws Exception 86 { 87 junit.textui.TestRunner.run(suite()); 88 } 89 90 } 91 92 | Popular Tags |