Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 225   Methods: 12
NCLOC: 181   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NewLocalTest.java - 87.2% 83.3% 86.8%
coverage coverage
 1    package org.jboss.cache.pojo;
 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.aop.proxy.ClassProxy;
 9    import org.jboss.cache.Fqn;
 10    import org.jboss.cache.pojo.test.Person;
 11   
 12    import java.util.ArrayList;
 13    import java.util.HashMap;
 14    import java.util.HashSet;
 15    import java.util.Map;
 16   
 17    /**
 18    * Additional basic tests
 19    *
 20    * @author Ben Wang
 21    */
 22   
 23    public class NewLocalTest extends TestCase
 24    {
 25    Log log_ = LogFactory.getLog(NewLocalTest.class);
 26    PojoCache cache_;
 27   
 28  12 public NewLocalTest(String name)
 29    {
 30  12 super(name);
 31    }
 32   
 33  12 protected void setUp() throws Exception
 34    {
 35  12 super.setUp();
 36  12 log_.info("setUp() ....");
 37  12 String configFile = "META-INF/local-service.xml";
 38  12 boolean toStart = false;
 39  12 cache_ = PojoCacheFactory.createCache(configFile, toStart);
 40  12 cache_.start();
 41    }
 42   
 43  12 protected void tearDown() throws Exception
 44    {
 45  12 super.tearDown();
 46  12 cache_.stop();
 47    }
 48   
 49    // public void testDummy() {}
 50   
 51  0 public void XtestBadFqn() throws Exception
 52    {
 53  0 log_.info("testBadFqn() ....");
 54  0 Person test = new Person();
 55  0 test.setName("Ben");
 56  0 test.setAge(10);
 57  0 cache_.attach("/a", test);
 58  0 Person result = (Person) cache_.detach("/a");
 59  0 assertEquals(" ", test, result);
 60  0 result.setAge(20);
 61   
 62  0 try
 63    {
 64  0 cache_.attach(InternalConstant.JBOSS_INTERNAL_STRING, test);
 65  0 fail("putObject under JBoss_Internal should fail");
 66    }
 67    catch (IllegalArgumentException iex)
 68    {
 69    // ok
 70    }
 71   
 72  0 try
 73    {
 74  0 cache_.detach(InternalConstant.JBOSS_INTERNAL_STRING);
 75  0 fail("putObject under JBoss_Internal should fail");
 76    }
 77    catch (IllegalArgumentException iex)
 78    {
 79    // ok
 80    }
 81    }
 82   
 83  2 public void testPutRemove() throws Exception
 84    {
 85  2 log_.info("testPutRemove() ....");
 86  2 Person test = new Person();
 87  2 test.setName("Ben");
 88  2 test.setAge(10);
 89  2 cache_.attach("/a", test);
 90  2 Person result = (Person) cache_.find("/a");
 91  2 assertEquals(" ", test, result);
 92  2 result.setAge(20);
 93  2 cache_.detach("/a");
 94  2 assertNull("Object should be null ", cache_.find("/a"));
 95  2 assertEquals("Age should be updated as ", 20, test.getAge());
 96    }
 97   
 98  2 public void testPutRemoveNodeExistence() throws Exception
 99    {
 100  2 log_.info("testPutRemove() ....");
 101  2 Person test = new Person();
 102  2 test.setName("Ben");
 103  2 test.setAge(10);
 104  2 cache_.attach("person", test);
 105  2 Person result = (Person) cache_.find("person");
 106  2 assertEquals(" ", test, result);
 107  2 result.setAge(20);
 108  2 cache_.detach("person");
 109  2 assertNull("Object should be null ", cache_.find("person"));
 110  2 assertEquals("Age should be updated as ", 20, test.getAge());
 111   
 112  2 assertNull("DataNode should not exisit ", cache_.getCache().getRoot().getChild(Fqn.fromString("person")));
 113    }
 114   
 115  2 public void testRemoveProxyList() throws Exception
 116    {
 117  2 log_.info("testRemoveProxyList() ....");
 118  2 Person test = new Person();
 119  2 test.setName("Ben");
 120  2 test.setAge(10);
 121  2 ArrayList list = new ArrayList();
 122  2 list.add("English");
 123  2 list.add("Taiwanese");
 124  2 test.setLanguages(list);
 125  2 cache_.attach("/a", test);
 126  2 Person result = (Person) cache_.find("/a");
 127  2 assertEquals(" ", test, result);
 128   
 129  2 assertTrue("Instance of proxyclass ", result.getLanguages() instanceof ClassProxy);
 130   
 131  2 Person r1 = (Person) cache_.detach("/a");
 132   
 133  2 assertEquals("Same instance ", result, r1);
 134  2 assertFalse("Instance of proxyclass ", result.getLanguages() instanceof ClassProxy);
 135  2 assertEquals("Same Collection instance", list, result.getLanguages());
 136    }
 137   
 138  2 public void testRemoveProxySet() throws Exception
 139    {
 140  2 log_.info("testRemoveProxySet() ....");
 141  2 Person test = new Person();
 142  2 test.setName("Ben");
 143  2 test.setAge(10);
 144  2 HashSet set = new HashSet();
 145  2 set.add("Golf");
 146  2 set.add("Cooking");
 147  2 test.setSkills(set);
 148  2 cache_.attach("/a", test);
 149  2 Person result = (Person) cache_.find("/a");
 150  2 assertEquals(" ", test, result);
 151   
 152  2 assertTrue("Instance of proxyclass ", result.getSkills() instanceof ClassProxy);
 153   
 154  2 Person r1 = (Person) cache_.detach("/a");
 155   
 156  2 assertEquals("Same instance ", result, r1);
 157  2 assertFalse("Instance of proxyclass ", result.getSkills() instanceof ClassProxy);
 158  2 assertEquals("Same Collection instance", set, result.getSkills());
 159    }
 160   
 161  2 public void testRemoveProxyMap() throws Exception
 162    {
 163  2 log_.info("testRemoveProxyMap() ....");
 164  2 Person test = new Person();
 165  2 test.setName("Ben");
 166  2 test.setAge(10);
 167   
 168  2 HashMap map = new HashMap();
 169  2 map.put("1", "Golf");
 170  2 map.put("2", "Surfing");
 171  2 test.setHobbies(map);
 172   
 173  2 cache_.attach("/a", test);
 174  2 Person result = (Person) cache_.find("/a");
 175  2 assertEquals(" ", test, result);
 176   
 177  2 assertTrue("Instance of proxyclass ", result.getHobbies() instanceof ClassProxy);
 178   
 179  2 Person r1 = (Person) cache_.detach("/a");
 180   
 181  2 assertEquals("Same instance ", result, r1);
 182  2 assertFalse("Instance of proxyclass ", result.getHobbies() instanceof ClassProxy);
 183  2 assertEquals("Same Collection instance", map, result.getHobbies());
 184    }
 185   
 186  2 public void testFindObjects() throws Exception
 187    {
 188  2 log_.info("testFindObjects() ....");
 189  2 Map map = cache_.findAll("/");
 190  2 assertEquals("Objects size should be ", 0, map.size());
 191  2 Person ben = new Person();
 192  2 ben.setName("Ben");
 193  2 ben.setAge(10);
 194  2 cache_.attach("/a/b/c", ben);
 195  2 cache_.attach("/e", ben); // multiple keys, same pojo
 196  2 Person joe = new Person();
 197  2 joe.setName("Joe");
 198  2 joe.setAge(10);
 199  2 cache_.attach("/f/joe", joe);
 200  2 map = cache_.findAll("/");
 201  2 assertEquals("Objects size should be ", 3, map.size());
 202   
 203  2 map = cache_.findAll("/a");
 204  2 assertEquals("Objects size should be ", 1, map.size());
 205  2 cache_.detach("/e");
 206  2 map = cache_.findAll("/");
 207  2 assertEquals("Objects size should be ", 2, map.size());
 208   
 209  2 map = cache_.findAll(null); // should everything.
 210  2 assertEquals("Objects size should be ", 2, map.size());
 211    }
 212   
 213  2 public static Test suite() throws Exception
 214    {
 215  2 return new TestSuite(NewLocalTest.class);
 216    }
 217   
 218   
 219  0 public static void main(String[] args) throws Exception
 220    {
 221  0 junit.textui.TestRunner.run(suite());
 222    }
 223   
 224    }
 225