Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 180   Methods: 9
NCLOC: 136   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ReplicatedPutWithBulkRemoveTest.java - 98.9% 88.9% 98%
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;
 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.config.Configuration.CacheMode;
 16    import org.jboss.cache.factories.UnitTestCacheFactory;
 17    import org.jboss.cache.pojo.test.Address;
 18    import org.jboss.cache.pojo.test.Person;
 19   
 20    import javax.naming.Context;
 21    import java.util.ArrayList;
 22    import java.util.List;
 23    import java.util.Properties;
 24   
 25    /**
 26    * Test for attach with existing pojo for bulkd remove for speed.
 27    *
 28    * @author Ben Wang
 29    */
 30   
 31    public class ReplicatedPutWithBulkRemoveTest extends TestCase
 32    {
 33    Log log_ = LogFactory.getLog(ReplicatedPutWithBulkRemoveTest.class);
 34    PojoCache cache_;
 35    PojoCache cache1_;
 36   
 37  6 public ReplicatedPutWithBulkRemoveTest(String name)
 38    {
 39  6 super(name);
 40    }
 41   
 42  6 protected void setUp() throws Exception
 43    {
 44  6 super.setUp();
 45  6 Properties prop = new Properties();
 46  6 prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
 47  6 boolean toStart = false;
 48  6 cache_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
 49  6 cache1_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
 50  6 cache_.start();
 51  6 cache1_.start();
 52    }
 53   
 54  6 protected void tearDown() throws Exception
 55    {
 56  6 super.tearDown();
 57  6 cache_.stop();
 58  6 cache1_.stop();
 59    }
 60   
 61  2 public void testPutPutLocal() throws Exception
 62    {
 63  2 log_.info("testPutPut() ....");
 64  2 Person test = new Person();
 65  2 test.setName("Ben");
 66  2 test.setAge(10);
 67  2 Address addr = new Address();
 68  2 addr.setZip(95123);
 69  2 addr.setCity("Sunnyvale");
 70  2 test.setAddress(addr);
 71  2 cache_.attach("/a", test);
 72  2 Person result = (Person) cache_.find("/a");
 73  2 assertEquals(" ", test, result);
 74   
 75  2 Person joe = new Person();
 76  2 joe.setName("joe");
 77  2 joe.setAge(20);
 78  2 cache_.attach("/a", joe);
 79  2 Person joe1 = (Person) cache_.find("/a");
 80  2 assertEquals("Age should be ", 20, joe1.getAge());
 81   
 82  2 assertEquals("Age should be ", 10, result.getAge());
 83  2 assertEquals("Zip should be ", 95123, result.getAddress().getZip());
 84   
 85    // Try to re-use the pojo
 86  2 cache_.attach("/a", test);
 87  2 Person result1 = (Person) cache_.find("/a");
 88  2 assertEquals("Zip should be ", 95123, result1.getAddress().getZip());
 89   
 90    }
 91   
 92  2 public void testPutPut() throws Exception
 93    {
 94  2 log_.info("testPutPut() ....");
 95  2 Person test = new Person();
 96  2 test.setName("Ben");
 97  2 test.setAge(10);
 98  2 Address addr = new Address();
 99  2 addr.setZip(95123);
 100  2 addr.setCity("Sunnyvale");
 101  2 test.setAddress(addr);
 102  2 cache_.attach("/a", test);
 103  2 Person result = (Person) cache_.find("/a");
 104  2 assertEquals(" ", test, result);
 105   
 106  2 Person result1 = (Person) cache1_.find("/a");
 107  2 assertEquals("Age should be ", 10, result1.getAge());
 108  2 assertEquals("Zip should be ", 95123, result1.getAddress().getZip());
 109   
 110  2 Person joe = new Person();
 111  2 joe.setName("joe");
 112  2 joe.setAge(20);
 113  2 cache_.attach("/a", joe);
 114  2 Person joe1 = (Person) cache_.find("/a");
 115  2 assertEquals("Age should be ", 20, joe1.getAge());
 116   
 117  2 assertEquals("Age should be ", 10, result.getAge());
 118  2 assertEquals("Zip should be ", 95123, result.getAddress().getZip());
 119    }
 120   
 121  6 Address getAddress(String city)
 122    {
 123  6 Address addr = new Address();
 124  6 addr.setCity(city);
 125  6 addr.setZip(95123);
 126  6 addr.setStreet("Sunnyvale");
 127  6 return addr;
 128    }
 129   
 130  2 public void testPutCollection() throws Exception
 131    {
 132  2 log_.info("testPutCollection() ....");
 133  2 Person p1 = new Person();
 134  2 p1.setName("Ben");
 135  2 p1.setAge(10);
 136  2 p1.setAddress(getAddress("Sunnyvale"));
 137   
 138  2 List<Address> lang = new ArrayList<Address>();
 139  2 lang.add(getAddress("Taipei"));
 140  2 lang.add(getAddress("Tainan"));
 141  2 p1.setLanguages(lang);
 142   
 143  2 cache_.attach("/a", p1);
 144  2 Person result = (Person) cache_.find("/a");
 145  2 assertEquals(" ", p1, result);
 146   
 147  2 Person result1 = (Person) cache1_.find("/a");
 148  2 assertEquals("Age should be ", 10, result1.getAge());
 149  2 assertEquals("Zip should be ", 95123, result1.getAddress().getZip());
 150   
 151  2 Person p2 = new Person();
 152  2 p2.setName("joe");
 153  2 p2.setAge(20);
 154  2 cache_.attach("/a", p2);
 155  2 Person joe1 = (Person) cache_.find("/a");
 156  2 assertEquals("Age should be ", 20, joe1.getAge());
 157   
 158    // put p1 again
 159  2 cache_.attach("/a", p1);
 160   
 161    // remove p1
 162  2 Person p3 = (Person) cache_.detach("/a");
 163  2 assertEquals("Zip should be ", 95123, p3.getAddress().getZip());
 164   
 165  2 assertEquals("Age should be ", 10, result.getAge());
 166  2 assertEquals("Zip should be ", 95123, result.getAddress().getZip());
 167    }
 168   
 169  2 public static Test suite() throws Exception
 170    {
 171  2 return new TestSuite(ReplicatedPutWithBulkRemoveTest.class);
 172    }
 173   
 174   
 175  0 public static void main(String[] args) throws Exception
 176    {
 177  0 junit.textui.TestRunner.run(ReplicatedPutWithBulkRemoveTest.suite());
 178    }
 179   
 180    }