Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 174   Methods: 9
NCLOC: 122   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ReplicatedAnnotationTest.java - 76.4% 77.8% 76.5%
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.annotation;
 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.UnitTestCacheConfigurationFactory;
 17    import org.jboss.cache.pojo.PojoCache;
 18    import org.jboss.cache.pojo.PojoCacheFactory;
 19    import org.jboss.cache.pojo.test.Gadget;
 20    import org.jboss.cache.pojo.test.Resource;
 21    import org.jboss.cache.pojo.test.SpecialAddress;
 22   
 23    import javax.naming.Context;
 24    import java.util.ArrayList;
 25    import java.util.List;
 26    import java.util.Properties;
 27   
 28    /**
 29    * Test for JDK50 specific annotation.
 30    *
 31    * @author Ben Wang
 32    */
 33    public class ReplicatedAnnotationTest extends TestCase
 34    {
 35    Log log_ = LogFactory.getLog(ReplicatedAnnotationTest.class);
 36    PojoCache cache_;
 37    PojoCache cache1_;
 38   
 39  3 public ReplicatedAnnotationTest(String name)
 40    {
 41  3 super(name);
 42    }
 43   
 44  3 protected void setUp() throws Exception
 45    {
 46  3 super.setUp();
 47  3 Properties prop = new Properties();
 48  3 prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
 49  3 boolean toStart = false;
 50  3 cache_ = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
 51   
 52  3 cache1_ = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
 53  3 cache_.start();
 54  3 cache1_.start();
 55    }
 56   
 57  3 protected void tearDown() throws Exception
 58    {
 59  3 super.tearDown();
 60  3 cache_.stop();
 61  3 cache1_.stop();
 62    }
 63   
 64  1 public void testTransientAnnotation() throws Exception
 65    {
 66  1 log_.info("testTransientAnnotation() ....");
 67  1 Gadget ga = new Gadget();
 68  1 ga.setName("Printer");
 69  1 Resource res = new Resource();
 70  1 res.setName("Inet");
 71  1 res.setConnection("Eth0");
 72  1 ga.setResource(res);
 73   
 74  1 cache_.attach("/gadget", ga);
 75  1 Object obj = cache_.find("/gadget");
 76  1 assertEquals(ga, obj);
 77   
 78  1 Gadget ga1 = (Gadget) cache1_.find("/gadget");
 79  1 assertEquals("Name is ", ga.getName(), ga1.getName());
 80   
 81  1 assertNotNull("Resource should not be null on cache1 ", ga.getResource());
 82  1 assertNull("Resource should be null", ga1.getResource());
 83    }
 84   
 85  1 public void testSeriazableAnnotation() throws Exception
 86    {
 87  1 log_.info("testSerializableAnnotation() ....");
 88  1 Gadget ga = new Gadget();
 89  1 ga.setName("Printer");
 90  1 SpecialAddress addr = new SpecialAddress();
 91  1 addr.setAddr("10.1.2.2");
 92  1 ga.setAddr(addr);
 93   
 94  1 cache_.attach("/gadget", ga);
 95  1 Object obj = cache_.find("/gadget");
 96  1 assertEquals(ga, obj);
 97   
 98  1 Gadget ga1 = (Gadget) cache1_.find("/gadget");
 99  1 assertEquals("Name is ", ga.getName(), ga1.getName());
 100   
 101  1 SpecialAddress addr1 = (SpecialAddress) ga1.getAddr();
 102  1 addr1.setAddr("5152967326");
 103   
 104  1 assertNotSame("Special address should not be updated: ", addr1.getAddr(), addr.getAddr());
 105   
 106  1 ga1.setAddr(addr1);
 107  1 assertEquals("Special address should be the same", ga.getAddr().getAddr(), ga1.getAddr().getAddr());
 108   
 109    }
 110   
 111    /**
 112    * We haven't implemented this feature yet.
 113    *
 114    * @throws Exception
 115    */
 116  0 public void XtestSeriazableAnnotationWithRelationship() throws Exception
 117    {
 118  0 log_.info("testSerializableAnnotationWithRelationship() ....");
 119  0 Gadget ga = new Gadget();
 120  0 ga.setName("Printer");
 121  0 SpecialAddress addr = new SpecialAddress();
 122  0 addr.setAddr("10.1.2.2");
 123  0 ga.setAddr(addr);
 124   
 125  0 cache_.attach("/gadget1", ga);
 126  0 Object obj = cache_.find("/gadget1");
 127  0 assertEquals(ga, obj);
 128   
 129  0 Gadget ga2 = new Gadget();
 130  0 ga2.setName("Fax");
 131  0 ga2.setAddr(addr);
 132  0 cache_.attach("/gadget2", ga2);
 133   
 134  0 ga = (Gadget) cache1_.find("/gadget1");
 135  0 ga2 = (Gadget) cache1_.find("/gadget2");
 136  0 assertTrue("Sepecial address should be the same ", ga.getAddr() == ga2.getAddr());
 137    }
 138   
 139    /**
 140    * Test ClassProxy for generic List.
 141    *
 142    * @throws Exception
 143    */
 144  1 public void testCollectionWithGenerics() throws Exception
 145    {
 146  1 log_.info("testCollectionWithGenerics() ....");
 147  1 List<String> list = new ArrayList<String>();
 148  1 list.add("1");
 149  1 list.add("2");
 150   
 151  1 cache_.attach("/test", list);
 152   
 153  1 List<String> list1 = (List<String>) cache_.find("/test");
 154  1 list1.add("3");
 155  1 String l3 = list1.get(2);
 156  1 assertEquals("String ", "3", l3);
 157   
 158  1 list1 = (List<String>) cache1_.find("/test");
 159  1 l3 = list1.get(2);
 160  1 assertEquals("String ", "3", l3);
 161    }
 162   
 163  1 public static Test suite() throws Exception
 164    {
 165  1 return new TestSuite(ReplicatedAnnotationTest.class);
 166    }
 167   
 168   
 169  0 public static void main(String[] args) throws Exception
 170    {
 171  0 junit.textui.TestRunner.run(ReplicatedAnnotationTest.suite());
 172    }
 173   
 174    }