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