KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > pojo > annotation > ReplicatedAnnotationTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
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.pojo.PojoCache;
16 import org.jboss.cache.pojo.PojoCacheFactory;
17 import org.jboss.cache.pojo.test.Gadget;
18 import org.jboss.cache.pojo.test.Resource;
19 import org.jboss.cache.pojo.test.SpecialAddress;
20
21 import javax.naming.Context JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 /**
27  * Test for JDK50 specific annotation.
28  *
29  * @author Ben Wang
30  */

31 public class ReplicatedAnnotationTest extends TestCase
32 {
33    Log log_ = LogFactory.getLog(ReplicatedAnnotationTest.class);
34    PojoCache cache_;
35    PojoCache cache1_;
36
37    public ReplicatedAnnotationTest(String JavaDoc name)
38    {
39       super(name);
40    }
41
42    protected void setUp() throws Exception JavaDoc
43    {
44       super.setUp();
45       Properties JavaDoc prop = new Properties JavaDoc();
46       prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
47       String JavaDoc configStr = "META-INF/replSync-service.xml";
48       boolean toStart = false;
49       cache_ = PojoCacheFactory.createCache(configStr, toStart);
50
51       cache1_ = PojoCacheFactory.createCache(configStr, toStart);
52       cache_.start();
53       cache1_.start();
54    }
55
56    protected void tearDown() throws Exception JavaDoc
57    {
58       super.tearDown();
59       cache_.stop();
60       cache1_.stop();
61    }
62
63    public void testTransientAnnotation() throws Exception JavaDoc
64    {
65       log_.info("testTransientAnnotation() ....");
66       Gadget ga = new Gadget();
67       ga.setName("Printer");
68       Resource res = new Resource();
69       res.setName("Inet");
70       res.setConnection("Eth0");
71       ga.setResource(res);
72
73       cache_.attach("/gadget", ga);
74       Object JavaDoc obj = cache_.find("/gadget");
75       assertEquals(ga, obj);
76
77       Gadget ga1 = (Gadget) cache1_.find("/gadget");
78       assertEquals("Name is ", ga.getName(), ga1.getName());
79
80       assertNotNull("Resource should not be null on cache1 ", ga.getResource());
81       assertNull("Resource should be null", ga1.getResource());
82    }
83
84    public void testSeriazableAnnotation() throws Exception JavaDoc
85    {
86       log_.info("testSerializableAnnotation() ....");
87       Gadget ga = new Gadget();
88       ga.setName("Printer");
89       SpecialAddress addr = new SpecialAddress();
90       addr.setAddr("10.1.2.2");
91       ga.setAddr(addr);
92
93       cache_.attach("/gadget", ga);
94       Object JavaDoc obj = cache_.find("/gadget");
95       assertEquals(ga, obj);
96
97       Gadget ga1 = (Gadget) cache1_.find("/gadget");
98       assertEquals("Name is ", ga.getName(), ga1.getName());
99
100       SpecialAddress addr1 = (SpecialAddress) ga1.getAddr();
101       addr1.setAddr("5152967326");
102
103       assertNotSame("Special address should not be updated: ", addr1.getAddr(), addr.getAddr());
104
105       ga1.setAddr(addr1);
106       assertEquals("Special address should be the same", ga.getAddr().getAddr(), ga1.getAddr().getAddr());
107
108    }
109
110    /**
111     * We haven't implemented this feature yet.
112     *
113     * @throws Exception
114     */

115    public void XtestSeriazableAnnotationWithRelationship() throws Exception JavaDoc
116    {
117       log_.info("testSerializableAnnotationWithRelationship() ....");
118       Gadget ga = new Gadget();
119       ga.setName("Printer");
120       SpecialAddress addr = new SpecialAddress();
121       addr.setAddr("10.1.2.2");
122       ga.setAddr(addr);
123
124       cache_.attach("/gadget1", ga);
125       Object JavaDoc obj = cache_.find("/gadget1");
126       assertEquals(ga, obj);
127
128       Gadget ga2 = new Gadget();
129       ga2.setName("Fax");
130       ga2.setAddr(addr);
131       cache_.attach("/gadget2", ga2);
132
133       ga = (Gadget) cache1_.find("/gadget1");
134       ga2 = (Gadget) cache1_.find("/gadget2");
135       assertTrue("Sepecial address should be the same ", ga.getAddr() == ga2.getAddr());
136    }
137
138    /**
139     * Test ClassProxy for generic List.
140     *
141     * @throws Exception
142     */

143    public void testCollectionWithGenerics() throws Exception JavaDoc
144    {
145       log_.info("testCollectionWithGenerics() ....");
146       List JavaDoc<String JavaDoc> list = new ArrayList JavaDoc<String JavaDoc>();
147       list.add("1");
148       list.add("2");
149
150       cache_.attach("/test", list);
151
152       List JavaDoc<String JavaDoc> list1 = (List JavaDoc<String JavaDoc>) cache_.find("/test");
153       list1.add("3");
154       String JavaDoc l3 = list1.get(2);
155       assertEquals("String ", "3", l3);
156
157       list1 = (List JavaDoc<String JavaDoc>) cache1_.find("/test");
158       l3 = list1.get(2);
159       assertEquals("String ", "3", l3);
160    }
161
162    public static Test suite() throws Exception JavaDoc
163    {
164       return new TestSuite(ReplicatedAnnotationTest.class);
165    }
166
167
168    public static void main(String JavaDoc[] args) throws Exception JavaDoc
169    {
170       junit.textui.TestRunner.run(ReplicatedAnnotationTest.suite());
171    }
172
173 }
174
Popular Tags