Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 205   Methods: 4
NCLOC: 131   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeInterceptorRemoveKeyValTest.java - 100% 100% 100%
coverage
 1    /*
 2    * Created on 17-Feb-2005
 3    *
 4    *
 5    *
 6    */
 7    package org.jboss.cache.optimistic;
 8   
 9    import org.jboss.cache.CacheImpl;
 10    import org.jboss.cache.Fqn;
 11    import org.jboss.cache.GlobalTransaction;
 12    import org.jboss.cache.OptimisticTransactionEntry;
 13    import org.jboss.cache.TransactionTable;
 14    import org.jboss.cache.interceptors.Interceptor;
 15    import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
 16    import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
 17    import org.jboss.cache.loader.SamplePojo;
 18    import org.jboss.cache.transaction.DummyTransactionManager;
 19   
 20    import javax.transaction.Transaction;
 21    import java.util.HashMap;
 22    import java.util.Map;
 23   
 24    /**
 25    * @author xenephon
 26    */
 27    public class NodeInterceptorRemoveKeyValTest extends AbstractOptimisticTestCase
 28    {
 29   
 30   
 31    /**
 32    * @param name
 33    */
 34  3 public NodeInterceptorRemoveKeyValTest(String name)
 35    {
 36  3 super(name);
 37   
 38    }
 39   
 40  1 public void testTransactionRemoveNoNodeKeyValMethod() throws Exception
 41    {
 42   
 43  1 TestListener listener = new TestListener();
 44  1 final CacheImpl cache = createCacheWithListener(listener);
 45   
 46  1 Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
 47  1 interceptor.setCache(cache);
 48  1 Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
 49  1 nodeInterceptor.setCache(cache);
 50  1 MockInterceptor dummy = new MockInterceptor();
 51  1 dummy.setCache(cache);
 52   
 53  1 interceptor.setNext(nodeInterceptor);
 54  1 nodeInterceptor.setNext(dummy);
 55   
 56  1 cache.setInterceptorChain(interceptor);
 57   
 58    // first set up a node with a pojo
 59  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 60  1 mgr.begin();
 61  1 Transaction tx = mgr.getTransaction();
 62   
 63    // inject InvocationContext
 64  1 cache.getInvocationContext().setTransaction(tx);
 65  1 cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
 66   
 67  1 cache.remove("/one/two", "keyOne");
 68   
 69  1 assertEquals(null, dummy.getCalled());
 70  1 TransactionTable table = cache.getTransactionTable();
 71   
 72  1 GlobalTransaction gtx = table.get(tx);
 73   
 74  1 OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
 75   
 76  1 TransactionWorkspace workspace = entry.getTransactionWorkSpace();
 77   
 78   
 79  1 mgr.commit();
 80   
 81    //assert what should be the results of our call
 82  1 assertEquals(0, workspace.getNodes().size());
 83  1 assertNull(workspace.getNode(Fqn.fromString("/one/two")));
 84  1 assertTrue(entry.getLocks().isEmpty());
 85  1 assertEquals(1, entry.getModifications().size());
 86  1 assertTrue(!cache.exists("/one/two"));
 87  1 assertEquals(null, dummy.getCalled());
 88  1 cache.stop();
 89    }
 90   
 91  1 public void testTransactionRemoveNoKeyValMethod() throws Exception
 92    {
 93   
 94  1 TestListener listener = new TestListener();
 95  1 final CacheImpl cache = createCacheWithListener(listener);
 96   
 97  1 Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
 98  1 interceptor.setCache(cache);
 99  1 Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
 100  1 nodeInterceptor.setCache(cache);
 101  1 MockInterceptor dummy = new MockInterceptor();
 102  1 dummy.setCache(cache);
 103   
 104  1 interceptor.setNext(nodeInterceptor);
 105  1 nodeInterceptor.setNext(dummy);
 106   
 107  1 cache.setInterceptorChain(interceptor);
 108   
 109    // first set up a node with a pojo
 110  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 111  1 mgr.begin();
 112  1 Transaction tx = mgr.getTransaction();
 113   
 114    // inject InvocationContext
 115  1 cache.getInvocationContext().setTransaction(tx);
 116  1 cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
 117   
 118  1 SamplePojo pojo = new SamplePojo(21, "test");
 119  1 Map temp = new HashMap();
 120  1 temp.put("key1", pojo);
 121  1 cache.put("/one/two", temp);
 122   
 123  1 cache.remove("/one/two", "key2");
 124   
 125  1 assertEquals(null, dummy.getCalled());
 126  1 TransactionTable table = cache.getTransactionTable();
 127   
 128  1 GlobalTransaction gtx = table.get(tx);
 129   
 130  1 OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
 131   
 132  1 TransactionWorkspace workspace = entry.getTransactionWorkSpace();
 133   
 134   
 135  1 mgr.commit();
 136   
 137    //assert what should be the results of our call
 138  1 assertEquals(3, workspace.getNodes().size());
 139  1 assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
 140  1 assertNotNull(workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
 141  1 assertNull(workspace.getNode(Fqn.fromString("/one/two")).get("key2"));
 142  1 assertTrue(entry.getLocks().isEmpty());
 143  1 assertEquals(2, entry.getModifications().size());
 144  1 assertTrue(!cache.exists("/one/two"));
 145  1 assertEquals(null, dummy.getCalled());
 146  1 cache.stop();
 147    }
 148   
 149  1 public void testTransactionRemoveKeyValMethod() throws Exception
 150    {
 151   
 152  1 TestListener listener = new TestListener();
 153  1 final CacheImpl cache = createCacheWithListener(listener);
 154   
 155  1 Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
 156  1 interceptor.setCache(cache);
 157  1 Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
 158  1 nodeInterceptor.setCache(cache);
 159  1 MockInterceptor dummy = new MockInterceptor();
 160  1 dummy.setCache(cache);
 161   
 162  1 interceptor.setNext(nodeInterceptor);
 163  1 nodeInterceptor.setNext(dummy);
 164   
 165  1 cache.setInterceptorChain(interceptor);
 166   
 167    // first set up a node with a pojo
 168  1 DummyTransactionManager mgr = DummyTransactionManager.getInstance();
 169  1 mgr.begin();
 170  1 Transaction tx = mgr.getTransaction();
 171   
 172    // inject InvocationContext
 173  1 cache.getInvocationContext().setTransaction(tx);
 174  1 cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
 175   
 176  1 SamplePojo pojo = new SamplePojo(21, "test");
 177  1 Map temp = new HashMap();
 178  1 temp.put("key1", pojo);
 179  1 cache.put("/one/two", temp);
 180   
 181  1 cache.remove("/one/two", "key1");
 182   
 183  1 assertEquals(null, dummy.getCalled());
 184  1 TransactionTable table = cache.getTransactionTable();
 185   
 186  1 GlobalTransaction gtx = table.get(tx);
 187   
 188  1 OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
 189   
 190  1 TransactionWorkspace workspace = entry.getTransactionWorkSpace();
 191   
 192   
 193  1 mgr.commit();
 194   
 195    //assert what should be the results of our call
 196  1 assertEquals(3, workspace.getNodes().size());
 197  1 assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
 198  1 assertNull(workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
 199  1 assertTrue(entry.getLocks().isEmpty());
 200  1 assertEquals(2, entry.getModifications().size());
 201  1 assertTrue(!cache.exists("/one/two"));
 202  1 assertEquals(null, dummy.getCalled());
 203  1 cache.stop();
 204    }
 205    }