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