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