Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 165   Methods: 12
NCLOC: 128   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ReplicatedTest.java - 98.5% 91.7% 97.4%
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.config.Configuration.CacheMode;
 17    import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
 18    import org.jboss.cache.pojo.PojoCache;
 19    import org.jboss.cache.pojo.PojoCacheFactory;
 20    import org.jboss.cache.pojo.test.Person;
 21    import org.jboss.cache.pojo.test.Student;
 22   
 23    import java.util.List;
 24   
 25    /**
 26    * Replicated test that use a tester wrapper. Future new test should use NewReplicatedAopTest
 27    *
 28    * @author Ben Wang
 29    */
 30    public class ReplicatedTest extends TestCase
 31    {
 32    Log log = LogFactory.getLog(org.jboss.cache.pojo.region.ReplicatedTest.class);
 33    PojoCache cache, cache1;
 34   
 35   
 36  5 public ReplicatedTest(String name)
 37    {
 38  5 super(name);
 39    }
 40   
 41  5 protected void setUp() throws Exception
 42    {
 43  5 super.setUp();
 44  5 log.info("setUp() ....");
 45  5 boolean toStart = false;
 46  5 cache = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
 47  5 cache.start();
 48  5 cache1 = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
 49  5 cache1.start();
 50  5 cache.getCache().getRegion(Fqn.fromString("SESSION"), true);
 51  5 cache1.getCache().getRegion(Fqn.fromString("SESSION"), true);
 52    }
 53   
 54  5 protected void tearDown() throws Exception
 55    {
 56  5 super.tearDown();
 57  5 cache.stop();
 58  5 cache1.stop();
 59    }
 60   
 61    // public void testDummy() {}
 62   
 63  4 private Person createPerson(String id, String name, int age)
 64    {
 65  4 Person p = new Person();
 66  4 p.setName(name);
 67  4 p.setAge(age);
 68  4 cache.attach(id, p);
 69  4 return p;
 70    }
 71   
 72  1 private Student createStudent(String id, String name, int age, String grade)
 73    {
 74  1 Student p = new Student();
 75  1 p.setName(name);
 76  1 p.setAge(age);
 77  1 p.setYear(grade);
 78  1 cache.attach(id, p);
 79  1 return p;
 80    }
 81   
 82  1 public void testSimple() throws Exception
 83    {
 84  1 log.info("testSimple() ....");
 85  1 Person ben = createPerson("/person/test1", "Ben Wang", 40);
 86  1 assertEquals("Ben Wang", ben.getName());
 87  1 assertEquals("Ben Wang", ((Person) cache1.find("/person/test1")).getName());
 88  1 cache.detach("/person/test1");
 89    }
 90   
 91   
 92  1 public void testDynamicRefSwapping() throws Exception
 93    {
 94  1 Person person = createPerson("/person/test3", "Joe", 32);
 95  1 try
 96    {
 97  1 person.setAge(30);
 98  1 List med = person.getMedication();
 99  1 assertNull("Medication should be null ", med);
 100  1 person.setAge(61);
 101  1 med = person.getMedication();
 102  1 assertEquals("Medication ", (Object) "Lipitor", (Object) med.get(0));
 103  1 assertEquals("Medication on cache1 ", "Lipitor",
 104    person.getMedication().get(0));
 105   
 106  1 person.setAge(71);
 107  1 assertEquals("Medication ", "Vioxx", med.get(1));
 108  1 assertEquals("Medication on cache1 ", "Vioxx",
 109    ((Person) cache1.find("/person/test3")).getMedication().get(1));
 110  1 cache.detach("/person/test3");
 111   
 112    }
 113    catch (Exception e)
 114    {
 115    // should be thrown
 116    }
 117    }
 118   
 119  1 public void testTransient() throws Exception
 120    {
 121  1 log.info("testTransient() ....");
 122  1 Person ben = createPerson("/person/test1", "Ben Wang", 40);
 123  1 ben.setCurrentStatus("Idle");
 124  1 assertEquals("Cache 1 ", "Idle", ben.getCurrentStatus());
 125  1 assertEquals("Cache 2 ", "Active",
 126    ((Person) cache1.find("/person/test1")).getCurrentStatus());
 127  1 cache.detach("/person/test1");
 128    }
 129   
 130  1 public void testModification() throws Exception
 131    {
 132  1 Person ben = createPerson("/person/test2", "Ben Wang", 40);
 133  1 ben.setName("Harald Gliebe");
 134  1 assertEquals(ben.getName(), "Harald Gliebe");
 135  1 assertEquals(((Person) cache1.find("/person/test2")).getName(), "Harald Gliebe");
 136  1 cache.detach("/person/test2");
 137    }
 138   
 139  1 public void testInheritance() throws Exception
 140    {
 141  1 Student joe = createStudent("/person/joe", "Joe", 32, "Senior");
 142  1 joe.setName("Joe Black");
 143  1 assertEquals(joe.getName(), "Joe Black");
 144  1 Student joe1 = (Student) cache1.find("/person/joe");
 145  1 assertEquals(joe1.getName(), "Joe Black");
 146  1 joe1.setYear("Junior");
 147  1 assertEquals(joe.getYear(), "Junior");
 148  1 assertEquals(joe1.getYear(), "Junior");
 149  1 cache.detach("/person/joe");
 150  1 cache.detach("/person/joe");
 151    }
 152   
 153   
 154  1 public static Test suite() throws Exception
 155    {
 156  1 return new TestSuite(org.jboss.cache.pojo.region.ReplicatedTest.class);
 157    }
 158   
 159   
 160  0 public static void main(String[] args) throws Exception
 161    {
 162  0 junit.textui.TestRunner.run(org.jboss.cache.pojo.region.ReplicatedTest.suite());
 163    }
 164   
 165    }