1 package org.jboss.cache.tests.aop; 2 3 import junit.framework.Test; 4 import junit.framework.TestCase; 5 import junit.framework.TestSuite; 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 import java.util.List ; 10 11 13 14 20 21 public class ReplicatedAopTest extends TestCase 22 { 23 Log log=LogFactory.getLog(ReplicatedAopTest.class); 25 TreeCacheAopTester tester, tester1; 26 27 28 public ReplicatedAopTest(String name) 29 { 30 super(name); 31 } 32 33 protected void setUp() throws Exception 34 { 35 super.setUp(); 36 log.info("setUp() ...."); 37 String configFile = "META-INF/replSync-service.xml"; 38 tester = new TreeCacheAopTester(configFile); 39 tester1 = new TreeCacheAopTester(configFile); 40 } 41 42 protected void tearDown() throws Exception 43 { 44 super.tearDown(); 45 tester.stop(); 46 tester1.stop(); 47 tester = null; 48 tester1 = null; 49 } 50 51 53 public void testSetup() 54 { 55 log.info("testSetup() ...."); 56 try { 57 tester.testSetup(); 58 tester1.testSetup(); 59 } catch (Exception ex) { 60 ex.printStackTrace(); 61 fail("testSetup(): fails. " + ex.toString()); 62 } 63 } 64 65 public void testSimple() throws Exception 66 { 67 log.info("testSimple() ...."); 68 tester.createPerson("/person/test1", "Ben Wang", 40); 69 assertEquals((Object ) "Ben Wang", (Object ) tester.getName("/person/test1")); 70 assertEquals((Object ) "Ben Wang", (Object ) tester1.getName("/person/test1")); 71 } 72 73 74 public void testDynamicRefSwapping() throws Exception 75 { 76 tester.createPerson("/person/test3", "Joe", 32); 77 Person person = (Person)tester.getPerson("/person/test3"); 78 try { 79 person.setAge(30); 80 List med = person.getMedication(); 81 assertNull("Medication should be null ", med); 82 person.setAge(61); 83 med = person.getMedication(); 84 assertEquals("Medication ", (Object )"Lipitor", (Object )med.get(0)); 85 assertEquals("Medication on cache1 ", (Object )"Lipitor", 86 (Object )((Person)tester1.getPerson("/person/test3")).getMedication().get(0)); 87 88 person.setAge(71); 89 assertEquals("Medication ", (Object )"Vioxx", (Object )med.get(1)); 90 assertEquals("Medication on cache1 ", (Object )"Vioxx", 91 (Object )((Person)tester1.getPerson("/person/test3")).getMedication().get(1)); 92 93 } catch (Exception e) { 94 } 96 } 97 98 public void testTransient() throws Exception 99 { 100 log.info("testTransient() ...."); 101 tester.createPerson("/person/test1", "Ben Wang", 40); 102 tester.setCurrentStatus("/person/test1", "Idle"); 103 assertEquals("Cache 1 ", (Object ) "Idle", (Object ) tester.getCurrentStatus("/person/test1")); 104 assertEquals("Cache 2 ", (Object ) "Active", (Object ) tester1.getCurrentStatus("/person/test1")); 105 } 106 107 public void testModification() throws Exception 108 { 109 tester.createPerson("/person/test2", "Ben Wang", 40); 110 tester.setName("/person/test2", "Harald Gliebe"); 111 assertEquals((Object ) tester.getName("/person/test2"), (Object ) "Harald Gliebe"); 112 assertEquals((Object ) tester1.getName("/person/test2"), (Object ) "Harald Gliebe"); 113 tester.removePerson("/person/test2"); 114 } 115 116 public void testInheritance() throws Exception 117 { 118 tester.createStudent("/person/joe", "Joe", 32, "Senior"); 119 tester.setName("/person/joe", "Joe Black"); 120 assertEquals((Object ) tester.getName("/person/joe"), (Object ) "Joe Black"); 121 assertEquals((Object ) tester1.getName("/person/joe"), (Object ) "Joe Black"); 122 tester1.setYear("/person/joe", "Junior"); 123 assertEquals((Object ) tester.getYear("/person/joe"), (Object ) "Junior"); 124 assertEquals((Object ) tester1.getYear("/person/joe"), (Object ) "Junior"); 125 tester.removePerson("/person/joe"); 126 } 127 128 129 public static Test suite() throws Exception 130 { 131 return new TestSuite(ReplicatedAopTest.class); 132 } 133 134 135 public static void main(String [] args) throws Exception 136 { 137 junit.textui.TestRunner.run(suite()); 138 } 139 140 } 141 142 | Popular Tags |