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