KickJava   Java API By Example, From Geeks To Geeks.

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


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

13
14 /**
15  * Set interface testing.
16  */

17
18 public class CachedSetAopTest extends TestCase
19 {
20    Log log=LogFactory.getLog(CachedSetAopTest.class);
21    TreeCacheAopTester tester;
22    Set skills;
23
24    public CachedSetAopTest(String JavaDoc name)
25    {
26       super(name);
27    }
28
29    protected void setUp() throws Exception JavaDoc
30    {
31       super.setUp();
32       log.info("setUp() ....");
33       String JavaDoc configFile = "META-INF/replSync-service.xml";
34       tester = new TreeCacheAopTester(configFile);
35       tester.createPerson("/person/test7", "p7", 27);
36       tester.addSkill("/person/test7", "Java");
37       tester.addSkill("/person/test7", "C++");
38       tester.addSkill("/person/test7", "Perl");
39       skills = tester.getSkills("/person/test7");
40    }
41
42    protected void tearDown() throws Exception JavaDoc
43    {
44       super.tearDown();
45       tester.stop();
46       tester = null;
47    }
48
49    public void testAddAndRemoveIndex() throws Throwable JavaDoc
50    {
51       int size = skills.size();
52       assertEquals("Size is ", 3, size);
53
54       skills.add("Golf");
55       size = skills.size();
56       assertEquals("Size is ", 4, size);
57
58       skills.add("Golf");
59       size = skills.size();
60       assertEquals("Size is ", 4, size);
61
62       assertTrue("Skill contain Golf ", skills.contains("Golf"));
63
64       skills.remove("C++");
65       size = skills.size();
66       assertEquals("Size is ", 3, size);
67       assertFalse("Skill does not contain C++ anymore ", skills.contains("C++"));
68
69       skills.clear();
70       size = skills.size();
71       assertEquals("Size is ", 0, size);
72
73       assertTrue("Should be empty", skills.isEmpty());
74    }
75
76    public void testAddAndRemoveAll() throws Throwable JavaDoc
77    {
78       int size = skills.size();
79       assertEquals("Size is ", 3, size);
80
81       List list = new ArrayList();
82       list.add("Tennis");
83       list.add("Polo");
84       list.add("Baseball");
85
86       skills.addAll((Collection)list);
87       size = skills.size();
88       assertEquals("Size is ", 6, size);
89       assertTrue("Skill contains Polo ", skills.contains("Polo"));
90
91       skills.removeAll((Collection)list);
92       size = skills.size();
93       assertEquals("Size is ", 3, size);
94       assertFalse("Skill does not contain Polo ", skills.contains("Polo"));
95       assertTrue("Skill contains C++ ", skills.contains("C++"));
96
97    }
98
99    public void testIterator() {
100       Iterator it = skills.iterator();
101       int counter = 0;
102       while(it.hasNext()) {
103          counter++;
104          it.next();
105          it.remove();
106       }
107
108       assertEquals("Size should be ", 3, counter);
109       assertEquals("Skills should be empty ", 0, skills.size());
110    }
111
112    public void testEquals() throws Throwable JavaDoc {
113       Set set = (Set)tester.getSkills("/person/test7");
114       assertTrue("List should be the same ", set.equals(skills));
115       set = new HashSet();
116       set.add("German");
117       set.add("test");
118       set.add("English");
119       assertFalse("List should not be the same ", set.equals(skills));
120       assertFalse("List should not be the same ", skills.equals(set));
121    }
122
123    public static Test suite() throws Exception JavaDoc
124    {
125       return new TestSuite(CachedSetAopTest.class);
126    }
127
128    public static void main(String JavaDoc[] args) throws Exception JavaDoc
129    {
130       junit.textui.TestRunner.run(suite());
131    }
132
133 }
134
135
Popular Tags