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