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 ; 12 import java.util.LinkedHashSet ; 13 import java.util.LinkedList ; 14 import java.util.Map ; 15 16 17 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 name) 28 { 29 super(name); 30 } 31 32 protected void setUp() throws Exception 33 { 34 super.setUp(); 35 log.info("setUp() ...."); 36 String configFile = "META-INF/local-service.xml"; 37 tester = new TreeCacheAopTester(configFile); 38 39 cache = tester.getCache(); 40 } 41 42 protected void tearDown() throws Exception 43 { 44 super.tearDown(); 45 tester.stop(); 46 tester = null; 47 } 48 49 53 public void testLinkedList() throws Exception { 54 LinkedList list = new LinkedList (); 55 LinkedList list1; 56 list.add("English"); 57 try { 58 cache.putObject("/aop/list", list); 59 list = (LinkedList )cache.getObject("/aop/list"); 60 list.add("French"); 61 list1 = (LinkedList )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 73 public void testLinkedMap() throws Exception { 74 LinkedHashMap map = new LinkedHashMap (); 75 LinkedHashMap map1; 76 map.put("1", "English"); 77 try { 78 cache.putObject("/aop/map", map); 79 map = (LinkedHashMap )cache.getObject("/aop/map"); 80 map.put("2", "French"); 81 map1 = (LinkedHashMap )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 93 public void testLinkedSet() throws Exception { 94 LinkedHashSet set = new LinkedHashSet (); 95 LinkedHashSet set1; 96 set.add("English"); 97 Map map; 98 try { 99 cache.putObject("/aop/set", set); 100 set = (LinkedHashSet )cache.getObject("/aop/set"); 101 set.add("French"); 102 set1 = (LinkedHashSet )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 111 { 112 return new TestSuite(CollectionAopTest.class); 113 } 114 115 public static void main(String [] args) throws Exception 116 { 117 junit.textui.TestRunner.run(suite()); 118 } 119 120 } 121 122 | Popular Tags |