Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 268   Methods: 15
NCLOC: 212   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ObjectGraphTest.java - 96.6% 86.7% 95.7%
coverage coverage
 1    package org.jboss.cache.pojo.collection;
 2   
 3    import junit.framework.Test;
 4    import junit.framework.TestCase;
 5    import junit.framework.TestSuite;
 6    import org.apache.commons.logging.Log;
 7    import org.apache.commons.logging.LogFactory;
 8    import org.jboss.cache.pojo.PojoCache;
 9    import org.jboss.cache.pojo.PojoCacheFactory;
 10    import org.jboss.cache.pojo.test.Address;
 11    import org.jboss.cache.pojo.test.Person;
 12   
 13    import java.util.ArrayList;
 14    import java.util.HashMap;
 15    import java.util.HashSet;
 16    import java.util.List;
 17    import java.util.Map;
 18    import java.util.Set;
 19   
 20    /**
 21    * Test object graph handling in aop, e.g., circular reference, multiple reference, link, etc.
 22    *
 23    * @author Ben Wang
 24    */
 25   
 26    public class ObjectGraphTest extends TestCase
 27    {
 28    Log log = LogFactory.getLog(ObjectGraphTest.class);
 29    PojoCache cache_;
 30   
 31  9 public ObjectGraphTest(String name)
 32    {
 33  9 super(name);
 34    }
 35   
 36  9 protected void setUp() throws Exception
 37    {
 38  9 super.setUp();
 39  9 log.info("setUp() ....");
 40  9 String configFile = "META-INF/local-service.xml";
 41  9 boolean toStart = false;
 42  9 cache_ = PojoCacheFactory.createCache(configFile, toStart);
 43  9 cache_.start();
 44    }
 45   
 46  9 protected void tearDown() throws Exception
 47    {
 48  9 super.tearDown();
 49  9 cache_.stop();
 50    }
 51   
 52    // public void testDummy() {}
 53   
 54  0 protected Person createPerson(String name, int age)
 55    {
 56  0 Person p = new Person();
 57  0 p.setName(name);
 58  0 p.setAge(age);
 59  0 return p;
 60    }
 61   
 62   
 63  1 public void testListWithMultipleSharedObjccts() throws Exception
 64    {
 65  1 log.info("testListWithMultipleSharedObjects() ....");
 66  1 List list1 = new ArrayList();
 67  1 Address addr = new Address();
 68  1 addr.setCity("San Jose");
 69  1 addr.setZip(95123);
 70  1 list1.add(addr);
 71   
 72  1 List list2 = new ArrayList();
 73  1 List list3 = new ArrayList();
 74  1 list2.add(addr);
 75  1 list3.add(addr);
 76   
 77  1 cache_.attach("/list1", list1);
 78  1 cache_.attach("/list2", list2);
 79  1 cache_.attach("/list3", list3);
 80   
 81  1 list3 = (List) cache_.find("/list3");
 82  1 assertTrue("List size should not be 0 ", (list3.size() != 0));
 83  1 assertEquals("Address ", addr.getZip(), ((Address) list3.get(0)).getZip());
 84  1 addr.setCity("Sunnyvale");
 85  1 assertEquals("Address ", addr.getCity(), ((Address) list3.get(0)).getCity());
 86   
 87  1 cache_.detach("/list1");
 88  1 cache_.detach("/list2");
 89  1 cache_.detach("/list3");
 90    }
 91   
 92  1 public void testRelationshipWithSharedList1() throws Exception
 93    {
 94  1 log.info("testRelationshipWithList() ....");
 95  1 List list1 = new ArrayList();
 96  1 Address addr = new Address();
 97  1 addr.setCity("San Jose");
 98  1 addr.setZip(95123);
 99  1 list1.add(addr);
 100   
 101  1 cache_.attach("/list", list1);
 102  1 list1 = (List) cache_.find("/list");
 103  1 assertEquals("List size should be ", 1, list1.size());
 104  1 cache_.attach("/alias", list1);
 105   
 106  1 list1 = (List) cache_.find("/list");
 107  1 assertEquals("List size should be ", 1, list1.size());
 108  1 List list2 = (List) cache_.find("/alias");
 109    // System.out.println(cache_.printDetails());
 110  1 assertEquals("List size should be ", 1, list2.size());
 111  1 assertEquals("Both lists should be equal ", list1, list2);
 112  1 assertEquals("Both list values should be equal ", list1.get(0), list2.get(0));
 113    }
 114   
 115  1 public void testRelationshipWithSharedList2() throws Exception
 116    {
 117  1 log.info("testRelationshipWithList2() ....");
 118  1 List list1 = new ArrayList();
 119  1 Address addr = new Address();
 120  1 addr.setCity("San Jose");
 121  1 addr.setZip(95123);
 122  1 list1.add(addr);
 123   
 124  1 List list2 = new ArrayList();
 125  1 list2.add(addr);
 126   
 127  1 cache_.attach("/list1", list1);
 128  1 cache_.attach("/list2", list2);
 129  1 Address add2 = (Address) ((List) cache_.find("/list2")).get(0);
 130  1 Address add1 = (Address) ((List) cache_.find("/list1")).get(0);
 131  1 assertEquals("Address should be the same", add1, add2);
 132  1 assertEquals("Both shared object should be equal ", add2.getZip(), add1.getZip());
 133    }
 134   
 135  1 public void testListWithAttachAndDetach() throws Exception
 136    {
 137  1 log.info("testListWithAttachAndDetach() ....");
 138  1 List list1 = new ArrayList();
 139  1 Address addr1 = new Address();
 140  1 addr1.setCity("San Jose");
 141  1 addr1.setZip(95123);
 142   
 143  1 Address addr2 = new Address();
 144  1 addr2.setCity("Sunnyvale");
 145  1 addr2.setZip(94086);
 146  1 list1.add(addr2);
 147   
 148  1 cache_.attach("/list", list1);
 149  1 list1 = (List) cache_.find("/list");
 150  1 assertEquals("List size should be ", 1, list1.size());
 151  1 cache_.attach("/alias", list1);
 152   
 153  1 list1 = (List) cache_.find("/list");
 154  1 assertEquals("List size should be ", 1, list1.size());
 155  1 List list2 = (List) cache_.find("/alias");
 156    // System.out.println(cache_.printDetails());
 157  1 assertEquals("List size should be ", 1, list2.size());
 158  1 assertEquals("Both lists should be equal ", list1, list2);
 159  1 assertEquals("Both list values should be equal ", list1.get(0), list2.get(0));
 160    }
 161   
 162  1 public void testRelationshipWithSharedSet1() throws Exception
 163    {
 164  1 log.info("testRelationshipWithSet() ....");
 165  1 Set set1 = new HashSet();
 166  1 Address addr = new Address();
 167  1 addr.setCity("San Jose");
 168  1 addr.setZip(95123);
 169  1 set1.add(addr);
 170   
 171    // Pure set
 172  1 cache_.attach("/set", set1);
 173    // We specifically need to use Proxy otherwise it won't work with multiple references
 174  1 set1 = (Set) cache_.find("/set");
 175  1 cache_.attach("/alias", set1);
 176   
 177  1 set1 = (Set) cache_.find("/set");
 178  1 Set set2 = (Set) cache_.find("/alias");
 179  1 assertTrue("Set size should not be 0 ", (set2.size() != 0));
 180  1 assertEquals("Both sets should be equal ", set1, set2);
 181  1 Address add1 = (Address) set2.iterator().next();
 182  1 assertNotNull("Address should not be null", add1);
 183  1 assertEquals("Zip ", 95123, add1.getZip());
 184    }
 185   
 186  1 public void testRelationshipWithSharedSet2() throws Exception
 187    {
 188  1 log.info("testRelationshipWithSet2() ....");
 189  1 Set set1 = new HashSet();
 190  1 Address addr = new Address();
 191  1 addr.setCity("San Jose");
 192  1 addr.setZip(95123);
 193  1 set1.add(addr);
 194   
 195  1 Set set2 = new HashSet();
 196  1 set2.add(addr);
 197   
 198  1 cache_.attach("/set1", set1);
 199  1 cache_.attach("/set2", set2);
 200   
 201  1 Address add2 = (Address) ((Set) cache_.find("/set2")).iterator().next();
 202  1 Address add1 = (Address) ((Set) cache_.find("/set1")).iterator().next();
 203  1 assertEquals("Address should be the same", add1, add2);
 204  1 assertEquals("Both shared object should be equal ", add2.getZip(), add1.getZip());
 205    }
 206   
 207  1 public void testRelationshipWithSharedMap1() throws Exception
 208    {
 209  1 log.info("testRelationshipWithMap() ....");
 210  1 Map map1 = new HashMap();
 211  1 Address addr = new Address();
 212  1 addr.setCity("San Jose");
 213  1 addr.setZip(95123);
 214  1 map1.put("key1", addr);
 215   
 216  1 cache_.attach("/map", map1);
 217  1 cache_.attach("/alias", map1);
 218   
 219  1 map1 = (Map) cache_.find("/map");
 220  1 Map map2 = (Map) cache_.find("/alias");
 221  1 assertTrue("Map size should not be 0 ", (map2.size() != 0));
 222  1 assertEquals("Both maps should be equal ", map1, map2);
 223  1 Address add1 = (Address) ((Map.Entry) map2.entrySet().iterator().next()).getValue();
 224  1 assertNotNull("Address should not be null", add1);
 225  1 assertEquals("Zip ", 95123, add1.getZip());
 226    }
 227   
 228  1 public void testRelationshipWithSharedMap2() throws Exception
 229    {
 230  1 log.info("testRelationshipWithMap2() ....");
 231  1 Map map1 = new HashMap();
 232  1 Address addr = new Address();
 233  1 addr.setCity("San Jose");
 234  1 addr.setZip(95123);
 235  1 map1.put("key1", addr);
 236   
 237  1 Map map2 = new HashMap();
 238  1 map2.put("key2", addr);
 239   
 240    // Pure map
 241  1 cache_.attach("/map", map1);
 242  1 cache_.attach("/alias", map2);
 243   
 244  1 map1 = (Map) cache_.find("/map");
 245  1 map2 = (Map) cache_.find("/alias");
 246  1 assertTrue("Map size should not be 0 ", (map2.size() != 0));
 247  1 Address add1 = (Address) ((Map.Entry) map2.entrySet().iterator().next()).getValue();
 248  1 assertNotNull("Address should not be null", add1);
 249  1 assertEquals("Zip ", 95123, add1.getZip());
 250    }
 251   
 252   
 253  1 public void testObjectIdentity() throws Exception
 254    {
 255    }
 256   
 257  1 public static Test suite() throws Exception
 258    {
 259  1 return new TestSuite(ObjectGraphTest.class);
 260    }
 261   
 262  0 public static void main(String[] args) throws Exception
 263    {
 264  0 junit.textui.TestRunner.run(suite());
 265    }
 266   
 267    }
 268