1 |
| package org.jboss.cache.pojo; |
2 |
| |
3 |
| import junit.framework.TestCase; |
4 |
| import org.apache.commons.logging.Log; |
5 |
| import org.apache.commons.logging.LogFactory; |
6 |
| import org.jboss.cache.pojo.test.IdObject; |
7 |
| import org.jboss.cache.pojo.test.ValueObject; |
8 |
| |
9 |
| import java.util.HashMap; |
10 |
| import java.util.Map; |
11 |
| import java.util.ArrayList; |
12 |
| import java.util.HashSet; |
13 |
| |
14 |
| public class RecursiveRefTest extends TestCase |
15 |
| { |
16 |
| private static final String CONFIG_FILENAME = "META-INF/local-service.xml"; |
17 |
| private PojoCache cache; |
18 |
| Log log = LogFactory.getLog(RecursiveRefTest.class); |
19 |
| |
20 |
| private Map cachedMap; |
21 |
| |
22 |
8
| public RecursiveRefTest(String name)
|
23 |
| { |
24 |
8
| super(name);
|
25 |
| } |
26 |
| |
27 |
8
| protected void setUp() throws Exception
|
28 |
| { |
29 |
8
| super.setUp();
|
30 |
8
| log.info("setUp() ....");
|
31 |
8
| boolean toStart = false;
|
32 |
8
| cache = PojoCacheFactory.createCache(CONFIG_FILENAME, toStart);
|
33 |
8
| cache.start();
|
34 |
8
| cache.attach("/aop/test", new HashMap());
|
35 |
8
| cachedMap = (Map) cache.find("/aop/test");
|
36 |
| } |
37 |
| |
38 |
8
| protected void tearDown() throws Exception
|
39 |
| { |
40 |
8
| super.tearDown();
|
41 |
| } |
42 |
| |
43 |
0
| public void XtestDummy()
|
44 |
| { |
45 |
| |
46 |
| } |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
2
| public void testRecuriveMapKey()
|
53 |
| { |
54 |
2
| try
|
55 |
| { |
56 |
2
| IdObject id = new IdObject("1");
|
57 |
2
| ValueObject value = new ValueObject(id, 3.0f);
|
58 |
2
| cachedMap.put(id, value);
|
59 |
| } |
60 |
| catch (Exception x) |
61 |
| { |
62 |
0
| x.printStackTrace();
|
63 |
0
| fail("testFailed");
|
64 |
| } |
65 |
| } |
66 |
| |
67 |
2
| public void testRecursiveList() throws Exception
|
68 |
| { |
69 |
2
| ArrayList list = new ArrayList();
|
70 |
2
| list.add("1");
|
71 |
2
| cache.attach("list", list);
|
72 |
2
| list = (ArrayList)cache.find("list");
|
73 |
2
| list.add(list);
|
74 |
2
| System.out.println(list.toString());
|
75 |
| } |
76 |
| |
77 |
2
| public void testRecursiveSet() throws Exception
|
78 |
| { |
79 |
2
| HashSet set = new HashSet();
|
80 |
2
| set.add("1");
|
81 |
2
| cache.attach("set", set);
|
82 |
2
| set = (HashSet)cache.find("set");
|
83 |
2
| set.add(set);
|
84 |
2
| System.out.println(set.toString());
|
85 |
| } |
86 |
| |
87 |
2
| public void testRecursiveMap() throws Exception
|
88 |
| { |
89 |
2
| HashMap map = new HashMap();
|
90 |
2
| map.put("1", "1");
|
91 |
2
| cache.attach("map", map);
|
92 |
2
| map = (HashMap)cache.find("map");
|
93 |
2
| map.put("2", map);
|
94 |
2
| System.out.println(map.toString());
|
95 |
| } |
96 |
| |
97 |
| } |
98 |
| |
99 |
| |