Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 162   Methods: 9
NCLOC: 122   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NewLocalTest.java - 77.9% 77.8% 77.9%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7   
 8    package org.jboss.cache.pojo.region;
 9   
 10    import junit.framework.Test;
 11    import junit.framework.TestCase;
 12    import junit.framework.TestSuite;
 13    import org.apache.commons.logging.Log;
 14    import org.apache.commons.logging.LogFactory;
 15    import org.jboss.cache.Fqn;
 16    import org.jboss.cache.pojo.PojoCache;
 17    import org.jboss.cache.pojo.PojoCacheFactory;
 18    import org.jboss.cache.pojo.impl.InternalConstant;
 19    import org.jboss.cache.pojo.test.Person;
 20   
 21    import java.util.Map;
 22   
 23    /**
 24    * Additional basic tests
 25    *
 26    * @author Ben Wang
 27    */
 28   
 29    public class NewLocalTest extends TestCase
 30    {
 31    Log log_ = LogFactory.getLog(org.jboss.cache.pojo.region.NewLocalTest.class);
 32    PojoCache cache_;
 33   
 34  3 public NewLocalTest(String name)
 35    {
 36  3 super(name);
 37    }
 38   
 39  3 protected void setUp() throws Exception
 40    {
 41  3 super.setUp();
 42  3 log_.info("setUp() ....");
 43  3 String configFile = "META-INF/local-service.xml";
 44  3 boolean toStart = false;
 45  3 cache_ = PojoCacheFactory.createCache(configFile, toStart);
 46  3 cache_.start();
 47  3 cache_.getCache().getRegion(Fqn.fromString("SESSION"), true);
 48    }
 49   
 50  3 protected void tearDown() throws Exception
 51    {
 52  3 super.tearDown();
 53  3 cache_.stop();
 54    }
 55   
 56    // public void testDummy() {}
 57   
 58    /**
 59    * Not applied anymore.
 60    *
 61    * @throws Exception
 62    */
 63  0 public void XtestBadFqn() throws Exception
 64    {
 65  0 log_.info("testBadFqn() ....");
 66  0 Person test = new Person();
 67  0 test.setName("Ben");
 68  0 test.setAge(10);
 69  0 cache_.attach("/a", test);
 70  0 Person result = (Person) cache_.detach("/a");
 71  0 assertEquals(" ", test, result);
 72  0 result.setAge(20);
 73   
 74  0 try
 75    {
 76  0 cache_.attach(InternalConstant.JBOSS_INTERNAL_STRING, test);
 77  0 fail("putObject under JBoss_Internal should fail");
 78    }
 79    catch (IllegalArgumentException iex)
 80    {
 81    // ok
 82    }
 83   
 84  0 try
 85    {
 86  0 cache_.detach(InternalConstant.JBOSS_INTERNAL_STRING);
 87  0 fail("putObject under JBoss_Internal should fail");
 88    }
 89    catch (IllegalArgumentException iex)
 90    {
 91    // ok
 92    }
 93    }
 94   
 95  1 public void testPutRemove() throws Exception
 96    {
 97  1 log_.info("testPutRemove() ....");
 98  1 Person test = new Person();
 99  1 test.setName("Ben");
 100  1 test.setAge(10);
 101  1 cache_.attach("/a", test);
 102  1 Person result = (Person) cache_.find("/a");
 103  1 assertEquals(" ", test, result);
 104  1 result.setAge(20);
 105  1 cache_.detach("/a");
 106  1 assertNull("Object should be null ", cache_.find("/a"));
 107  1 assertEquals("Age should be updated as ", 20, test.getAge());
 108    }
 109   
 110  1 public void testPutRemoveNodeExistence() throws Exception
 111    {
 112  1 log_.info("testPutRemove() ....");
 113  1 Person test = new Person();
 114  1 test.setName("Ben");
 115  1 test.setAge(10);
 116  1 cache_.attach("person", test);
 117  1 Person result = (Person) cache_.find("person");
 118  1 assertEquals(" ", test, result);
 119  1 result.setAge(20);
 120  1 cache_.detach("person");
 121  1 assertNull("Object should be null ", cache_.find("person"));
 122  1 assertEquals("Age should be updated as ", 20, test.getAge());
 123   
 124  1 assertNull("DataNode should not exisit ", cache_.getCache().getRoot().get("person"));
 125    }
 126   
 127  1 public void testFindObjects() throws Exception
 128    {
 129  1 log_.info("testFindObjects() ....");
 130  1 Map map = cache_.findAll("/");
 131  1 assertEquals("Objects size should be ", 0, map.size());
 132  1 Person ben = new Person();
 133  1 ben.setName("Ben");
 134  1 ben.setAge(10);
 135  1 cache_.attach("/a/b/c", ben);
 136  1 cache_.attach("/e", ben); // multiple keys, same pojo
 137  1 Person joe = new Person();
 138  1 joe.setName("Joe");
 139  1 joe.setAge(10);
 140  1 cache_.attach("/f/joe", joe);
 141  1 map = cache_.findAll("/");
 142  1 assertEquals("Objects size should be ", 3, map.size());
 143   
 144  1 map = cache_.findAll("/a");
 145  1 assertEquals("Objects size should be ", 1, map.size());
 146  1 cache_.detach("/e");
 147  1 map = cache_.findAll("/");
 148  1 assertEquals("Objects size should be ", 2, map.size());
 149    }
 150   
 151  1 public static Test suite() throws Exception
 152    {
 153  1 return new TestSuite(org.jboss.cache.pojo.region.NewLocalTest.class);
 154    }
 155   
 156   
 157  0 public static void main(String[] args) throws Exception
 158    {
 159  0 junit.textui.TestRunner.run(org.jboss.cache.pojo.region.NewLocalTest.suite());
 160    }
 161   
 162    }