Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 146   Methods: 10
NCLOC: 107   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SetTxUndoTest.java 100% 98.3% 90% 97.2%
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.rollback;
 9   
 10    import junit.framework.TestCase;
 11    import junit.framework.Test;
 12    import junit.framework.TestSuite;
 13    import org.apache.commons.logging.Log;
 14    import org.apache.commons.logging.LogFactory;
 15    import org.jboss.cache.pojo.PojoCache;
 16    import org.jboss.cache.pojo.PojoCacheFactory;
 17    import org.jboss.cache.pojo.test.Person;
 18    import org.jboss.cache.transaction.DummyTransactionManager;
 19    import org.jboss.aop.proxy.ClassProxy;
 20   
 21    import javax.transaction.TransactionManager;
 22    import java.util.HashSet;
 23   
 24    /**
 25    * Additional basic tests
 26    *
 27    * @author Ben Wang
 28    */
 29   
 30    public class SetTxUndoTest extends TestCase
 31    {
 32    Log log_ = LogFactory.getLog(SetTxUndoTest.class);
 33    PojoCache cache_;
 34    TransactionManager tx_mgr;
 35   
 36  8 public SetTxUndoTest(String name)
 37    {
 38  8 super(name);
 39    }
 40   
 41  8 protected void setUp() throws Exception
 42    {
 43  8 super.setUp();
 44  8 log_.info("setUp() ....");
 45  8 String configFile = "META-INF/local-service.xml";
 46  8 boolean toStart = false;
 47  8 cache_ = PojoCacheFactory.createCache(configFile, toStart);
 48  8 cache_.start();
 49  8 tx_mgr = DummyTransactionManager.getInstance();
 50   
 51    }
 52   
 53  8 protected void tearDown() throws Exception
 54    {
 55  8 super.tearDown();
 56  8 cache_.stop();
 57    }
 58   
 59    // public void testDummy() {}
 60   
 61  2 public void testSimple() throws Exception
 62    {
 63  2 HashSet set = new HashSet();
 64  2 set.add("test1");
 65   
 66  2 tx_mgr.begin();
 67  2 cache_.attach("/a", set);
 68  2 tx_mgr.getTransaction().rollback();
 69  2 assertFalse("Should not have cache interceptor ", isProxy(set));
 70   
 71  2 cache_.attach("/a", set);
 72    }
 73   
 74  2 public void testSimpleTxWithRollback1() throws Exception
 75    {
 76  2 log_.info("testSimpleTxWithRollback1() ....");
 77  2 Person test = new Person();
 78  2 test.setName("Ben");
 79  2 test.setAge(10);
 80  2 HashSet set = new HashSet();
 81  2 set.add("English");
 82  2 test.setSkills(set);
 83   
 84  2 tx_mgr.begin();
 85  2 cache_.attach("/a", test);
 86  2 tx_mgr.getTransaction().rollback();
 87  2 assertFalse("Should not have cache interceptor ", isProxy(test.getSkills()));
 88   
 89  2 cache_.attach("/a", test);
 90    }
 91   
 92  8 private boolean isProxy(Object pojo)
 93    {
 94  2 if(pojo instanceof ClassProxy) return true;
 95  6 return false;
 96    }
 97   
 98  2 public void testSimpleTxWithRollback2() throws Exception
 99    {
 100  2 log_.info("testSimpleTxWithRollback1() ....");
 101  2 Person test = new Person();
 102  2 test.setName("Ben");
 103  2 test.setAge(10);
 104  2 HashSet set = new HashSet();
 105  2 set.add("English");
 106  2 test.setSkills(set);
 107   
 108  2 cache_.attach("/a", test);
 109   
 110  2 tx_mgr.begin();
 111  2 cache_.detach("/a");
 112  2 tx_mgr.getTransaction().rollback();
 113   
 114  2 assertTrue("Should still have cache interceptor ", isProxy(test.getSkills()));
 115  2 cache_.detach("/a");
 116    }
 117   
 118  2 public void testSimpleTxWithRollback3() throws Exception
 119    {
 120  2 log_.info("testSimpleTxWithRollback1() ....");
 121  2 Person test = new Person();
 122  2 test.setName("Ben");
 123  2 test.setAge(10);
 124  2 HashSet set = new HashSet();
 125  2 set.add("English");
 126  2 test.setSkills(set);
 127  2 tx_mgr.begin();
 128  2 cache_.attach("/a", test);
 129  2 cache_.detach("/a");
 130  2 tx_mgr.getTransaction().rollback();
 131   
 132  2 assertFalse("Should not have cache interceptor ", isProxy(test.getSkills()));
 133    }
 134   
 135  2 public static Test suite() throws Exception
 136    {
 137  2 return new TestSuite(SetTxUndoTest.class);
 138    }
 139   
 140   
 141  0 public static void main(String[] args) throws Exception
 142    {
 143  0 junit.textui.TestRunner.run(SetTxUndoTest.suite());
 144    }
 145   
 146    }