Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 178   Methods: 7
NCLOC: 130   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ActiveInactiveTest.java - 98.6% 100% 98.7%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7   
 8    package org.jboss.cache.marshall;
 9   
 10    import junit.framework.TestCase;
 11    import org.jboss.cache.CacheImpl;
 12    import org.jboss.cache.DefaultCacheFactory;
 13    import org.jboss.cache.Fqn;
 14    import org.jboss.cache.Region;
 15    import org.jboss.cache.RegionManager;
 16    import org.jboss.cache.Version;
 17   
 18    import java.lang.reflect.Method;
 19   
 20    /**
 21    * Tests the "activate/deactivate" functionality of LegacyTreeCacheMarshaller.
 22    *
 23    * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
 24    * @version $Revision$
 25    */
 26    public class ActiveInactiveTest extends TestCase
 27    {
 28    RegionManager rman;
 29    CacheImpl c;
 30    Fqn A = Fqn.fromString("/a");
 31    Fqn I = Fqn.fromString("/i");
 32    Fqn A_B = new Fqn(A, "b");
 33   
 34  5 @Override
 35    protected void setUp() throws Exception
 36    {
 37  5 super.setUp();
 38  5 c = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 39  5 c.getConfiguration().setUseRegionBasedMarshalling(true);
 40  5 c.getConfiguration().setFetchInMemoryState(false);
 41  5 c.start();
 42  5 rman = c.getRegionManager();
 43    }
 44   
 45  5 @Override
 46    protected void tearDown() throws Exception
 47    {
 48  5 super.tearDown();
 49  5 c.stop();
 50  5 c = null;
 51  5 rman = null;
 52    }
 53   
 54  1 public void testDefaultActive() throws Exception
 55    {
 56  1 rman.setDefaultInactive(false);
 57  1 assertFalse("Root is not active", rman.isInactive(Fqn.ROOT));
 58   
 59  1 rman.deactivate(A);
 60  1 assertFalse("Root is not active after inactivating subtree",
 61    rman.isInactive(Fqn.ROOT));
 62   
 63  1 rman.activate(A);
 64  1 assertFalse("Root is not active after activating subtree",
 65    rman.isInactive(Fqn.ROOT));
 66   
 67  1 rman.activate(A_B);
 68   
 69  1 rman.deactivate(Fqn.ROOT);
 70  1 assertTrue("Root is active", rman.isInactive(Fqn.ROOT));
 71    }
 72   
 73  1 public void testDefaultInactive() throws Exception
 74    {
 75  1 rman.setDefaultInactive(true);
 76   
 77  1 assertTrue("Root is not inactive", rman.isInactive(Fqn.ROOT));
 78   
 79  1 rman.activate(A);
 80  1 assertTrue("Root is not inactive after activating subtree",
 81    rman.isInactive(Fqn.ROOT));
 82   
 83  1 rman.deactivate(A);
 84  1 assertTrue("Root is not inactive after inactivating subtree",
 85    rman.isInactive(Fqn.ROOT));
 86   
 87  1 rman.deactivate(A_B);
 88   
 89  1 rman.activate(Fqn.ROOT);
 90  1 assertFalse("Root is not active", rman.isInactive(Fqn.ROOT));
 91    }
 92   
 93  1 public void testActivate() throws Exception
 94    {
 95  1 rman.setDefaultInactive(false);
 96  1 rman.activate(A);
 97  1 assertFalse("/a is not active after activating",
 98    rman.isInactive(A));
 99   
 100  1 rman.deactivate(A);
 101  1 rman.activate(A);
 102  1 assertFalse("/a is not active after reactivating",
 103    rman.isInactive(A));
 104   
 105  1 rman.reset();
 106  1 rman.setDefaultInactive(true);
 107   
 108  1 rman.activate(I);
 109  1 assertFalse("/i is not active after activating",
 110    rman.isInactive(I));
 111  1 assertFalse("/i/k is not active after activating /i",
 112    rman.isInactive(Fqn.fromString("/i/k")));
 113   
 114  1 rman.deactivate(I);
 115  1 rman.activate(I);
 116  1 assertFalse("/i is not active after reactivating",
 117    rman.isInactive(I));
 118    }
 119   
 120  1 public void testInactivate() throws Exception
 121    {
 122  1 rman.setDefaultInactive(true);
 123   
 124  1 rman.deactivate(I);
 125  1 assertTrue("/i is not inactive after inactivating",
 126    rman.isInactive(I));
 127   
 128  1 rman.activate(I);
 129  1 rman.deactivate(I);
 130  1 assertTrue("/i is not inactive after re-inactivating",
 131    rman.isInactive(I));
 132   
 133  1 rman.reset();
 134  1 rman.setDefaultInactive(false);
 135   
 136  1 rman.deactivate(A);
 137  1 assertTrue("/a is not inactive after inactivating",
 138    rman.isInactive(A));
 139  1 assertTrue("/a/b is not inactive after inactivating /a",
 140    rman.isInactive(A_B));
 141   
 142  1 rman.activate(A);
 143  1 rman.deactivate(A);
 144  1 assertTrue("/a is not inactive after re-inactivating",
 145    rman.isInactive(A));
 146    }
 147   
 148  1 public void testObjectFromByteBuffer() throws Exception
 149    {
 150  1 MethodCall put = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal,
 151    null, A_B, "name", "Joe", false);
 152   
 153  1 MethodCall replicate = MethodCallFactory.create(MethodDeclarations.replicateMethod, put);
 154   
 155  1 rman.setDefaultInactive(true);
 156  1 VersionAwareMarshaller testee = new VersionAwareMarshaller(rman, true, true, Version.getVersionString(Version.getVersionShort()));
 157  1 byte[] callBytes = testee.objectToByteBuffer(replicate);
 158   
 159  1 try
 160    {
 161  1 testee.objectFromByteBuffer(callBytes);
 162  0 fail("Expected to fail since region is inactive");
 163    }
 164    catch (Exception e)
 165    {
 166    // expected to fail since region is inactive
 167    }
 168   
 169  1 rman.activate(A);
 170  1 assertTrue(rman.hasRegion(A, Region.Type.ANY));
 171   
 172  1 MethodCall result = (MethodCall) testee.objectFromByteBuffer(callBytes);
 173  1 Method method = result.getMethod();
 174  1 assertEquals("Did not get replicate method when passing" +
 175    " call for active node", MethodDeclarations.replicateMethod, method);
 176    }
 177   
 178    }