[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/pojo/collection ...

Ben Wang bwang at jboss.com
Sat Jan 13 10:55:00 EST 2007


  User: bwang   
  Date: 07/01/13 10:55:00

  Added:       tests/functional/org/jboss/cache/pojo/collection            
                        CollectionTest.java CachedListTest.java
                        CachedSetTest.java ReplicatedSyncListTest.java
                        CachedListImplTest.java CachedMapImplTest.java
                        CachedMapNullTest.java ObjectGraphTest.java
                        CachedMapTest.java ReplicatedSyncSetTest.java
                        CachedListTxTest.java ReplicatedSyncMapTest.java
  Log:
  JBCACHE-922 Merged src-50 and tests-50 into src and tests, respectively.
  
  Revision  Changes    Path
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/CollectionTest.java
  
  Index: CollectionTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.LinkedHashMap;
  import java.util.LinkedHashSet;
  import java.util.LinkedList;
  import java.util.Map;
  
  /**
   * Generic Collection class support testing.
   *
   * @author Ben Wang
   */
  
  public class CollectionTest extends TestCase
  {
     Log log_ = LogFactory.getLog(CollectionTest.class);
     PojoCache cache_;
  
     public CollectionTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log_.info("setUp() ....");
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache_ = PojoCacheFactory.createCache(configFile, toStart);
        cache_.start();
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
  
     /**
      * Testing using LinkedList proxy.
      *
      * @throws Exception
      */
     public void testLinkedList() throws Exception
     {
        LinkedList list = new LinkedList();
        LinkedList list1;
        list.add("English");
        try
        {
           cache_.attach("/aop/list", list);
           list = (LinkedList) cache_.find("/aop/list");
           list.add("French");
           list1 = (LinkedList) cache_.find("/aop/list");
           assertEquals("Size of list ", 2, list1.size());
        } catch (Exception e)
        {
           fail("pubtObject fails");
           throw e;
        }
     }
  
     /**
      * Testing using LinkedMap proxy.
      *
      * @throws Exception
      */
     public void testLinkedMap() throws Exception
     {
        LinkedHashMap map = new LinkedHashMap();
        LinkedHashMap map1;
        map.put("1", "English");
        try
        {
           cache_.attach("/aop/map", map);
           map = (LinkedHashMap) cache_.find("/aop/map");
           map.put("2", "French");
           map1 = (LinkedHashMap) cache_.find("/aop/map");
           assertEquals("Size of map ", 2, map1.size());
        } catch (Exception e)
        {
           fail("pubtObject fails");
           throw e;
        }
     }
  
     /**
      * Testing using LinkedSet proxy.
      *
      * @throws Exception
      */
     public void testLinkedSet() throws Exception
     {
        LinkedHashSet set = new LinkedHashSet();
        LinkedHashSet set1;
        set.add("English");
        Map map;
        try
        {
           cache_.attach("/aop/set", set);
           set = (LinkedHashSet) cache_.find("/aop/set");
           set.add("French");
           set1 = (LinkedHashSet) cache_.find("/aop/set");
           assertEquals("Size of set ", 2, set1.size());
        } catch (Exception e)
        {
           fail("pubtObject fails");
           throw e;
        }
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CollectionTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
     // tests for each of the methods in Collection interface
     public void testSize() throws Exception
     {
  
        LinkedList list = new LinkedList();
        list.add("java");
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           assertEquals("size of collection", 1, list.size());
           list.add("c");
           list.add("lisp");
           assertEquals("size of collection", 3, list.size());
           list.remove("lisp");
           assertEquals("size of collection", 2, list.size());
           list.remove("c");
           assertEquals("size of collection", 1, list.size());
           list.clear();
           assertEquals("size of collection", 0, list.size());
        }
        catch (Exception e)
        {
           fail("testSize " + e.getMessage());
           throw e;
        }
  
     }
  
     public void testIsEmpty() throws Exception
     {
        LinkedList list = new LinkedList();
  
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           assertTrue("collection is empty", list.isEmpty());
           list.add("c");
           list.add("lisp");
           assertFalse("collection is not empty", list.isEmpty());
           list.remove("lisp");
           assertFalse("collection is not empty", list.isEmpty());
           list.remove("c");
           assertTrue("collection is empty", list.isEmpty());
        }
        catch (Exception e)
        {
           fail("testIsEmpty " + e.getMessage());
           throw e;
        }
     }
  
     public void testContains() throws Exception
     {
        LinkedList list = new LinkedList();
        list.add("java");
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           assertFalse("collection doesn't contains", list.contains("lisp"));
           list.add("c");
           list.add("lisp");
           assertTrue("collection contains", list.contains("lisp"));
           list.remove("lisp");
           assertFalse("collection doesn't contain", list.contains("lisp"));
           list.remove("c");
           list.clear();
           assertFalse("collection doesn't contains", list.contains("c"));
        }
        catch (Exception e)
        {
           fail("testContains " + e.getMessage());
           throw e;
        }
  
     }
  
     public void testIterator() throws Exception
     {
        LinkedList list = new LinkedList();
        LinkedList list2 = new LinkedList();
        list2.add("java");
        list2.add("c");
        list2.add("lisp");
        list2.add("c++");
        list2.add("forth");
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           list.addAll(list2);
           Iterator iter = list.iterator();
           while (iter.hasNext())
           {
              Object o = iter.next();
              assertTrue("Iteration test", list2.contains(o));
           }
        }
        catch (Exception e)
        {
           fail("testIterator " + e.getMessage());
           throw e;
        }
     }
  
     public void testToArray() throws Exception
     {
        LinkedList list = new LinkedList();
        LinkedList list2 = new LinkedList();
        list2.add("java");
        list2.add("c");
        list2.add("lisp");
        list2.add("c++");
        list2.add("forth");
        list.addAll(list2);
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           Object[] values = list.toArray();
  
           for (int looper = 0; looper < values.length; looper ++)
           {
              assertTrue("toArray test", list2.contains(values[looper]));
           }
  
           values = new Object[1];
           values = list.toArray(values);  // test with too small of an array
           for (int looper = 0; looper < values.length; looper ++)
           {
              assertTrue("toArray test", list2.contains(values[looper]));
           }
  
           values = new Object[10];
           values = list.toArray(values);  // test with too large of an array, result should be null padded
           for (int looper = 0; looper < values.length; looper ++)
           {
              assertTrue("toArray test", (values[looper] == null || list2.contains(values[looper])));
           }
  
        }
        catch (Exception e)
        {
           fail("testToArray " + e.getMessage());
           throw e;
        }
     }
  
     public void testAdd() throws Exception
     {
        LinkedList list = new LinkedList();
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           list.add("java");
           assertTrue("add test", list.contains("java"));
           assertFalse("add test", list.contains("c#"));
        }
        catch (Exception e)
        {
           fail("testAdd " + e.getMessage());
           throw e;
        }
  
     }
  
     public void testRemove() throws Exception
     {
        LinkedList list = new LinkedList();
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           list.add("java");
           assertTrue(list.remove("java"));
           assertFalse("remove test", list.contains("java"));
        }
        catch (Exception e)
        {
           fail("testRemove " + e.getMessage());
           throw e;
        }
  
     }
  
     public void testAddAll() throws Exception
     {
        LinkedList list = new LinkedList();
        LinkedList list2 = new LinkedList();
        list2.add("java");
        list2.add("c");
        list2.add("lisp");
        list2.add("c++");
        list2.add("forth");
  
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           assertTrue(list.addAll(list2));
           Object[] values = list.toArray();
  
           for (int looper = 0; looper < values.length; looper ++)
           {
              assertTrue("testAddAll", list2.contains(values[looper]));
           }
        }
        catch (Exception e)
        {
           fail("testAddAll " + e.getMessage());
           throw e;
        }
  
     }
  
     public void testClear() throws Exception
     {
        LinkedList list = new LinkedList();
        LinkedList list2 = new LinkedList();
        list2.add("java");
        list2.add("c");
        list2.add("lisp");
        list2.add("c++");
        list2.add("forth");
  
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           assertTrue(list.addAll(list2));
           assertTrue("testClear", list.size() > 0);
           list.clear();
           assertTrue("testClear", list.size() == 0);
        }
        catch (Exception e)
        {
           fail("testClear " + e.getMessage());
           throw e;
        }
  
     }
  
     public void testRetainAll() throws Exception
     {
        LinkedList list = new LinkedList();
        LinkedList list2 = new LinkedList();
        list2.add("java");
        list2.add("c");
        list2.add("lisp");
        list2.add("c++");
        list2.add("forth");
  
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           assertTrue(list.addAll(list2));
           list2.remove("c");
           list2.remove("lisp");
           list2.remove("c++");
           list2.remove("forth");
           assertTrue("testRetainAll", list.retainAll(list2));
           // should only have java left
           assertTrue("testRetainAll, list size should be 1 but is " + list.size(), list.size() == 1);
           assertTrue("testRetainAll", list.contains("java"));
        }
        catch (Exception e)
        {
           fail("testRetainAll " + e.getMessage());
           throw e;
        }
  
  
     }
  
     public void testRemoveAll() throws Exception
     {
        LinkedList list = new LinkedList();
        LinkedList list2 = new LinkedList();
        list2.add("java");
        list2.add("c");
        list2.add("lisp");
        list2.add("c++");
        list2.add("forth");
  
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           assertTrue(list.addAll(list2));
           list2.remove("java");
           assertTrue("testRemoveAll", list.removeAll(list2));
           // should only have java left
           assertTrue("testRemoveAll", list.size() == 1);
           assertTrue("testRemoveAll", list.contains("java"));
        }
  
        catch (Exception e)
        {
           fail("testRemoveAll " + e.getMessage());
           throw e;
        }
  
  
     }
  
     public void testContainsAll() throws Exception
     {
        LinkedList list = new LinkedList();
        LinkedList list2 = new LinkedList();
        list2.add("java");
        list2.add("c");
        list2.add("lisp");
        list2.add("c++");
        list2.add("forth");
  
        try
        {
           cache_.attach("/language/list", list);
           list = (LinkedList) cache_.find("/language/list");
           assertTrue(list.addAll(list2));
           list2.remove("java");
           assertTrue("testContainsAll", list.containsAll(list2));
           list.remove("c");
           assertFalse("testContainsAll", list.containsAll(list2));
        }
        catch (Exception e)
        {
           fail("testContainsAll " + e.getMessage());
           throw e;
        }
     }
     
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/CachedListTest.java
  
  Index: CachedListTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.test.Address;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.ListIterator;
  import java.util.NoSuchElementException;
  
  /**
   * List interface testing.
   *
   * @author Ben Wang
   */
  
  public class CachedListTest extends TestCase
  {
     Log log = LogFactory.getLog(CachedListTest.class);
     PojoCache cache_;
     List languages;
     List languages2;
  
     public CachedListTest(String name)
     {
        super(name);
     }
  
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache_ = PojoCacheFactory.createCache(configFile, toStart);
        cache_.start();
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
  
     public void testAddAndRemoveIndex() throws Throwable
     {
        stage();
  
        languages.add(1, "Taiwanese");
        assertEquals("Languages size ", 4, languages.size());
        assertEquals("Language ", (Object) "Taiwanese", (Object) languages.get(1));
        languages.remove(2);
        assertEquals("Languages size ", 3, languages.size());
        assertEquals("Language ", (Object) "English", (Object) languages.get(2));
  
        languages.add("Mandarin");
        assertEquals("Languages size ", 4, languages.size());
        languages.remove("Mandarin");
        assertEquals("Languages size ", 3, languages.size());
     }
  
     protected void stage() throws Throwable
     {
        languages = new ArrayList();
        languages.add("English");
        languages.add("French");
        languages.add("English");
        cache_.attach("/person/test6", languages);
        languages = (List) cache_.find("/person/test6");
        int size = languages.size();
        assertEquals("Size of list ", 3, size);
  
        languages2 = new ArrayList();
        languages2.addAll(languages);
        assertEquals("New ArrayList().addAll(CachedList)", languages, languages2);
     }
  
     public void testAddAllAndClear() throws Throwable
     {
        stage();
        List list = new ArrayList();
        list.add("Taiwanese");
        list.add("Madarin");
  
        assertTrue("Language is Taiwanese ", list.contains("Taiwanese"));
  
        languages.addAll(list);
        assertEquals("Languages size ", 5, languages.size());
  
        languages.removeAll(list);
        assertEquals("Languages size ", 3, languages.size());
  
        assertEquals("Index of French ", 1, languages.indexOf("French"));
  
        languages.clear();
        assertEquals("Languages size ", 0, languages.size());
  
        assertTrue("Languages empty ", languages.isEmpty());
     }
  
     public void testEquals() throws Throwable
     {
        stage();
  
        List list = (List) cache_.find("/person/test6");
        assertTrue("List should be the same ", list.equals(languages));
        list = new ArrayList();
        list.add("German");
        list.add("test");
        list.add("English");
        assertFalse("List should not be the same ", languages.equals(list));
        assertFalse("List should not be the same ", list.equals(languages));
     }
  
     public void testSet() throws Throwable
     {
        stage();
  
        List list = (List) cache_.find("/person/test6");
        assertTrue("List should be the same ", list.equals(languages));
        assertEquals("List size ", 3, list.size());
        list.set(0, "German");
        list.set(1, "test");
        list.set(2, "English");
        assertEquals("List size ", 3, list.size());
     }
  
     public void testIterator() throws Throwable
     {
        languages = new ArrayList();
        Iterator it0 = languages.iterator();
        assertFalse("Iterator should be empty ", it0.hasNext());
  
        stage();
  
        Iterator it = languages.iterator();
        Iterator it2 = languages2.iterator();
        int counter = 0;
        while (it.hasNext())
        {
           counter++;
           assertEquals(it.next(), it2.next());
           it.remove();
           it2.remove();
        }
  
        assertEquals("Size should be ", 3, counter);
        assertEquals("Skills should be empty ", 0, languages.size());
     }
  
     public void testListIterator() throws Throwable
     {
        languages = new ArrayList();
        ListIterator it0 = languages.listIterator();
        assertFalse("Iterator should be empty ", it0.hasNext());
        assertFalse("Iterator should be empty ", it0.hasPrevious());
  
        stage();
  
        ListIterator li = languages.listIterator();
        ListIterator li2 = languages2.listIterator();
        assertFalse("LI has no previous element ", li.hasPrevious());
        assertFalse("LI2 has no previous element ", li2.hasPrevious());
        assertTrue("LI has next element ", li.hasNext());
        assertTrue("LI2 has next element ", li2.hasNext());
        assertEquals(li.next(), li2.next());
        assertEquals("Index is ", 1, li.nextIndex());
        assertEquals("Index is ", 1, li2.nextIndex());
        assertEquals("Index is ", 0, li.previousIndex());
        assertEquals("Index is ", 0, li2.previousIndex());
        assertEquals(li.next(), li2.next());
        assertEquals(li.next(), li2.next()); // the end
        try
        {
           li.next();
           fail("Should throw an exception here ");
        }
        catch (NoSuchElementException ex)
        {
           ;
        }
        try
        {
           li2.next();
           fail("Should throw an exception here ");
        }
        catch (NoSuchElementException ex)
        {
           ;
        }
  
        assertEquals("Index is ", 3, li.nextIndex());
        assertEquals("Index is ", 3, li2.nextIndex());
        assertEquals("Index is ", 2, li.previousIndex());
        assertEquals("Index is ", 2, li2.previousIndex());
        li.previous();
        li2.previous();
        assertEquals("Index is ", 2, li.nextIndex());
        assertEquals("Index is ", 2, li2.nextIndex());
        assertEquals("Index is ", 1, li.previousIndex());
        assertEquals("Index is ", 1, li2.previousIndex());
        li.previous();
        li2.previous();
        li.previous();
        li2.previous();
  
        try
        {
           li.previous();
           fail("Should throw an exception here ");
        }
        catch (NoSuchElementException ex)
        {
           ;
        }
  
        try
        {
           li2.previous();
           fail("Should throw an exception here ");
        }
        catch (NoSuchElementException ex)
        {
           ;
        }
  
        try
        {
           assertEquals(li.next(), li2.next());
           li.remove();
           li2.remove();
        }
        catch (Exception e)
        {
           fail("ListIterator.remove failed" + e);
        }
  
  
        try
        {
           assertEquals(li.next(), li2.next());
           li.remove();
           li2.remove();
        }
        catch (Exception e)
        {
           fail("ListIterator.remove failed" + e);
        }
  
        try
        {
           assertEquals(li.next(), li2.next());
           assertEquals("ListIterator.remove test problem with nextIndex, cache next index=" + li.nextIndex() +
                   ", jdk next index=" + li2.nextIndex() + "cache list size = " + languages.size() + ", jdk list size = " + languages.size(),
                   li.nextIndex(), li2.nextIndex());
           li2.set("German");
           li.set("German");
           String s1 = (String) li.previous();
           String s2 = (String) li2.previous();
           assertEquals(s1, s2);
           assertEquals(s2, "German");
        }
        catch (Exception e)
        {
           fail("ListIterator.remove failed" + e + ", cache list size = " + languages.size() + ", jdk list size = " + languages.size());
        }
  
        try
        {
           assertEquals(li.next(), li2.next());
           li2.add("Vulcan");
           li.add("Vulcan");
           String s1 = (String) li.previous();
           String s2 = (String) li2.previous();
           assertEquals(s1, s2);
           assertEquals(s2, "Vulcan");
        }
        catch (Exception e)
        {
           fail("ListIterator.add failed" + e + ", cache list size = " + languages.size() + ", jdk list size = " + languages.size());
        }
  
     }
  
  
     public void testAttachAndDetach() throws Exception
     {
        List list = new ArrayList();
        list.add("English");
        list.add("French");
        list.add("Taiwanese");
  
        cache_.attach("/test", list); // attach
        list = (List) cache_.find("/test");
        assertEquals("Size ", 3, list.size());
  
        list = (List) cache_.detach("/test");
        assertEquals("Size ", 3, list.size());
  
        System.out.println("**** End of cache content **** ");
        list.remove(2);
        list.add("Hoklo");
        assertEquals("Size ", 3, list.size());
        assertEquals("Content ", "Hoklo", list.get(2));
  
        // Try to re-attach
        cache_.attach("/test", list);
        list.remove(2);
        assertEquals("Size ", 2, list.size());
     }
  
     public void testPojoAttachAndDetach() throws Exception
     {
        Address add1 = new Address();
        add1.setCity("San Jose");
        add1.setZip(95123);
  
        Address add2 = new Address();
        add2.setCity("Sunnyvale");
        add2.setZip(94086);
  
        Address add3 = new Address();
        add3.setCity("Santa Clara");
        add3.setZip(951131);
  
        List list = new ArrayList();
        list.add(add1);
        list.add(add2);
        list.add(add3);
  
        cache_.attach("/test", list); // attach
        list = (List) cache_.find("/test");
        assertEquals("Size ", 3, list.size());
  
        list = (List) cache_.detach("/test");
        assertEquals("Size ", 3, list.size());
  
        System.out.println("**** End of cache content **** ");
        list.remove(2);
        list.add(add2);
        assertEquals("Size ", 3, list.size());
        assertEquals("Content ", add2, list.get(2));
  
        // Try to re-attach
        cache_.attach("/test", list);
        list.remove(2);
        assertEquals("Size ", 2, list.size());
     }
  
     public void testEqual1() throws Exception
     {
        List list1 = new ArrayList();
        list1.add("ID1");
        list1.add("ID2");
        cache_.attach("test1", list1);
        list1 = (List)cache_.find("test1");
  
        List list2 = new ArrayList();
        list2.add("ID1");
        list2.add("ID2");
        cache_.attach("test2", list2);
        list2 = (List)cache_.find("test2");
  
        List list3 = new ArrayList();
        list3.add("ID2");
        list3.add("ID1");
        cache_.attach("test3", list3);
        list3 = (List)cache_.find("test3");
  
        assertEquals("List should be equal: ", list1, list1);
        assertTrue("List should be equal: ", list1.equals(list1));
        assertTrue("List should be equal: ", list1.equals(list2));
        assertFalse("List should not be equal: ", list1.equals(list3));
     }
  
     public void testEqual2() throws Exception
     {
        List list1 = new ArrayList();
        cache_.attach("test1", list1);
        list1 = (List)cache_.find("test1");
        list1.add("ID1");
        list1.add("ID2");
  
        List list2 = new ArrayList();
        cache_.attach("test2", list2);
        list2 = (List)cache_.find("test2");
        list2.add("ID1");
        list2.add("ID2");
  
        List list3 = new ArrayList();
        cache_.attach("test3", list3);
        list3 = (List)cache_.find("test3");
        list3.add("ID2");
        list3.add("ID1");
  
        assertEquals("List should be equal: ", list1, list1);
        assertTrue("List should be equal: ", list1.equals(list1));
        assertTrue("List should be equal: ", list1.equals(list2));
        assertFalse("List should not be equal: ", list1.equals(list3));
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CachedListTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/CachedSetTest.java
  
  Index: CachedSetTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.test.Address;
  
  import java.io.PrintWriter;
  import java.io.StringWriter;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.NoSuchElementException;
  import java.util.Set;
  
  /**
   * Set interface testing.
   *
   * @author Ben Wang
   */
  
  public class CachedSetTest extends TestCase
  {
     Log log = LogFactory.getLog(CachedSetTest.class);
     PojoCache cache_;
     Set skills;
  
     public CachedSetTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache_ = PojoCacheFactory.createCache(configFile, toStart);
        cache_.start();
  
        stage();
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
  
     protected void stage() throws Exception
     {
        skills = new HashSet();
        skills.add("Java");
        skills.add("C++");
        skills.add("Perl");
  
        cache_.attach("/person/test7", skills);
        skills = (Set) cache_.find("/person/test7");
        int size = skills.size();
        assertEquals("Size is ", 3, size);
     }
  
     public void testClear() throws Throwable
     {
        int size = skills.size();
        assertEquals("Size is ", 3, size);
  
        skills.clear();
        size = skills.size();
        assertEquals("Size is ", 0, size);
  
        assertTrue("Should be empty", skills.isEmpty());
     }
  
     public void testAddAndRemoveIndex() throws Throwable
     {
        skills.add("Golf");
        int size = skills.size();
        assertEquals("Size is ", 4, size);
  
        skills.add("Golf");
        size = skills.size();
        assertEquals("Size is ", 4, size);
  
        assertTrue("Skill shuold contain Golf ", skills.contains("Golf"));
        skills.remove("C++");
        size = skills.size();
        assertEquals("Size is ", 3, size);
        assertFalse("Skill does not contain C++ anymore ", skills.contains("C++"));
  
        skills.add("Golf");
        size = skills.size();
        assertEquals("Size is ", 3, size);
        skills.clear();
        size = skills.size();
        assertEquals("Size is ", 0, size);
  
        assertTrue("Should be empty", skills.isEmpty());
     }
  
     private static class DumbObject implements java.io.Serializable
     {
        int i;
        DumbObject(int i) { this.i = i; }
        public int hashCode()
        {
           return 0;
        }
        public String toString()
        {
           return "" + i;
        }
     }
     
     public void testConflictingHash() throws Exception
     {
        Set set = new HashSet();
        String nulls = null;
        DumbObject o1 = new DumbObject(1);
        DumbObject o2 = new DumbObject(2);
        DumbObject o3 = new DumbObject(3);
        set.add(o1);
        set.add(o2);
        set.add(o3);
        set.add(nulls);
        Set set2 = Collections.unmodifiableSet(new HashSet(set));
  
        cache_.attach("/test", set); // attach
        set = (Set) cache_.find("/test");
        assertEquals("Same", set2, set);
        assertEquals(true, set.remove(o2));
        assertEquals(true, set.remove(nulls));
        assertEquals(false, set.remove(o2));
        assertEquals("Same minus 2 ", set2.size()-2, set.size());
        assertEquals("set " + set, true, set.add(o2));
        assertEquals("set " + set, true, set.add(nulls));
        assertEquals(false, set.add(o2));
        assertEquals(false, set.add(nulls));
        assertEquals("Same", set2, set);
     }
  
     public void testAddAndRemoveAll() throws Throwable
     {
        List list = new ArrayList();
        list.add("Tennis");
        list.add("Polo");
        list.add("Baseball");
  
        skills.addAll((Collection) list);
        int size = skills.size();
        assertEquals("Size is ", 6, size);
        assertTrue("Skill contains Polo ", skills.contains("Polo"));
  
        skills.removeAll((Collection) list);
        size = skills.size();
        assertEquals("Size is ", 3, size);
        assertFalse("Skill does not contain Polo ", skills.contains("Polo"));
        assertTrue("Skill contains C++ ", skills.contains("C++"));
  
     }
  
     public void testRemoveAndAdd()
     {
        assertTrue(skills.remove("C++"));
        assertTrue(skills.add("C++"));
        assertEquals("removeAndAdd: size is 3", 3, skills.size());
     }
  
     public void testIterator()
     {
        Iterator it = skills.iterator();
        int counter = 0;
        while (it.hasNext())
        {
           counter++;
           it.next();
           it.remove();
        }
  
        assertEquals("iterator: Size should be ", 3, counter);
        assertEquals("iterator: Skills should be empty ", 0, skills.size());
  
        List list = new ArrayList();
        list.add("Tennis");
        list.add("Polo");
        list.add("Baseball");
        list.add("Soccer");
        list.add("Hockey");
        list.add("Lacrosse");
        skills.addAll(list);
        it = skills.iterator();
        while (it.hasNext())
        {
           counter++;
           if ("Polo".equals(it.next()))
           {
              it.remove();
           }
        }
        assertFalse("iterator: item removed via iterator", skills.contains("Polo"));
        assertTrue("iterator: item not removed via iterator", skills.contains("Lacrosse"));
  
        // Check for proper relationship between hasNext and next
        list = new ArrayList();
        list.add("Tennis");
        list.add("Polo");
        list.add("Baseball");
        skills.addAll(list);
        it = skills.iterator();
        while (it.hasNext())
        {
           it.next();
        }
        try
        {
           it.next();
           fail("iterator: Didn't fail on next() when hasNext() == false");
        }
        catch (NoSuchElementException good)
        {
        }
  
        // Check for proper relationship between next and remove
        it = skills.iterator();
        try
        {
           it.remove();
        }
        catch (IllegalStateException good)
        {
           // behaves correctly per Iterator contract
        }
        catch (Exception e)
        {
           StringWriter stackTrace = new StringWriter();
           e.printStackTrace(new PrintWriter(stackTrace));
           fail("iterator: failed with incorrect exception type when removing " +
                   "without first calling next() -- " + e.getClass().getName() + ".  stackTrace=" + stackTrace);
        }
  
  
     }
  
     public void testEquals() throws Throwable
     {
        Set set = (Set) cache_.find("/person/test7");
        assertTrue("iterator: List should be the same ", set.equals(skills));
        set = new HashSet();
        set.add("German");
        set.add("test");
        set.add("English");
        assertFalse("List should not be the same ", set.equals(skills));
        assertFalse("List should not be the same ", skills.equals(set));
     }
  
  
     public void testAttachAndDetach() throws Exception
     {
        Set set = new HashSet();
        set.add("English");
        set.add("French");
        set.add("Taiwanese");
  
        cache_.attach("/test", set); // attach
        set = (Set) cache_.find("/test");
        assertEquals("Size ", 3, set.size());
  
        set = (Set) cache_.detach("/test");
        assertEquals("Size ", 3, set.size());
  
        System.out.println("**** End of cache content **** ");
        set.remove("French");
        set.add("Hoklo");
        assertEquals("Size ", 3, set.size());
        assertTrue("Content ", set.contains("Hoklo"));
  
        // Try to re-attach
        cache_.attach("/test", set);
        set.remove("Taiwanese");
        assertEquals("Size ", 2, set.size());
     }
  
     public void testPojoAttachAndDetach() throws Exception
     {
        Address add1 = new Address();
        add1.setCity("San Jose");
        add1.setZip(95123);
  
        Address add2 = new Address();
        add2.setCity("Sunnyvale");
        add2.setZip(94086);
  
        Address add3 = new Address();
        add3.setCity("Santa Clara");
        add3.setZip(951131);
  
        Set set = new HashSet();
        set.add(add1);
        set.add(add2);
        set.add(add3);
  
        cache_.attach("/test", set); // attach
        set = (Set) cache_.find("/test");
        assertEquals("Size ", 3, set.size());
  
        set = (Set) cache_.detach("/test");
        assertEquals("Size ", 3, set.size());
  
        System.out.println("**** End of cache content **** ");
        set.remove(add2);
        set.add(add2);
        assertEquals("Size ", 3, set.size());
        assertTrue("Content ", set.contains(add2));
  
        // Try to re-attach
        cache_.attach("/test", set);
        set.remove(add2);
        assertEquals("Size ", 2, set.size());
     }
  
     public void testToArray() throws Exception
     {
        Object[] arr = skills.toArray();
        assertEquals("toArray: array length is correct", 3, arr.length);
        testLanguagesFound(arr);
  
        Object[] arr1 = skills.toArray(arr);
        assertTrue("toArray: arrays match", Arrays.equals(arr, arr1));
  
        arr = new Object[5];
        arr = skills.toArray(arr);
        assertEquals("toArray: array length is correct", 5, arr.length);
        testLanguagesFound(arr);
        assertEquals(null, arr[3]);
        assertEquals(null, arr[4]);
  
        arr = new Object[2];
        arr = skills.toArray(arr);
        assertEquals("toArray: array length is correct", 3, arr.length);
        testLanguagesFound(arr);
  
     }
  
     private void testLanguagesFound(Object[] arr)
     {
        boolean[] found = new boolean[3];
        for (int i = 0; i < arr.length; i++)
        {
           if ("Java".equals(arr[i]))
              found[0] = true;
           else if ("C++".equals(arr[i]))
              found[1] = true;
           else if ("Perl".equals(arr[i]))
              found[2] = true;
        }
        assertTrue("toArray: all elements found", found[0] && found[1] && found[2]);
  
     }
  
     public void testRetainAll() throws Exception
     {
        LinkedList list2 = new LinkedList();
        list2.add("Java");
  
        assertTrue("testRetainAll", skills.retainAll(list2));
        // should only have Java left
        assertTrue("testRetainAll, skills size should be 1 but is " + skills.size(), skills.size() == 1);
        assertTrue("testRetainAll", skills.contains("Java"));
  
     }
  
     public void testContainsAll() throws Exception
     {
        LinkedList list2 = new LinkedList();
        list2.add("Java");
        list2.add("C++");
        list2.add("Perl");
  
        skills.clear();
  
        assertTrue(skills.addAll(list2));
        list2.remove("Java");
        assertTrue("testContainsAll", skills.containsAll(list2));
        skills.remove("C++");
        assertFalse("testContainsAll", skills.containsAll(list2));
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CachedSetTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/ReplicatedSyncListTest.java
  
  Index: ReplicatedSyncListTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.test.Address;
  import org.jboss.cache.pojo.test.Person;
  import org.jboss.cache.Fqn;
  import org.jboss.aop.proxy.ClassProxy;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.ListIterator;
  
  /**
   * Test object graph handling in aop, e.g., circular reference, multiple reference, link, etc.
   *
   * @author Ben Wang
   */
  
  public class ReplicatedSyncListTest extends TestCase
  {
     Log log = LogFactory.getLog(ReplicatedSyncListTest.class);
     PojoCache cache1;
     PojoCache cache2;
  
     public ReplicatedSyncListTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        cache1 = createCache("CacheGroup");
        cache2 = createCache("CacheGroup");
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache1.getCache().removeNode(Fqn.fromString("/"));
        cache1.stop();
        cache2.stop();
     }
  
     private PojoCache createCache(String name) throws Exception
     {
        boolean toStart = false;
        PojoCache cache = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
        cache.start();
        return cache;
     }
  
  //   public void testDummy() {}
  
  
     protected Person createPerson(String name, int age)
     {
        Person p = new Person();
        p.setName(name);
        p.setAge(age);
        return p;
     }
  
     /**
      * Test attachment and then detachment and attachment.
      *
      * @throws Exception
      */
     public void testAttachDetach() throws Exception
     {
        log.info("testAttachDetach() ....");
        List list1 = new ArrayList();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        list1.add(addr);
  
        Address addr2 = new Address();
        addr2.setCity("Santa Clara");
        addr2.setZip(95131);
  
        Address addr3 = new Address();
        addr3.setCity("Sunnyvale");
        addr3.setZip(94086);
  
        // Pure list
        cache1.attach("/list", list1);
        list1 = (List) cache1.find("/list");
        list1.add(addr2);
        // The return value is the original reference.
        list1 = (List)cache1.detach("/list");
        assertEquals("Detached list should still be", 2, list1.size());
        list1.add(addr3);
        cache1.attach("/list", list1);
  
        List list2 = (List) cache2.find("/list");
        assertTrue("List size should not be 0 ", (list2.size() != 0));
        assertEquals("Both list values should be equal ", ((Address) list1.get(0)).getZip(),
                ((Address) list2.get(0)).getZip());
     }
  
     /**
      * Two different keys share same list.
      *
      * @throws Exception
      */
     public void testRelationshipWithSharedList1() throws Exception
     {
        log.info("testRelationshipWithList() ....");
        List list1 = new ArrayList();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        list1.add(addr);
  
        // Pure list
        cache1.attach("/list", list1);
        // We specifically need to use Proxy otherwise it won't work with multiple references
        list1 = (List) cache1.find("/list");
        cache1.attach("/alias", list1);
  
        List list2 = (List) cache1.find("/alias");
        Address add1 = (Address) list2.get(0);
        assertNotNull("Address should not be null", add1);
        assertEquals("Zip ", 95123, add1.getZip());
  
        list1 = (List) cache2.find("/list");
        list2 = (List) cache2.find("/alias");
        assertTrue("List size should not be 0 ", (list2.size() != 0));
        assertEquals("Both lists should be equal ", list1, list2);
        assertEquals("Both list values should be equal ", list1.get(0), list2.get(0));
     }
  
     /**
      * Shared object between two list item.
      *
      * @throws Exception
      */
     public void testRelationshipWithSharedList2() throws Exception
     {
        log.info("testRelationshipWithList2() ....");
        // 2 lists with shared objects
        List list1 = new ArrayList();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        list1.add(addr);
  
        List list2 = new ArrayList();
        list2.add(addr);
  
        cache1.attach("/list1", list1);
        cache1.attach("/list2", list2);
        Address add2 = (Address) ((List) cache2.find("/list2")).get(0);
        Address add1 = (Address) ((List) cache2.find("/list1")).get(0);
        assertEquals("Address should be the same", add1, add2);
        assertEquals("Both shared object should be equal ", add2.getZip(), add1.getZip());
     }
  
     /**
      * Shared object between regular POJO and List item.
      *
      * @throws Exception
      */
     public void testRelationshipWithSharedList3() throws Exception
     {
        log.info("testRelationshipWithList3() ....");
        // 2 lists with shared objects
        List list1 = new ArrayList();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        list1.add(addr);
  
        List list2 = new ArrayList();
        list2.add(addr);
  
        cache1.attach("/address", addr);
        cache1.attach("/list1", list1);
        Address add1 = (Address) ((List) cache2.find("/list1")).get(0);
        Address add2 = (Address) cache2.find("/address");
        assertEquals("Address should be the same", add1, add2);
        assertEquals("Both shared object should be equal ", 95123, add1.getZip());
     }
  
     public void testNullWithSharedList1() throws Exception
     {
        log.info("testNullWithSharedList1() ....");
        List list1 = new ArrayList();
        list1.add("element 0");
        list1.add(null);  // element 1
        list1.add("element 2");
        list1.add(null);  // element 3
  
        // Pure set
        cache1.attach("/list", list1);
        // We specifically need to use Proxy otherwise it won't work with multiple references
        list1 = (List) cache1.find("/list");
        cache1.attach("/alias", list1);
  
        List list2 = (List) cache1.find("/alias");
  
        list1 = (List) cache2.find("/list");
        list2 = (List) cache2.find("/alias");
        assertTrue("List size should not be 0 ", (list2.size() != 0));
        assertEquals("Both listss should be equal ", list1, list2);
  
        Object a1[] = list1.toArray();
        Object a2[] = list2.toArray();
        assertTrue("element 1 is null", (a1[1] == null));
        assertTrue("element 1 is null", (a2[1] == null));
        assertTrue("element 3 is null", (a1[3] == null));
        assertTrue("element 3 is null", (a2[3] == null));
  
        assertTrue("contains test for null value", list1.contains(null));
        assertTrue("contains test for null value", list2.contains(null));
  
        assertTrue("index of null ", list2.indexOf(null) == 1);
        assertTrue("last index of null ", list2.lastIndexOf(null) == 3);
  
        list1.set(0, null);   // set first element to null
        assertTrue("set first item to null", list2.get(0) == null);
        list1.set(0, "element 0");
        assertTrue("set first item to 'element 0'", list2.get(0).equals("element 0"));
  
  
        ListIterator listIter = list1.listIterator();
        assertTrue("listiter has next", listIter.hasNext());
        assertTrue("listiter 1st element is 'element 0'", listIter.next().equals("element 0"));
        assertTrue("listiter has next", listIter.hasNext());
        assertTrue("listiter 2nd element is null", listIter.next() == null);
        listIter.remove();
  
        assertTrue("2nd element should be 'element 2'", list2.get(1).equals("element 2"));
  
     }
  
     public void testRecursion1() throws Exception
     {
        List list = new ArrayList();
        list.add("1");
        list.add("2");
        cache1.attach("list", list);
        
        list = (List)cache1.find("list");
        list.add(list);
  
        assertEquals("size ", 3, list.size());
        List l2 = (List)list.get(2);
        assertTrue("Instance of AopProxy", l2 instanceof ClassProxy);
  //      assertEquals("ClassProxy instance", list, l2);
     }
  
     public void testRecursion2() throws Exception
     {
        List list = new ArrayList();
        list.add("1");
        list.add("2");
        list.add(list);
  
        cache1.attach("list", list);
  
        list = (List)cache1.find("list");
        list.toString();
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ReplicatedSyncListTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/CachedListImplTest.java
  
  Index: CachedListImplTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.Fqn;
  
  import java.util.List;
  import java.util.ArrayList;
  
  /**
   * List implementation testing.
   *
   * @author Ben Wang
   */
  
  public class CachedListImplTest extends TestCase
  {
     Log log = LogFactory.getLog(CachedListImplTest.class);
     PojoCache cache_, cache1_;
  
     public CachedListImplTest(String name)
     {
        super(name);
     }
  
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        boolean toStart = true;
        cache_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
  
        cache1_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
        cache1_.stop();
     }
  
     public void testSimpleRepl()
     {
        List list = new ArrayList();
        list.add("1");
        list.add("2");
  
        cache_.attach("list", list);
  
        // proxy now
        list = (List)cache_.find("list");
  
        // test repl
        cache_.getCache().put(Fqn.fromString("test"), "1", list);
  
        ArrayList l1 = (ArrayList)cache1_.getCache().get(Fqn.fromString("test"), "1");
        System.out.println(" list : " +l1);
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CachedListImplTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/CachedMapImplTest.java
  
  Index: CachedMapImplTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.TestCase;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.Fqn;
  
  import java.util.List;
  import java.util.ArrayList;
  import java.util.Map;
  import java.util.HashMap;
  
  /**
   * List implementation testing.
   *
   * @author Ben Wang
   */
  
  public class CachedMapImplTest extends TestCase
  {
     Log log = LogFactory.getLog(CachedMapImplTest.class);
     PojoCache cache_, cache1_;
  
     public CachedMapImplTest(String name)
     {
        super(name);
     }
  
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        boolean toStart = true;
        cache_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
  
        cache1_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
        cache1_.stop();
     }
  
     public void testSimpleRepl()
     {
        Map map = new HashMap();
        map.put("1", "1");
        map.put("2", "2");
  
        cache_.attach("map", map);
  
        // proxy now
        map = (Map)cache_.find("map");
  
        // test repl
        cache_.getCache().put(Fqn.fromString("test"), "1", map);
  
        Map m1 = (Map)cache1_.getCache().get(Fqn.fromString("test"), "1");
        System.out.println(" map : " +m1);
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CachedMapImplTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/CachedMapNullTest.java
  
  Index: CachedMapNullTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.aop.proxy.ClassProxy;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.test.Address;
  
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  
  /**
   * Set interface testing.
   *
   * @author Scott Marlow
   */
  
  public class CachedMapNullTest extends TestCase
  {
     Log log = LogFactory.getLog(CachedMapNullTest.class);
     PojoCache cache_;
     Map hobbies;
  
     public CachedMapNullTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache_ = PojoCacheFactory.createCache(configFile, toStart);
        cache_.start();
  
        stage();
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
  
     static final int NUMBER_OF_STAGED_HOBBIES = 5;
  
     protected void stage() throws Exception
     {
        hobbies = new HashMap();
        hobbies.put("1", "golf");
        hobbies.put("2", "tennis");
        hobbies.put("3", "polo");
        hobbies.put(null, "Non-null value but the key is null");
        hobbies.put("key is non-null but value is null", null);
  
        cache_.attach("/person/test7", hobbies);
        hobbies = (Map) cache_.find("/person/test7");
        assertEquals("Map size", NUMBER_OF_STAGED_HOBBIES, hobbies.size());
  
        if (!(hobbies instanceof ClassProxy || hobbies instanceof Map))
        {
           fail("testPut(): hobbies is not instance of ClassProxy nor Map");
        }
     }
  
     /**
      * Test simple put
      *
      * @throws Throwable
      */
     public void testPut() throws Throwable
     {
        int size = hobbies.size();
        assertEquals("Size is ", NUMBER_OF_STAGED_HOBBIES, size);
  
        hobbies.put("6", "baseball");
        size = hobbies.size();
        assertEquals("Size is ", NUMBER_OF_STAGED_HOBBIES + 1, size);
  
     }
  
     public void testAddAndRemoveIndex() throws Throwable
     {
        hobbies.put("4", "baseball");
        int size = hobbies.size();
        assertEquals("Size is ", NUMBER_OF_STAGED_HOBBIES + 1, size);
  
        assertTrue("Skill contain Golf ", hobbies.containsKey("3"));
  
        hobbies.remove("3");
        size = hobbies.size();
        assertEquals("Size is ", NUMBER_OF_STAGED_HOBBIES, size);
        assertFalse("Skill does not contain " + NUMBER_OF_STAGED_HOBBIES + " anymore ", hobbies.containsKey("3"));
  
        assertTrue("search for null key returned non-null value " + hobbies.get(null), hobbies.get(null) != null);
  
        hobbies.remove(null);
        size = hobbies.size();
        assertEquals("Size is ", NUMBER_OF_STAGED_HOBBIES - 1, size);
        assertFalse("Skill does not contain " + (NUMBER_OF_STAGED_HOBBIES - 1) + " ", hobbies.containsKey(null));
  
        hobbies.clear();
        size = hobbies.size();
        assertEquals("Size is ", 0, size);
  
        assertTrue("Should be empty", hobbies.isEmpty());
     }
  
     public void testPutAllEtc() throws Throwable
     {
        Map map = new HashMap();
        map.put("4", "pingpong");
        map.put("5", "handball");
  
        hobbies.putAll(map);
        int size = hobbies.size();
        assertEquals("Size is ", NUMBER_OF_STAGED_HOBBIES + 2, size);
  
        assertTrue("Key is ", hobbies.containsKey("4"));
  
        Set keys = hobbies.keySet();
        assertEquals("Key size ", NUMBER_OF_STAGED_HOBBIES + 2, keys.size());
  
        Set entries = hobbies.entrySet();
        assertEquals("Entry size ", NUMBER_OF_STAGED_HOBBIES + 2, entries.size());
  
     }
  
     public void testEntrySet() throws Throwable
     {
        System.out.println("Map " + hobbies.toString());
        for (Iterator i = hobbies.entrySet().iterator(); i.hasNext();)
        {
           Map.Entry entry = (Map.Entry) i.next();
           System.out.println("Entry key and value " + entry.getKey() + " " + entry.getValue());
        }
     }
  
     public void testValues() throws Throwable
     {
        System.out.println("Map " + hobbies.toString());
  
        Set correct = new HashSet();
        correct.add("golf");
        correct.add("tennis");
        correct.add("polo");
        correct.add("Non-null value but the key is null");
        correct.add(null);
  
        Collection values = hobbies.values();
        assertEquals("Correct number of elements in value collection",
                correct.size(), values.size());
  
        Iterator iter = null;
        for (iter = correct.iterator(); iter.hasNext();)
           assertTrue(values.contains(iter.next()));
  
        for (iter = values.iterator(); iter.hasNext();)
        {
           Object value = iter.next();
           assertTrue(value + " expected", correct.remove(value));
        }
        assertTrue("No missing elements from iterator", correct.size() == 0);
  
        iter.remove();
        assertTrue("2 elements left after remove via iter", values.size() == NUMBER_OF_STAGED_HOBBIES - 1);
        assertTrue("Iter removal reflected in map", hobbies.size() == NUMBER_OF_STAGED_HOBBIES - 1);
  
        Object[] data = values.toArray();
        assertTrue("2 elements in values array", data.length == NUMBER_OF_STAGED_HOBBIES - 1);
  
        values.remove(data[0]);
        assertTrue("1 element left after remove", values.size() == NUMBER_OF_STAGED_HOBBIES - 2);
        assertTrue("Removal reflected in map", hobbies.size() == NUMBER_OF_STAGED_HOBBIES - 2);
  
        values.clear();
        assertTrue("0 elements left after clear", values.size() == 0);
        assertTrue("Clear reflected in map", hobbies.size() == 0);
     }
  
     public void testContainsValue() throws Throwable
     {
        System.out.println("Map " + hobbies.toString());
        assertTrue("contains golf", hobbies.containsValue("golf"));
        assertTrue("contains tennis", hobbies.containsValue("tennis"));
        assertTrue("contains polo", hobbies.containsValue("polo"));
        assertFalse("does not contain squash", hobbies.containsValue("squash"));
     }
  
     public void testEquals() throws Throwable
     {
        Map map = new HashMap();
        map.put("1", "test");
        map.put("4", "test");
        map.put("2", "tennis");
        assertFalse("Map should not be the same ", map.equals(hobbies));
  
        map.clear();
        map.put("1", "golf");
        map.put("2", "tennis");
        map.put("3", "polo");
        map.put(null, "Non-null value but the key is null");
        map.put("key is non-null but value is null", null);
        assertTrue("Map should be the same ", map.equals(hobbies));
        assertTrue("Map should be the same, hobbies=" + hobbies.toString() + ", map=" + map.toString(), hobbies.equals(map));
        assertTrue("Map should be the same ", hobbies.equals(hobbies));
     }
  
     public void testAttachAndDetach() throws Exception
     {
        Map map = new HashMap();
        map.put("1", "English");
        map.put("2", "French");
        map.put("3", "Taiwanese");
  
        cache_.attach("/test", map); // attach
        map = (Map) cache_.find("/test");
        assertEquals("Size ", 3, map.size());
  
        map = (Map) cache_.detach("/test");  // detach
        assertEquals("Size ", 3, map.size());
  
        System.out.println("**** End of cache content **** ");
        map.remove("2");
        map.put("2", "Hoklo");
        assertEquals("Size ", 3, map.size());
        assertEquals("Content ", "Hoklo", map.get("2"));
  
        // Try to re-attach
        cache_.attach("/test", map);
        map.remove("3");
        assertEquals("Size ", 2, map.size());
     }
  
     public void testPojoAttachAndDetach() throws Exception
     {
        Address add1 = new Address();
        add1.setCity("San Jose");
        add1.setZip(95123);
  
        Address add2 = new Address();
        add1.setCity("Sunnyvale");
        add1.setZip(94086);
  
        Address add3 = new Address();
        add1.setCity("Santa Clara");
        add1.setZip(951131);
  
        Map map = new HashMap();
        map.put("1", add1);
        map.put("2", add2);
        map.put("3", add3);
  
        cache_.attach("/test", map); // attach
        map = (Map) cache_.find("/test");
        assertEquals("Size ", 3, map.size());
  
        map = (Map) cache_.detach("/test");
        assertEquals("Size ", 3, map.size());
  
        System.out.println("**** End of cache content **** ");
        map.remove("2");
        map.put("2", add2);
        assertEquals("Size ", 3, map.size());
        assertEquals("Content ", add2, map.get("2"));
  
        // Try to re-attach
        cache_.attach("/test", map);
        map.remove("2");
        assertEquals("Size ", 2, map.size());
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CachedMapNullTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/ObjectGraphTest.java
  
  Index: ObjectGraphTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.test.Address;
  import org.jboss.cache.pojo.test.Person;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  /**
   * Test object graph handling in aop, e.g., circular reference, multiple reference, link, etc.
   *
   * @author Ben Wang
   */
  
  public class ObjectGraphTest extends TestCase
  {
     Log log = LogFactory.getLog(ObjectGraphTest.class);
     PojoCache cache_;
  
     public ObjectGraphTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache_ = PojoCacheFactory.createCache(configFile, toStart);
        cache_.start();
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
  
  //   public void testDummy() {}
  
     protected Person createPerson(String name, int age)
     {
        Person p = new Person();
        p.setName(name);
        p.setAge(age);
        return p;
     }
  
  
     public void testListWithMultipleSharedObjccts() throws Exception
     {
        log.info("testListWithMultipleSharedObjects() ....");
        List list1 = new ArrayList();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        list1.add(addr);
  
        List list2 = new ArrayList();
        List list3 = new ArrayList();
        list2.add(addr);
        list3.add(addr);
  
        cache_.attach("/list1", list1);
        cache_.attach("/list2", list2);
        cache_.attach("/list3", list3);
  
        list3 = (List) cache_.find("/list3");
        assertTrue("List size should not be 0 ", (list3.size() != 0));
        assertEquals("Address ", addr.getZip(), ((Address) list3.get(0)).getZip());
        addr.setCity("Sunnyvale");
        assertEquals("Address ", addr.getCity(), ((Address) list3.get(0)).getCity());
  
        cache_.detach("/list1");
        cache_.detach("/list2");
        cache_.detach("/list3");
     }
  
     public void testRelationshipWithSharedList1() throws Exception
     {
        log.info("testRelationshipWithList() ....");
        List list1 = new ArrayList();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        list1.add(addr);
  
        cache_.attach("/list", list1);
        list1 = (List) cache_.find("/list");
        assertEquals("List size should be ", 1, list1.size());
        cache_.attach("/alias", list1);
  
        list1 = (List) cache_.find("/list");
        assertEquals("List size should be ", 1, list1.size());
        List list2 = (List) cache_.find("/alias");
  //      System.out.println(cache_.printDetails());
        assertEquals("List size should be ", 1, list2.size());
        assertEquals("Both lists should be equal ", list1, list2);
        assertEquals("Both list values should be equal ", list1.get(0), list2.get(0));
     }
  
     public void testRelationshipWithSharedList2() throws Exception
     {
        log.info("testRelationshipWithList2() ....");
        List list1 = new ArrayList();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        list1.add(addr);
  
        List list2 = new ArrayList();
        list2.add(addr);
  
        cache_.attach("/list1", list1);
        cache_.attach("/list2", list2);
        Address add2 = (Address) ((List) cache_.find("/list2")).get(0);
        Address add1 = (Address) ((List) cache_.find("/list1")).get(0);
        assertEquals("Address should be the same", add1, add2);
        assertEquals("Both shared object should be equal ", add2.getZip(), add1.getZip());
     }
  
     public void testListWithAttachAndDetach() throws Exception
     {
        log.info("testListWithAttachAndDetach() ....");
        List list1 = new ArrayList();
        Address addr1 = new Address();
        addr1.setCity("San Jose");
        addr1.setZip(95123);
  
        Address addr2 = new Address();
        addr2.setCity("Sunnyvale");
        addr2.setZip(94086);
        list1.add(addr2);
  
        cache_.attach("/list", list1);
        list1 = (List) cache_.find("/list");
        assertEquals("List size should be ", 1, list1.size());
        cache_.attach("/alias", list1);
  
        list1 = (List) cache_.find("/list");
        assertEquals("List size should be ", 1, list1.size());
        List list2 = (List) cache_.find("/alias");
  //      System.out.println(cache_.printDetails());
        assertEquals("List size should be ", 1, list2.size());
        assertEquals("Both lists should be equal ", list1, list2);
        assertEquals("Both list values should be equal ", list1.get(0), list2.get(0));
     }
  
     public void testRelationshipWithSharedSet1() throws Exception
     {
        log.info("testRelationshipWithSet() ....");
        Set set1 = new HashSet();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        set1.add(addr);
  
        // Pure set
        cache_.attach("/set", set1);
        // We specifically need to use Proxy otherwise it won't work with multiple references
        set1 = (Set) cache_.find("/set");
        cache_.attach("/alias", set1);
  
        set1 = (Set) cache_.find("/set");
        Set set2 = (Set) cache_.find("/alias");
        assertTrue("Set size should not be 0 ", (set2.size() != 0));
        assertEquals("Both sets should be equal ", set1, set2);
        Address add1 = (Address) set2.iterator().next();
        assertNotNull("Address should not be null", add1);
        assertEquals("Zip ", 95123, add1.getZip());
     }
  
     public void testRelationshipWithSharedSet2() throws Exception
     {
        log.info("testRelationshipWithSet2() ....");
        Set set1 = new HashSet();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        set1.add(addr);
  
        Set set2 = new HashSet();
        set2.add(addr);
  
        cache_.attach("/set1", set1);
        cache_.attach("/set2", set2);
  
        Address add2 = (Address) ((Set) cache_.find("/set2")).iterator().next();
        Address add1 = (Address) ((Set) cache_.find("/set1")).iterator().next();
        assertEquals("Address should be the same", add1, add2);
        assertEquals("Both shared object should be equal ", add2.getZip(), add1.getZip());
     }
  
     public void testRelationshipWithSharedMap1() throws Exception
     {
        log.info("testRelationshipWithMap() ....");
        Map map1 = new HashMap();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        map1.put("key1", addr);
  
        cache_.attach("/map", map1);
        cache_.attach("/alias", map1);
  
        map1 = (Map) cache_.find("/map");
        Map map2 = (Map) cache_.find("/alias");
        assertTrue("Map size should not be 0 ", (map2.size() != 0));
        assertEquals("Both maps should be equal ", map1, map2);
        Address add1 = (Address) ((Map.Entry) map2.entrySet().iterator().next()).getValue();
        assertNotNull("Address should not be null", add1);
        assertEquals("Zip ", 95123, add1.getZip());
     }
  
     public void testRelationshipWithSharedMap2() throws Exception
     {
        log.info("testRelationshipWithMap2() ....");
        Map map1 = new HashMap();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        map1.put("key1", addr);
  
        Map map2 = new HashMap();
        map2.put("key2", addr);
  
        // Pure map
        cache_.attach("/map", map1);
        cache_.attach("/alias", map2);
  
        map1 = (Map) cache_.find("/map");
        map2 = (Map) cache_.find("/alias");
        assertTrue("Map size should not be 0 ", (map2.size() != 0));
        Address add1 = (Address) ((Map.Entry) map2.entrySet().iterator().next()).getValue();
        assertNotNull("Address should not be null", add1);
        assertEquals("Zip ", 95123, add1.getZip());
     }
  
  
     public void testObjectIdentity() throws Exception
     {
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ObjectGraphTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/CachedMapTest.java
  
  Index: CachedMapTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.aop.proxy.ClassProxy;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.PojoCacheException;
  import org.jboss.cache.pojo.test.Address;
  
  import java.io.Serializable;
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  
  /**
   * Map interface testing.
   *
   * @author Ben Wang
   */
  
  public class CachedMapTest extends TestCase
  {
     Log log = LogFactory.getLog(CachedMapTest.class);
     PojoCache cache_;
     Map hobbies;
  
     public CachedMapTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache_ = PojoCacheFactory.createCache(configFile, toStart);
        cache_.start();
  
        stage();
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
  
     protected void stage() throws Exception
     {
        hobbies = new HashMap();
        hobbies.put("1", "golf");
        hobbies.put("2", "tennis");
        hobbies.put("3", "polo");
  
        cache_.attach("/person/test7", hobbies);
  
        hobbies = (Map) cache_.find("/person/test7");
        assertEquals("Map size", 3, hobbies.size());
  
        if (!(hobbies instanceof ClassProxy || hobbies instanceof Map))
        {
           fail("testPut(): hobbies is not instance of ClassProxy nor Map");
        }
     }
  
     /**
      * Test simple put
      *
      * @throws Throwable
      */
     public void testPut() throws Throwable
     {
        int size = hobbies.size();
        assertEquals("Size is ", 3, size);
  
        hobbies.put("6", "baseball");
        size = hobbies.size();
        assertEquals("Size is ", 4, size);
  
     }
  
     public void testAddAndRemoveIndex() throws Throwable
     {
        hobbies.put("4", "baseball");
        int size = hobbies.size();
        assertEquals("Size is ", 4, size);
  
        assertTrue("Skill contain Golf ", hobbies.containsKey("3"));
  
        hobbies.remove("3");
        size = hobbies.size();
        assertEquals("Size is ", 3, size);
        assertFalse("Skill does not contain 3 anymore ", hobbies.containsKey("3"));
  
        hobbies.clear();
        size = hobbies.size();
        assertEquals("Size is ", 0, size);
  
        assertTrue("Should be empty", hobbies.isEmpty());
     }
  
     public void testPutAllEtc() throws Throwable
     {
        Map map = new HashMap();
        map.put("4", "pingpong");
        map.put("5", "handball");
  
        hobbies.putAll(map);
        int size = hobbies.size();
        assertEquals("Size is ", 5, size);
  
        assertTrue("Key is ", hobbies.containsKey("4"));
  
        Set keys = hobbies.keySet();
        assertEquals("Key size ", 5, keys.size());
  
        Set entries = hobbies.entrySet();
        assertEquals("Entry size ", 5, entries.size());
  
     }
  
     public void testLongValue() throws Throwable
     {
        Long val = new Long("8225676592564383");
        Long val2 = 8225676592564383L;
        assertTrue(0 == val.compareTo(val2));   // sanity check
        hobbies.put(val, "prateek");
        assertTrue(hobbies.containsKey(val));
        assertTrue(hobbies.get(val).equals("prateek"));
     }
  
     public void testEntrySet() throws Throwable
     {
        System.out.println("Map " + hobbies.toString());
        for (Iterator i = hobbies.entrySet().iterator(); i.hasNext();)
        {
           Map.Entry entry = (Map.Entry) i.next();
           System.out.println("Entry key and value " + entry.getKey() + " " + entry.getValue());
        }
     }
  
     public void testValues() throws Throwable
     {
        System.out.println("Map " + hobbies.toString());
  
        Set correct = new HashSet();
        correct.add("golf");
        correct.add("tennis");
        correct.add("polo");
  
        Collection values = hobbies.values();
        assertEquals("Correct number of elements in value collection",
                correct.size(), values.size());
  
        Iterator iter = null;
        for (iter = correct.iterator(); iter.hasNext();)
           assertTrue(values.contains(iter.next()));
  
        for (iter = values.iterator(); iter.hasNext();)
        {
           Object value = iter.next();
           assertTrue(value + " expected", correct.remove(value));
        }
        assertTrue("No missing elements from iterator", correct.size() == 0);
  
        iter.remove();
        assertTrue("2 elements left after remove via iter", values.size() == 2);
        assertTrue("Iter removal reflected in map", hobbies.size() == 2);
  
        Object[] data = values.toArray();
        assertTrue("2 elements in values array", data.length == 2);
  
        values.remove(data[0]);
        assertTrue("1 element left after remove", values.size() == 1);
        assertTrue("Removal reflected in map", hobbies.size() == 1);
  
        values.clear();
        assertTrue("0 elements left after clear", values.size() == 0);
        assertTrue("Clear reflected in map", hobbies.size() == 0);
     }
  
     public void testContainsValue() throws Throwable
     {
        System.out.println("Map " + hobbies.toString());
        assertTrue("contains golf", hobbies.containsValue("golf"));
        assertTrue("contains tennis", hobbies.containsValue("tennis"));
        assertTrue("contains polo", hobbies.containsValue("polo"));
        assertFalse("does not contain squash", hobbies.containsValue("squash"));
     }
  
     public void testEquals1() throws Throwable
     {
        Map map = new HashMap();
        map.put("1", "test");
        map.put("4", "test");
        map.put("2", "tennis");
        assertFalse("Map should not be the same ", map.equals(hobbies));
     }
  
     public void testEquals2() throws Throwable
     {
        Map map1 = new HashMap();
        cache_.attach("map1", map1);
        map1 = (Map) cache_.find("map1");
        map1.put("1", "test");
  
        Map map2 = new HashMap();
        cache_.attach("map2", map2);
        map2 = (Map) cache_.find("map2");
        map2.put("1", "me");
  
        assertFalse("Map should not be the same ", map1.equals(map2));
     }
  
     public void testEquals3() throws Throwable
     {
        Map map1 = new HashMap();
        cache_.attach("map1", map1);
        map1 = (Map) cache_.find("map1");
        map1.put("1", "test");
        map1.put("2", "test");
  
        Map map2 = new HashMap();
        cache_.attach("map2", map2);
        map2 = (Map) cache_.find("map2");
        map2.put("1", "me");
        map2.put("2", "me");
  
        assertFalse("Map should not be the same ", map1.equals(map2));
     }
  
     public void testAttachAndDetach() throws Exception
     {
        Map map = new HashMap();
        map.put("1", "English");
        map.put("2", "French");
        map.put("3", "Taiwanese");
  
        cache_.attach("/test", map); // attach
        map = (Map) cache_.find("/test");
        assertEquals("Size ", 3, map.size());
  
        map = (Map) cache_.detach("/test");  // detach
        assertEquals("Size ", 3, map.size());
  
        System.out.println("**** End of cache content **** ");
        map.remove("2");
        map.put(2, "Hoklo");
        assertEquals("Size ", 3, map.size());
        assertEquals("Content ", "Hoklo", map.get(2));
  
        // Try to re-attach
        cache_.attach("/test", map);
        map.remove("3");
        assertEquals("Size ", 2, map.size());
     }
  
     public void testPojoAttachAndDetach() throws Exception
     {
        Address add1 = new Address();
        add1.setCity("San Jose");
        add1.setZip(95123);
  
        Address add2 = new Address();
        add2.setCity("Sunnyvale");
        add2.setZip(94086);
  
        Address add3 = new Address();
        add3.setCity("Santa Clara");
        add3.setZip(951131);
  
        Map map = new HashMap();
        map.put("1", add1);
        map.put("2", add2);
        map.put("3", add3);
  
        cache_.attach("/test", map); // attach
        map = (Map) cache_.find("/test");
        assertEquals("Size ", 3, map.size());
  
        map = (Map) cache_.detach("/test");
        assertEquals("Size ", 3, map.size());
  
        System.out.println("**** End of cache content **** ");
        map.remove("2");
        map.put("2", add2);
        assertEquals("Size ", 3, map.size());
        assertEquals("Content ", add2, map.get("2"));
  
        // Try to re-attach
        cache_.attach("/test", map);
        map.remove("2");
        assertEquals("Size ", 2, map.size());
     }
  
     public void testKeyAsObject() throws Exception
     {
        SerializableKeyValue key = new SerializableKeyValue(42, "Novell");
        Address add1 = new Address();
        add1.setCity("Waltham");
        add1.setStreet("404 Wyman Street");
        add1.setZip(02451);
  
        Map map = new HashMap();
        map.put(key, add1);
        cache_.attach("/keytest", map);
        Map ref = (Map) cache_.find("/keytest");
  
        Iterator iter = ref.keySet().iterator();
        assertTrue(iter.hasNext());
        Object keyFromMap = iter.next();
        assertEquals("original key is same as key in pojocache map, key class=" +
                key.getClass().getName() + ", keyFromMap class=" + keyFromMap.getClass().getName(),
                key, keyFromMap);
        assertEquals("local map is equal to pojocache map", map, ref);
     }
  
     public void testNonSerializableKeyAsObject() throws Exception
     {
        // negative test as we should get a java.io.NotSerializableException
        NotSerializableKeyValue key = new NotSerializableKeyValue(42, "Novell");
        Address add1 = new Address();
        add1.setCity("Waltham");
        add1.setStreet("404 Wyman Street");
        add1.setZip(02451);
  
        Map map = new HashMap();
        map.put(key, add1);
        try
        {
           cache_.attach("/keytest", map);  // this should throw RuntimeException with cause of java.io.NotSerializableException
           fail("failed to get expected runtimeException when adding nonserializable key to pojocache map");
        }
        catch (PojoCacheException e)
        {
           Throwable t = e;
  
           assertTrue("we got expected PojoCacheException "
                   + t.getCause().getClass().getName(), t.getCause() instanceof PojoCacheException);
        }
        map.clear();
        cache_.attach("/keytest", map);  // this should succeed
        Map ref = (Map) cache_.find("/keytest");
  
        // try adding nonserializable key to pojocache based map
        try
        {
           ref.put(key, add1);  // this should throw RuntimeException with cause of java.io.NotSerializableException
           fail("failed to get expected runtimeException when putting nonserializable key to pojocache map");
        }
        catch (RuntimeException e)
        {
           Throwable t = e;
  
           assertTrue("we got expected PojoCacheException "
                   + t.getClass().getName(), t instanceof PojoCacheException);
        }
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CachedMapTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
     static class SerializableKeyValue implements Serializable
     {
        Integer ivalue;
        String svalue;
  
        SerializableKeyValue(Integer ivalue, String svalue)
        {
           this.ivalue = ivalue;
           this.svalue = svalue;
        }
  
        public int hashCode()
        {
           return ivalue.hashCode() + svalue.hashCode();
        }
  
        public boolean equals(Object o)
        {
           if (o == this)
           {
              return true;
           }
           if (!(o instanceof SerializableKeyValue))
           {
              System.out.println("equals: not instanceof SerializableKeyValue , it is a " + o.getClass().getName());
              return false;
           }
           SerializableKeyValue val = (SerializableKeyValue) o;
           return val.ivalue == this.ivalue && val.svalue == this.svalue;
        }
     }
  
     static class NotSerializableKeyValue
     {
        Integer ivalue;
        String svalue;
  
        NotSerializableKeyValue(Integer ivalue, String svalue)
        {
           this.ivalue = ivalue;
           this.svalue = svalue;
        }
  
        public int hashCode()
        {
           return ivalue.hashCode() + svalue.hashCode();
        }
  
        public boolean equals(Object o)
        {
           if (o == this)
           {
              return true;
           }
           if (!(o instanceof SerializableKeyValue))
           {
              System.out.println("equals: not instanceof SerializableKeyValue , it is a " + o.getClass().getName());
              return false;
           }
           SerializableKeyValue val = (SerializableKeyValue) o;
           return val.ivalue == this.ivalue && val.svalue == this.svalue;
        }
     }
  
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/ReplicatedSyncSetTest.java
  
  Index: ReplicatedSyncSetTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.test.Address;
  import org.jboss.cache.pojo.test.Person;
  import org.jboss.cache.Fqn;
  
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Set;
  
  /**
   * Test object graph handling in aop, e.g., circular reference, multiple reference, link, etc.
   *
   * @author Ben Wang
   */
  
  public class ReplicatedSyncSetTest extends TestCase
  {
     Log log = LogFactory.getLog(ReplicatedSyncSetTest.class);
     PojoCache cache1;
     PojoCache cache2;
  
     public ReplicatedSyncSetTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        cache1 = createCache("CacheGroup");
        cache2 = createCache("CacheGroup");
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache1.getCache().removeNode(Fqn.fromString("/"));
        cache1.stop();
        cache2.stop();
     }
  
     private PojoCache createCache(String name) throws Exception
     {
        boolean toStart = false;
        PojoCache cache = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
        cache.start();
        return cache;
     }
  
  //   public void testDummy() {}
  
  
     protected Person createPerson(String name, int age)
     {
        Person p = new Person();
        p.setName(name);
        p.setAge(age);
        return p;
     }
  
     /**
      * Test attachment and then detachment and attachment.
      *
      * @throws Exception
      */
     public void testAttachDetach() throws Exception
     {
        log.info("testAttachDetach() ....");
        Set set1 = new HashSet();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        set1.add(addr);
  
        Address addr2 = new Address();
        addr2.setCity("Santa Clara");
        addr2.setZip(95131);
  
        Address addr3 = new Address();
        addr3.setCity("Sunnyvale");
        addr3.setZip(94086);
  
        // Pure list
        cache1.attach("/set", set1);
        set1 = (Set) cache1.find("/set");
        set1.add(addr2);
        set1 = (Set)cache1.detach("/set");
        assertEquals("Detached set should still be", 2, set1.size());
        set1.add(addr3);
        cache1.attach("/set", set1);
  
        Set set2 = (Set) cache2.find("/set");
        assertEquals("Set size should be ", 3, set2.size());
     }
  
     public void testRelationshipWithSharedSet1() throws Exception
     {
        log.info("testRelationshipWithSet() ....");
        Set set1 = new HashSet();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        set1.add(addr);
  
        // Pure set
        cache1.attach("/set", set1);
        // We specifically need to use Proxy otherwise it won't work with multiple references
        set1 = (Set) cache1.find("/set");
        cache1.attach("/alias", set1);
  
        Set set2 = (Set) cache1.find("/alias");
        Address add1 = (Address) set2.iterator().next();
        assertNotNull("Address should not be null", add1);
        assertEquals("Zip ", 95123, add1.getZip());
  
        set1 = (Set) cache2.find("/set");
        set2 = (Set) cache2.find("/alias");
        assertTrue("Set size should not be 0 ", (set2.size() != 0));
        assertEquals("Both sets should be equal ", set1, set2);
        add1 = (Address) set2.iterator().next();
        assertNotNull("Address should not be null", add1);
        assertEquals("Zip ", 95123, add1.getZip());
     }
  
     public void testRelationshipWithSharedSet2() throws Exception
     {
        log.info("testRelationshipWithSet2() ....");
        Set set1 = new HashSet();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        set1.add(addr);
  
        Set set2 = new HashSet();
        set2.add(addr);
  
        cache1.attach("/set1", set1);
        cache1.attach("/set2", set2);
        Address add2 = (Address) ((Set) cache2.find("/set2")).iterator().next();
        Address add1 = (Address) ((Set) cache2.find("/set1")).iterator().next();
        assertEquals("Address should be the same", add1, add2);
        assertEquals("Both shared object should be equal ", add2.getZip(), add1.getZip());
     }
  
     public void testNullWithSharedSet1() throws Exception
     {
        log.info("testNullWithSharedSet1() ....");
        Set set1 = new HashSet();
        set1.add("element 0");
        set1.add(null);  // element 1
        set1.add("element 2");
        assertTrue("contains test for null value", set1.contains(null));
        Object a1[] = set1.toArray();
        for (int looper = 0; looper < a1.length; looper++)
        {
           System.out.println("contained values:" + a1[looper]);
        }
  
        // Pure set
        cache1.attach("/set", set1);
        // We specifically need to use Proxy otherwise it won't work with multiple references
        set1 = (Set) cache1.find("/set");
        cache1.attach("/alias", set1);
  
        Set set2 = (Set) cache1.find("/alias");
  
        set1 = (Set) cache2.find("/set");
        set2 = (Set) cache2.find("/alias");
        assertTrue("Set size should not be 0 ", (set2.size() != 0));
        assertEquals("Both sets should be equal ", set1, set2);
  
        a1 = set1.toArray();
        for (int looper = 0; looper < a1.length; looper++)
        {
           System.out.println("contained values:" + a1[looper]);
        }
        assertTrue("contains test for null value", set1.contains(null));
        assertTrue("contains test for null value", set2.contains(null));
  
        Iterator iter = set1.iterator();
        while (iter.hasNext())
        {
           Object val = iter.next();
           if ("element 2".equals(val))
           {
              iter.remove();  // remove element 2
           }
        }
        assertFalse("element 2 is removed", set2.contains("element 2"));
     }
  
  
     /* This test won't pass since the recursive set will fail during replication as well
     because of HashSet that calls out to HashMap hashCode. This causes the recursion.
     public void testRecursion2() throws Exception
     {
        Set set = new HashSet();
        set.add("1");
        set.add("2");
        set.add(set);
  
        cache1.attach("set", set);
     }
     */
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ReplicatedSyncSetTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/CachedListTxTest.java
  
  Index: CachedListTxTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  
  /**
   * List interface testing with transaction control.
   *
   * @author Scott Marlow
   */
  
  public class CachedListTxTest extends TestCase
  {
     Log log = LogFactory.getLog(CachedListTxTest.class);
     PojoCache cache_;
  
  
     public CachedListTxTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        String configFile = "META-INF/cache-config.xml";
        boolean toStart = false;
        cache_ = PojoCacheFactory.createCache(configFile, toStart);
        cache_.start();
  
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
  
     public void testDummy()
     {
        // No op now.
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(CachedListTxTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  
  
  
  1.1      date: 2007/01/13 15:55:00;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/collection/ReplicatedSyncMapTest.java
  
  Index: ReplicatedSyncMapTest.java
  ===================================================================
  package org.jboss.cache.pojo.collection;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.PojoCacheException;
  import org.jboss.cache.pojo.test.Address;
  import org.jboss.cache.pojo.test.Person;
  import org.jboss.cache.Fqn;
  import org.jboss.aop.proxy.ClassProxy;
  
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  
  /**
   * Test replicated Map
   *
   * @author Ben Wang
   * @author Scott Marlow
   */
  
  public class ReplicatedSyncMapTest extends TestCase
  {
     Log log = LogFactory.getLog(ReplicatedSyncMapTest.class);
     PojoCache cache1;
     PojoCache cache2;
  
     public ReplicatedSyncMapTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log.info("setUp() ....");
        cache1 = createCache("CacheGroup");
        cache2 = createCache("CacheGroup");
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache1.getCache().removeNode(Fqn.fromString("/"));
        cache1.stop();
        cache2.stop();
     }
  
     private PojoCache createCache(String name) throws Exception
     {
        boolean toStart = false;
        PojoCache cache = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
        cache.start();
        return cache;
     }
  
  //   public void testDummy() {}
  
  
     protected Person createPerson(String name, int age)
     {
        Person p = new Person();
        p.setName(name);
        p.setAge(age);
        return p;
     }
  
  
     /**
      * Test attachment and then detachment and attachment.
      *
      * @throws Exception
      */
     public void testAttachDetach() throws Exception
     {
        log.info("testAttachDetach() ....");
        Map map1 = new HashMap();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        map1.put("key1", addr);
  
        Address addr2 = new Address();
        addr2.setCity("Santa Clara");
        addr2.setZip(95131);
  
        Address addr3 = new Address();
        addr2.setCity("Sunnyvale");
        addr3.setZip(94086);
  
        // Pure list
        cache1.attach("/map", map1);
        map1 = (Map) cache1.find("/map");
        map1.put("key2", addr2);
        map1 = (Map)cache1.detach("/map");
        assertEquals("Detached map should still be", 2, map1.size());
        map1.put("key3", addr3);
        cache1.attach("/map", map1);
  
        Map map2 = (Map) cache2.find("/map");
        assertEquals("Map size should be ", 3, map2.size());
     }
  
     public void testRelationshipWithSharedMap1() throws Exception
     {
        log.info("testRelationshipWithMap() ....");
        Map map1 = new HashMap();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        map1.put("key1", addr);
  
        // Pure set
        cache1.attach("/map", map1);
        // We specifically need to use Proxy otherwise it won't work with multiple references
        map1 = (Map) cache1.find("/map");
        cache1.attach("/alias", map1);
  
        Map map2 = (Map) cache1.find("/alias");
        Address add1 = (Address) ((Map.Entry) map2.entrySet().iterator().next()).getValue();
        assertNotNull("Address should not be null", add1);
        assertEquals("Zip ", 95123, add1.getZip());
  
        map1 = (Map) cache2.find("/map");
        map2 = (Map) cache2.find("/alias");
        assertTrue("Map size should not be 0 ", (map2.size() != 0));
        assertEquals("Both maps should be equal ", map1, map2);
        add1 = (Address) ((Map.Entry) map2.entrySet().iterator().next()).getValue();
        assertNotNull("Address should not be null", add1);
        assertEquals("Zip ", 95123, add1.getZip());
     }
  
     public void testNullWithSharedMap1() throws Exception
     {
        log.info("testNullWithSharedMap1() ....");
        Map map1 = new HashMap();
        map1.put("null value test", null);
        map1.put(null, "null key test");
  
        // Pure set
        cache1.attach("/map", map1);
        // We specifically need to use Proxy otherwise it won't work with multiple references
        map1 = (Map) cache1.find("/map");
        cache1.attach("/alias", map1);
  
        Map map2 = (Map) cache1.find("/alias");
  
        map1 = (Map) cache2.find("/map");
        map2 = (Map) cache2.find("/alias");
        assertTrue("Map size should not be 0 ", (map2.size() != 0));
        assertEquals("Both maps should be equal ", map1, map2);
  
        assertTrue("Get null key returns non-null value", map2.get(null) != null);
        assertTrue("Get null key returns correct value", map2.get(null).equals("null key test"));
  
        assertTrue("Get null value returns null value", map2.get("null value test") == null);
        assertTrue("containsKey test for null value", map2.containsKey("null value test"));
        assertTrue("containsKey test for null key", map2.containsKey(null));
        assertTrue("containsValue test for null value", map2.containsValue(null));
  
        assertTrue("values (positive) null test", map2.values().contains(null));
        Collection walk = map1.values();
  
        assertTrue(walk.remove(null));
        assertFalse("values (negative) null test", map2.values().contains(null));
  
        assertTrue("values (positive) null test", map2.values().contains("null key test"));
        assertTrue(walk.remove("null key test"));
        assertFalse("values (negative) null test", map2.values().contains("null key test"));
  
        map1.put("null value test", null);
        map1.put(null, "null key test");
  
  
        assertTrue("remove null item test", map1.remove(null).equals("null key test"));
        assertFalse("null item removed", map2.containsKey(null));
  
  
     }
  
     public void testRelationshipWithSharedMap2() throws Exception
     {
        log.info("testRelationshipWithMap2() ....");
        Map map1 = new HashMap();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        map1.put("key1", addr);
  
        Map map2 = new HashMap();
        map2.put("key2", addr);
  
        cache2.attach("/map1", map1);
        cache2.attach("/map2", map2);
  
        map1 = (Map) cache2.find("/map1");
        map2 = (Map) cache2.find("/map2");
        assertTrue("Map size should not be 0 ", (map2.size() != 0));
        assertEquals("Both maps should be equal ", map1.get("key1"), map2.get("key2"));
        Address add1 = (Address) ((Map.Entry) map2.entrySet().iterator().next()).getValue();
        assertNotNull("Address should not be null", add1);
        assertEquals("Zip ", 95123, add1.getZip());
     }
  
     public void testKeySetRemoveWithSharedMap1() throws Exception
     {
        log.info("testKeySetRemoveWithSharedMap1() ....");
        Map map1 = new HashMap();
        Address addr = new Address();
        addr.setCity("San Jose");
        addr.setZip(95123);
        map1.put("key1_map1", addr);
        map1.put("key2_map1", null);
        map1.put(null, "null value test");
        Map map2 = new HashMap();
        map2.put("key1_map2", addr);
        map2.put("key2_map2", "round");
  
        assertTrue("key1 exists", map1.containsKey("key1_map1"));
  
  
        cache2.attach("/map1", map1);
        cache2.attach("/map2", map2);
  
        map1 = (Map) cache1.find("/map1");
        map2 = (Map) cache1.find("/map2");
  
        assertTrue("key1 exists", map1.containsKey("key1_map1"));
        assertTrue("null key exists", map1.containsKey(null));
        assertTrue("key2 exists", map1.containsKey("key2_map1"));
  
        Set set = map1.keySet();
        Iterator iter = set.iterator();
        while (iter.hasNext())
        {
           Object o = iter.next();
           System.out.println("testKeySetRemoveWithSharedMap1 iter.next returned: " + o);
  
           if (o == null || "key1_map1".equals(o))
              iter.remove();
        }
        assertTrue("key2 exists", map1.containsKey("key2_map1"));
        assertFalse("key1 doesn't exist", map1.containsKey("key1_map1"));
        assertFalse("null key doesn't exist", map1.containsKey(null));
  
        map1 = (Map) cache2.find("/map1");
        map2 = (Map) cache2.find("/map2");
  
        assertTrue("key2 exists", map1.containsKey("key2_map1"));
        assertFalse("key1 doesn't exist", map1.containsKey("key1_map1"));
        assertFalse("null key doesn't exist", map1.containsKey(null));
  
     }
  
     public void testRecursion1() throws Exception
     {
        Map map = new HashMap();
        map.put("1", "1");
        map.put("2", "2");
        cache1.attach("map", map);
  
        map = (Map)cache1.find("map");
        map.put("map", map);
  
        assertEquals("size ", 3, map.size());
        Map m2 = (Map)map.get("map");
        assertTrue("Instance of AopProxy", m2 instanceof ClassProxy);
  //      assertEquals("ClassProxy instance", list, l2);
     }
  
     public void XtestRecursion2() throws Exception
     {
        Map map = new HashMap();
        map.put("1", "1");
        map.put("2", "2");
        map.put("map", map);
  
        try
        {
           cache1.attach("map", map);
        } catch (PojoCacheException pex)
        {
           // Expected, we can't do recursive map.
           pex.printStackTrace();
        }
  
        fail("Test should fail since we can't handle recursive map");
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ReplicatedSyncMapTest.class);
     }
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  
  



More information about the jboss-cvs-commits mailing list