KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cache > test > standAloneAop > CollectionAopTest


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.jboss.test.cache.test.standAloneAop;
8
9 import junit.framework.Test;
10 import junit.framework.TestCase;
11 import junit.framework.TestSuite;
12 import org.jboss.logging.Logger;
13 import org.jboss.cache.aop.TreeCacheAop;
14 import org.jboss.cache.CacheException;
15
16 import java.util.*;
17
18
19 /**
20  * Generic Collection class support testing.
21  */

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

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

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

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