KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > pojo > ReplicatedSerializableTest


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;
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.test.CacheObject;
16 import org.jboss.cache.pojo.test.Student;
17
18 import javax.naming.Context JavaDoc;
19 import java.util.Properties JavaDoc;
20
21 /**
22  * New NewReplicatedAopTest that doesn't use TreeCacheAopTester.
23  *
24  * @author Ben Wang
25  */

26
27 public class ReplicatedSerializableTest extends TestCase
28 {
29    Log log_ = LogFactory.getLog(ReplicatedSerializableTest.class);
30    PojoCache cache_;
31    PojoCache cache1_;
32
33    public ReplicatedSerializableTest(String JavaDoc name)
34    {
35       super(name);
36    }
37
38    protected void setUp() throws Exception JavaDoc
39    {
40       super.setUp();
41       Properties JavaDoc prop = new Properties JavaDoc();
42       prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
43       boolean toStart = false;
44       cache_ = PojoCacheFactory.createCache("META-INF/replSync-service.xml", toStart);
45       cache1_ = PojoCacheFactory.createCache("META-INF/replSync-service.xml", toStart);
46       cache_.start();
47       cache1_.start();
48    }
49
50    protected void tearDown() throws Exception JavaDoc
51    {
52       super.tearDown();
53       cache_.stop();
54       cache1_.stop();
55    }
56
57    public void testSeriazableSubObject() throws Exception JavaDoc
58    {
59       log_.info("testSerializableSubObject() ....");
60
61       Student ben = new Student();
62       ben.setName("Ben");
63       ben.setYear("9th grade");
64       CacheObject co1 = new CacheObject("1");
65       ben.setCO1(co1);
66       CacheObject co2 = new CacheObject("2");
67       ben.setCO2(co2);
68
69       cache_.attach("/test", ben);
70
71       Student be = (Student) cache1_.find("/test");
72       assertNotNull("CacheObject should not be null", be.getCO1());
73       assertNotNull("CacheObject should not be null", be.getCO2());
74       assertEquals("1", be.getCO1().getId());
75       assertEquals("2", be.getCO2().getId());
76    }
77
78    /**
79     * We don;t currently support Serializable with relationship now.
80     *
81     * @throws Exception
82     */

83    public void XtestSeriazableSubObjectRelation() throws Exception JavaDoc
84    {
85       log_.info("testSerializableSubObjectRelation() ....");
86
87       Student ben = new Student();
88       ben.setName("Ben");
89       ben.setYear("9th grade");
90       CacheObject co1 = new CacheObject("1");
91       ben.setCO1(co1);
92
93       Student elynne = new Student();
94       elynne.setName("Elynne");
95       elynne.setYear("9th grade");
96       // Same co object
97
elynne.setCO1(co1);
98
99       cache_.attach("/ben", ben);
100       cache_.attach("/elynne", elynne);
101
102       Student be = (Student) cache1_.find("/ben");
103       Student el = (Student) cache1_.find("/elynne");
104       assertNotNull("CacheObject should not be null", be.getCO1());
105       assertNotNull("CacheObject should not be null", el.getCO1());
106       assertEquals("Both co object should be the same", be.getCO1().getId(), el.getCO1().getId());
107       assertTrue("Both co should be the same reference", be.getCO1() == el.getCO1());
108    }
109
110    public void testPlainSeriazable() throws Exception JavaDoc
111    {
112       log_.info("testPlainSerializable() ....");
113       // First the flag is set to false
114
CacheObject co = new CacheObject("1");
115       cache_.attach("/test", co);
116       CacheObject co1 = (CacheObject) cache1_.find("/test");
117       assertNotNull("co on remote cache should not be null", co1);
118       assertEquals("co should be the same", co.getId(), co1.getId());
119
120    }
121
122    public static Test suite() throws Exception JavaDoc
123    {
124       return new TestSuite(ReplicatedSerializableTest.class);
125    }
126
127
128    public static void main(String JavaDoc[] args) throws Exception JavaDoc
129    {
130       junit.textui.TestRunner.run(ReplicatedSerializableTest.suite());
131    }
132
133 }
134
Popular Tags