1 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 ; 19 import java.util.Properties ; 20 21 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 name) 34 { 35 super(name); 36 } 37 38 protected void setUp() throws Exception 39 { 40 super.setUp(); 41 Properties prop = new Properties (); 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 51 { 52 super.tearDown(); 53 cache_.stop(); 54 cache1_.stop(); 55 } 56 57 public void testSeriazableSubObject() throws Exception 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 83 public void XtestSeriazableSubObjectRelation() throws Exception 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 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 111 { 112 log_.info("testPlainSerializable() ...."); 113 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 123 { 124 return new TestSuite(ReplicatedSerializableTest.class); 125 } 126 127 128 public static void main(String [] args) throws Exception 129 { 130 junit.textui.TestRunner.run(ReplicatedSerializableTest.suite()); 131 } 132 133 } 134 | Popular Tags |