Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
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.InternalConstant;
 17    import org.jboss.cache.pojo.PojoCache;
 18    import org.jboss.cache.pojo.PojoCacheFactory;
 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  6 public NewLocalTest(String name)
 35    {
 36  6 super(name);
 37    }
 38   
 39  6 protected void setUp() throws Exception
 40    {
 41  6 super.setUp();
 42  6 log_.info("setUp() ....");
 43  6 String configFile = "META-INF/local-service.xml";
 44  6 boolean toStart = false;
 45  6 cache_ = PojoCacheFactory.createCache(configFile, toStart);
 46  6 cache_.start();
 47  6 cache_.getCache().getRegion(Fqn.fromString("SESSION"), true);
 48    }
 49   
 50  6 protected void tearDown() throws Exception
 51    {
 52  6 super.tearDown();
 53  6 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  2 public void testPutRemove() throws Exception
 96    {
 97  2 log_.info("testPutRemove() ....");
 98  2 Person test = new Person();
 99  2 test.setName("Ben");
 100  2 test.setAge(10);
 101  2 cache_.attach("/a", test);
 102  2 Person result = (Person) cache_.find("/a");
 103  2 assertEquals(" ", test, result);
 104  2 result.setAge(20);
 105  2 cache_.detach("/a");
 106  2 assertNull("Object should be null ", cache_.find("/a"));
 107  2 assertEquals("Age should be updated as ", 20, test.getAge());
 108    }
 109   
 110  2 public void testPutRemoveNodeExistence() throws Exception
 111    {
 112  2 log_.info("testPutRemove() ....");
 113  2 Person test = new Person();
 114  2 test.setName("Ben");
 115  2 test.setAge(10);
 116  2 cache_.attach("person", test);
 117  2 Person result = (Person) cache_.find("person");
 118  2 assertEquals(" ", test, result);
 119  2 result.setAge(20);
 120  2 cache_.detach("person");
 121  2 assertNull("Object should be null ", cache_.find("person"));
 122  2 assertEquals("Age should be updated as ", 20, test.getAge());
 123   
 124  2 assertNull("DataNode should not exisit ", cache_.getCache().getRoot().get("person"));
 125    }
 126   
 127  2 public void testFindObjects() throws Exception
 128    {
 129  2 log_.info("testFindObjects() ....");
 130  2 Map map = cache_.findAll("/");
 131  2 assertEquals("Objects size should be ", 0, map.size());
 132  2 Person ben = new Person();
 133  2 ben.setName("Ben");
 134  2 ben.setAge(10);
 135  2 cache_.attach("/a/b/c", ben);
 136  2 cache_.attach("/e", ben); // multiple keys, same pojo
 137  2 Person joe = new Person();
 138  2 joe.setName("Joe");
 139  2 joe.setAge(10);
 140  2 cache_.attach("/f/joe", joe);
 141  2 map = cache_.findAll("/");
 142  2 assertEquals("Objects size should be ", 3, map.size());
 143   
 144  2 map = cache_.findAll("/a");
 145  2 assertEquals("Objects size should be ", 1, map.size());
 146  2 cache_.detach("/e");
 147  2 map = cache_.findAll("/");
 148  2 assertEquals("Objects size should be ", 2, map.size());
 149    }
 150   
 151  2 public static Test suite() throws Exception
 152    {
 153  2 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    }