Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 129   Methods: 9
NCLOC: 94   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LocalTxUndoTest.java 75% 97.8% 88.9% 94.8%
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.Advised;
 16    import org.jboss.aop.advice.Interceptor;
 17    import org.jboss.cache.pojo.PojoCache;
 18    import org.jboss.cache.pojo.PojoCacheFactory;
 19    import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor;
 20    import org.jboss.cache.pojo.test.Person;
 21    import org.jboss.cache.transaction.DummyTransactionManager;
 22   
 23    import javax.transaction.TransactionManager;
 24   
 25    /**
 26    * Additional basic tests
 27    *
 28    * @author Ben Wang
 29    */
 30   
 31    public class LocalTxUndoTest extends TestCase
 32    {
 33    Log log_ = LogFactory.getLog(LocalTxUndoTest.class);
 34    PojoCache cache_;
 35    TransactionManager tx_mgr;
 36   
 37  3 public LocalTxUndoTest(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  1 public void testSimpleTxWithRollback1() throws Exception
 63    {
 64  1 log_.info("testSimpleTxWithRollback1() ....");
 65  1 Person test = new Person();
 66  1 test.setName("Ben");
 67  1 test.setAge(10);
 68   
 69  1 tx_mgr.begin();
 70  1 cache_.attach("/a", test);
 71  1 tx_mgr.getTransaction().rollback();
 72  1 assertFalse("Should not have cache interceptor ", hasCacheInterceptor(test));
 73   
 74  1 cache_.attach("/a", test);
 75    }
 76   
 77  3 private boolean hasCacheInterceptor(Object pojo)
 78    {
 79  3 Interceptor[] interceptors = ((Advised) pojo)._getInstanceAdvisor().getInterceptors();
 80  3 for (int i = 0; i < interceptors.length; i++)
 81    {
 82  1 if (interceptors[i] instanceof CacheFieldInterceptor)
 83  1 return true;
 84    }
 85  2 return false;
 86    }
 87   
 88  1 public void testSimpleTxWithRollback2() throws Exception
 89    {
 90  1 log_.info("testSimpleTxWithRollback2() ....");
 91  1 Person test = new Person();
 92  1 test.setName("Ben");
 93  1 test.setAge(10);
 94  1 cache_.attach("/a", test);
 95   
 96  1 tx_mgr.begin();
 97  1 cache_.detach("/a");
 98  1 tx_mgr.getTransaction().rollback();
 99   
 100  1 assertTrue("Should still have cache interceptor ", hasCacheInterceptor(test));
 101  1 cache_.detach("/a");
 102    }
 103   
 104  1 public void testSimpleTxWithRollback3() throws Exception
 105    {
 106  1 log_.info("testSimpleTxWithRollback3() ....");
 107  1 Person test = new Person();
 108  1 test.setName("Ben");
 109  1 test.setAge(10);
 110  1 tx_mgr.begin();
 111  1 cache_.attach("/a", test);
 112  1 cache_.detach("/a");
 113  1 tx_mgr.getTransaction().rollback();
 114   
 115  1 assertFalse("Should not have cache interceptor ", hasCacheInterceptor(test));
 116    }
 117   
 118  1 public static Test suite() throws Exception
 119    {
 120  1 return new TestSuite(LocalTxUndoTest.class);
 121    }
 122   
 123   
 124  0 public static void main(String[] args) throws Exception
 125    {
 126  0 junit.textui.TestRunner.run(LocalTxUndoTest.suite());
 127    }
 128   
 129    }