KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.jboss.cache.CacheException;
9 import org.jboss.cache.aop.TreeCacheAop;
10
11 import java.util.LinkedHashMap JavaDoc;
12 import java.util.LinkedHashSet JavaDoc;
13 import java.util.LinkedList JavaDoc;
14 import java.util.Map JavaDoc;
15
16
17 /**
18  * Generic Collection class support testing.
19  */

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

53    public void testLinkedList() throws Exception JavaDoc {
54       LinkedList JavaDoc list = new LinkedList JavaDoc();
55       LinkedList JavaDoc list1;
56       list.add("English");
57       try {
58          cache.putObject("/aop/list", list);
59          list = (LinkedList JavaDoc)cache.getObject("/aop/list");
60          list.add("French");
61          list1 = (LinkedList JavaDoc)cache.getObject("/aop/list");
62          assertEquals("Size of list ", 2, list1.size());
63       } catch (CacheException e) {
64          fail("pubtObject fails");
65          throw e;
66       }
67    }
68
69    /**
70     * Testing using LinkedMap proxy.
71     * @throws Exception
72     */

73    public void testLinkedMap() throws Exception JavaDoc {
74       LinkedHashMap JavaDoc map = new LinkedHashMap JavaDoc();
75       LinkedHashMap JavaDoc map1;
76       map.put("1", "English");
77       try {
78          cache.putObject("/aop/map", map);
79          map = (LinkedHashMap JavaDoc)cache.getObject("/aop/map");
80          map.put("2", "French");
81          map1 = (LinkedHashMap JavaDoc)cache.getObject("/aop/map");
82          assertEquals("Size of map ", 2, map1.size());
83       } catch (CacheException e) {
84          fail("pubtObject fails");
85          throw e;
86       }
87    }
88
89    /**
90     * Testing using LinkedSet proxy.
91     * @throws Exception
92     */

93    public void testLinkedSet() throws Exception JavaDoc {
94       LinkedHashSet JavaDoc set = new LinkedHashSet JavaDoc();
95       LinkedHashSet JavaDoc set1;
96       set.add("English");
97       Map JavaDoc map;
98       try {
99          cache.putObject("/aop/set", set);
100          set = (LinkedHashSet JavaDoc)cache.getObject("/aop/set");
101          set.add("French");
102          set1 = (LinkedHashSet JavaDoc)cache.getObject("/aop/set");
103          assertEquals("Size of set ", 2, set1.size());
104       } catch (CacheException e) {
105          fail("pubtObject fails");
106          throw e;
107       }
108    }
109
110    public static Test suite() throws Exception JavaDoc
111    {
112       return new TestSuite(CollectionAopTest.class);
113    }
114
115    public static void main(String JavaDoc[] args) throws Exception JavaDoc
116    {
117       junit.textui.TestRunner.run(suite());
118    }
119
120 }
121
122
Popular Tags