KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > aop > ReplicatedAopTest


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 JavaDoc;
10
11 //import org.jboss.test.JBossTestCase;
12

13
14 /**
15  * LocalTestCase.java that uses standalone aop package.
16  * <p/>
17  * <p/>
18  * Created: Mon May 05 17:30:11 2003
19  */

20
21 public class ReplicatedAopTest extends TestCase
22 {
23 // Category log = getLog();
24
Log log=LogFactory.getLog(ReplicatedAopTest.class);
25    TreeCacheAopTester tester, tester1;
26
27
28    public ReplicatedAopTest(String JavaDoc name)
29    {
30       super(name);
31    }
32
33    protected void setUp() throws Exception JavaDoc
34    {
35       super.setUp();
36       log.info("setUp() ....");
37       String JavaDoc configFile = "META-INF/replSync-service.xml";
38       tester = new TreeCacheAopTester(configFile);
39       tester1 = new TreeCacheAopTester(configFile);
40    }
41
42    protected void tearDown() throws Exception JavaDoc
43    {
44       super.tearDown();
45       tester.stop();
46       tester1.stop();
47       tester = null;
48       tester1 = null;
49    }
50
51 // public void testDummy() {}
52

53    public void testSetup()
54    {
55       log.info("testSetup() ....");
56       try {
57          tester.testSetup();
58          tester1.testSetup();
59       } catch (Exception JavaDoc ex) {
60          ex.printStackTrace();
61          fail("testSetup(): fails. " + ex.toString());
62       }
63    }
64
65    public void testSimple() throws Exception JavaDoc
66    {
67       log.info("testSimple() ....");
68       tester.createPerson("/person/test1", "Ben Wang", 40);
69       assertEquals((Object JavaDoc) "Ben Wang", (Object JavaDoc) tester.getName("/person/test1"));
70       assertEquals((Object JavaDoc) "Ben Wang", (Object JavaDoc) tester1.getName("/person/test1"));
71    }
72
73
74    public void testDynamicRefSwapping() throws Exception JavaDoc
75    {
76       tester.createPerson("/person/test3", "Joe", 32);
77       Person person = (Person)tester.getPerson("/person/test3");
78       try {
79          person.setAge(30);
80          List JavaDoc med = person.getMedication();
81          assertNull("Medication should be null ", med);
82          person.setAge(61);
83          med = person.getMedication();
84          assertEquals("Medication ", (Object JavaDoc)"Lipitor", (Object JavaDoc)med.get(0));
85          assertEquals("Medication on cache1 ", (Object JavaDoc)"Lipitor",
86                (Object JavaDoc)((Person)tester1.getPerson("/person/test3")).getMedication().get(0));
87
88          person.setAge(71);
89          assertEquals("Medication ", (Object JavaDoc)"Vioxx", (Object JavaDoc)med.get(1));
90          assertEquals("Medication on cache1 ", (Object JavaDoc)"Vioxx",
91                (Object JavaDoc)((Person)tester1.getPerson("/person/test3")).getMedication().get(1));
92
93       } catch (Exception JavaDoc e) {
94          // should be thrown
95
}
96    }
97
98    public void testTransient() throws Exception JavaDoc
99    {
100       log.info("testTransient() ....");
101       tester.createPerson("/person/test1", "Ben Wang", 40);
102       tester.setCurrentStatus("/person/test1", "Idle");
103       assertEquals("Cache 1 ", (Object JavaDoc) "Idle", (Object JavaDoc) tester.getCurrentStatus("/person/test1"));
104       assertEquals("Cache 2 ", (Object JavaDoc) "Active", (Object JavaDoc) tester1.getCurrentStatus("/person/test1"));
105    }
106
107    public void testModification() throws Exception JavaDoc
108    {
109       tester.createPerson("/person/test2", "Ben Wang", 40);
110       tester.setName("/person/test2", "Harald Gliebe");
111       assertEquals((Object JavaDoc) tester.getName("/person/test2"), (Object JavaDoc) "Harald Gliebe");
112       assertEquals((Object JavaDoc) tester1.getName("/person/test2"), (Object JavaDoc) "Harald Gliebe");
113       tester.removePerson("/person/test2");
114    }
115
116    public void testInheritance() throws Exception JavaDoc
117    {
118       tester.createStudent("/person/joe", "Joe", 32, "Senior");
119       tester.setName("/person/joe", "Joe Black");
120       assertEquals((Object JavaDoc) tester.getName("/person/joe"), (Object JavaDoc) "Joe Black");
121       assertEquals((Object JavaDoc) tester1.getName("/person/joe"), (Object JavaDoc) "Joe Black");
122       tester1.setYear("/person/joe", "Junior");
123       assertEquals((Object JavaDoc) tester.getYear("/person/joe"), (Object JavaDoc) "Junior");
124       assertEquals((Object JavaDoc) tester1.getYear("/person/joe"), (Object JavaDoc) "Junior");
125       tester.removePerson("/person/joe");
126    }
127
128
129    public static Test suite() throws Exception JavaDoc
130    {
131       return new TestSuite(ReplicatedAopTest.class);
132    }
133
134
135    public static void main(String JavaDoc[] args) throws Exception JavaDoc
136    {
137       junit.textui.TestRunner.run(suite());
138    }
139
140 }
141
142
Popular Tags