1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.jboss.cache.pojo.annotation; |
9 |
| |
10 |
| import junit.framework.Test; |
11 |
| import junit.framework.TestCase; |
12 |
| import junit.framework.TestSuite; |
13 |
| import org.apache.commons.logging.Log; |
14 |
| import org.apache.commons.logging.LogFactory; |
15 |
| import org.jboss.cache.config.Configuration.CacheMode; |
16 |
| import org.jboss.cache.factories.UnitTestCacheFactory; |
17 |
| import org.jboss.cache.pojo.PojoCache; |
18 |
| import org.jboss.cache.pojo.PojoCacheFactory; |
19 |
| import org.jboss.cache.pojo.test.Gadget; |
20 |
| import org.jboss.cache.pojo.test.Resource; |
21 |
| import org.jboss.cache.pojo.test.SpecialAddress; |
22 |
| |
23 |
| import javax.naming.Context; |
24 |
| import java.util.ArrayList; |
25 |
| import java.util.List; |
26 |
| import java.util.Properties; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class ReplicatedAnnotationTest extends TestCase |
34 |
| { |
35 |
| Log log_ = LogFactory.getLog(ReplicatedAnnotationTest.class); |
36 |
| PojoCache cache_; |
37 |
| PojoCache cache1_; |
38 |
| |
39 |
6
| public ReplicatedAnnotationTest(String name)
|
40 |
| { |
41 |
6
| super(name);
|
42 |
| } |
43 |
| |
44 |
6
| protected void setUp() throws Exception
|
45 |
| { |
46 |
6
| super.setUp();
|
47 |
6
| Properties prop = new Properties();
|
48 |
6
| prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
|
49 |
6
| boolean toStart = false;
|
50 |
6
| cache_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
|
51 |
| |
52 |
6
| cache1_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
|
53 |
6
| cache_.start();
|
54 |
6
| cache1_.start();
|
55 |
| } |
56 |
| |
57 |
6
| protected void tearDown() throws Exception
|
58 |
| { |
59 |
6
| super.tearDown();
|
60 |
6
| cache_.stop();
|
61 |
6
| cache1_.stop();
|
62 |
| } |
63 |
| |
64 |
2
| public void testTransientAnnotation() throws Exception
|
65 |
| { |
66 |
2
| log_.info("testTransientAnnotation() ....");
|
67 |
2
| Gadget ga = new Gadget();
|
68 |
2
| ga.setName("Printer");
|
69 |
2
| Resource res = new Resource();
|
70 |
2
| res.setName("Inet");
|
71 |
2
| res.setConnection("Eth0");
|
72 |
2
| ga.setResource(res);
|
73 |
| |
74 |
2
| cache_.attach("/gadget", ga);
|
75 |
2
| Object obj = cache_.find("/gadget");
|
76 |
2
| assertEquals(ga, obj);
|
77 |
| |
78 |
2
| Gadget ga1 = (Gadget) cache1_.find("/gadget");
|
79 |
2
| assertEquals("Name is ", ga.getName(), ga1.getName());
|
80 |
| |
81 |
2
| assertNotNull("Resource should not be null on cache1 ", ga.getResource());
|
82 |
2
| assertNull("Resource should be null", ga1.getResource());
|
83 |
| } |
84 |
| |
85 |
2
| public void testSeriazableAnnotation() throws Exception
|
86 |
| { |
87 |
2
| log_.info("testSerializableAnnotation() ....");
|
88 |
2
| Gadget ga = new Gadget();
|
89 |
2
| ga.setName("Printer");
|
90 |
2
| SpecialAddress addr = new SpecialAddress();
|
91 |
2
| addr.setAddr("10.1.2.2");
|
92 |
2
| ga.setAddr(addr);
|
93 |
| |
94 |
2
| cache_.attach("/gadget", ga);
|
95 |
2
| Object obj = cache_.find("/gadget");
|
96 |
2
| assertEquals(ga, obj);
|
97 |
| |
98 |
2
| Gadget ga1 = (Gadget) cache1_.find("/gadget");
|
99 |
2
| assertEquals("Name is ", ga.getName(), ga1.getName());
|
100 |
| |
101 |
2
| SpecialAddress addr1 = (SpecialAddress) ga1.getAddr();
|
102 |
2
| addr1.setAddr("5152967326");
|
103 |
| |
104 |
2
| assertNotSame("Special address should not be updated: ", addr1.getAddr(), addr.getAddr());
|
105 |
| |
106 |
2
| ga1.setAddr(addr1);
|
107 |
2
| assertEquals("Special address should be the same", ga.getAddr().getAddr(), ga1.getAddr().getAddr());
|
108 |
| |
109 |
| } |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
0
| public void XtestSeriazableAnnotationWithRelationship() throws Exception
|
117 |
| { |
118 |
0
| log_.info("testSerializableAnnotationWithRelationship() ....");
|
119 |
0
| Gadget ga = new Gadget();
|
120 |
0
| ga.setName("Printer");
|
121 |
0
| SpecialAddress addr = new SpecialAddress();
|
122 |
0
| addr.setAddr("10.1.2.2");
|
123 |
0
| ga.setAddr(addr);
|
124 |
| |
125 |
0
| cache_.attach("/gadget1", ga);
|
126 |
0
| Object obj = cache_.find("/gadget1");
|
127 |
0
| assertEquals(ga, obj);
|
128 |
| |
129 |
0
| Gadget ga2 = new Gadget();
|
130 |
0
| ga2.setName("Fax");
|
131 |
0
| ga2.setAddr(addr);
|
132 |
0
| cache_.attach("/gadget2", ga2);
|
133 |
| |
134 |
0
| ga = (Gadget) cache1_.find("/gadget1");
|
135 |
0
| ga2 = (Gadget) cache1_.find("/gadget2");
|
136 |
0
| assertTrue("Sepecial address should be the same ", ga.getAddr() == ga2.getAddr());
|
137 |
| } |
138 |
| |
139 |
| |
140 |
| |
141 |
| |
142 |
| |
143 |
| |
144 |
2
| public void testCollectionWithGenerics() throws Exception
|
145 |
| { |
146 |
2
| log_.info("testCollectionWithGenerics() ....");
|
147 |
2
| List<String> list = new ArrayList<String>();
|
148 |
2
| list.add("1");
|
149 |
2
| list.add("2");
|
150 |
| |
151 |
2
| cache_.attach("/test", list);
|
152 |
| |
153 |
2
| List<String> list1 = (List<String>) cache_.find("/test");
|
154 |
2
| list1.add("3");
|
155 |
2
| String l3 = list1.get(2);
|
156 |
2
| assertEquals("String ", "3", l3);
|
157 |
| |
158 |
2
| list1 = (List<String>) cache1_.find("/test");
|
159 |
2
| l3 = list1.get(2);
|
160 |
2
| assertEquals("String ", "3", l3);
|
161 |
| } |
162 |
| |
163 |
2
| public static Test suite() throws Exception
|
164 |
| { |
165 |
2
| return new TestSuite(ReplicatedAnnotationTest.class);
|
166 |
| } |
167 |
| |
168 |
| |
169 |
0
| public static void main(String[] args) throws Exception
|
170 |
| { |
171 |
0
| junit.textui.TestRunner.run(ReplicatedAnnotationTest.suite());
|
172 |
| } |
173 |
| |
174 |
| } |