[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/api ...

Manik Surtani msurtani at jboss.com
Tue Jan 9 21:03:00 EST 2007


  User: msurtani
  Date: 07/01/09 21:03:00

  Modified:    tests/functional/org/jboss/cache/api   CacheSPITest.java
  Added:       tests/functional/org/jboss/cache/api   NodeSPITest.java
  Log:
  Bunch of API changes
  
  Revision  Changes    Path
  1.7       +0 -44     JBossCache/tests/functional/org/jboss/cache/api/CacheSPITest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheSPITest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/api/CacheSPITest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- CacheSPITest.java	5 Jan 2007 08:58:37 -0000	1.6
  +++ CacheSPITest.java	10 Jan 2007 02:03:00 -0000	1.7
  @@ -2,8 +2,6 @@
   
   import junit.framework.TestCase;
   import org.jboss.cache.CacheSPI;
  -import org.jboss.cache.Fqn;
  -import org.jboss.cache.NodeSPI;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.factories.DefaultCacheFactory;
   import org.jboss.cache.factories.XmlConfigurationParser;
  @@ -98,46 +96,4 @@
         assertTrue("Cache2 is coordinator", cache2.getRPCManager().isCoordinator());
   
      }
  -
  -   public void testDeepOperations() throws Exception
  -   {
  -      // only use 1 cache
  -      cache1.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
  -      cache1.start();
  -
  -      Fqn A = Fqn.fromString("/a");
  -      Fqn B = Fqn.fromString("/b");
  -      Fqn A_B = Fqn.fromString("/a/b");
  -
  -      NodeSPI nodeA, nodeB;
  -
  -      cache1.put(A, "k", "v");
  -      cache1.put(A_B, "k", "v");
  -
  -      nodeA = cache1.getRoot().getChildDirect(A); // should work
  -      nodeB = cache1.getRoot().getChildDirect(A_B); // should work
  -
  -      assertEquals(A_B, nodeB.getFqn());
  -
  -      nodeB = nodeA.getChildDirect(B); // should work
  -      assertEquals(A_B, nodeB.getFqn());
  -      cache1.getRoot().removeChildDirect(A_B); // should work
  -
  -      nodeA.removeChildDirect(B); // should work
  -      cache1.getRoot().removeChildDirect(A); // should work
  -
  -      try
  -      {
  -         cache1.getRoot().addChildDirect(A_B); // should fail
  -         fail("Should have failed");
  -      }
  -      catch (UnsupportedOperationException e)
  -      {
  -         // expected
  -      }
  -      nodeA = cache1.getRoot().addChildDirect(A); // should work
  -      nodeA.addChildDirect(B); // should work
  -
  -
  -   }
   }
  
  
  
  1.1      date: 2007/01/10 02:03:00;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/api/NodeSPITest.java
  
  Index: NodeSPITest.java
  ===================================================================
  package org.jboss.cache.api;
  
  import junit.framework.TestCase;
  import org.jboss.cache.CacheSPI;
  import org.jboss.cache.Fqn;
  import org.jboss.cache.NodeSPI;
  import org.jboss.cache.factories.DefaultCacheFactory;
  
  import java.util.Map;
  import java.util.Set;
  
  /**
   * Tests NodeSPI specific APIs.
   */
  public class NodeSPITest extends TestCase
  {
     private CacheSPI cache;
     private NodeSPI root;
  
     protected void setUp()
     {
        cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache();
        root = cache.getRoot();
     }
  
     protected void tearDown()
     {
        if (cache != null) cache.stop();
        root = null;
        cache = null;
     }
  
     public void testDeepOperations() throws Exception
     {
        Fqn A = Fqn.fromString("/a");
        Fqn B = Fqn.fromString("/b");
        Fqn A_B = Fqn.fromString("/a/b");
  
        NodeSPI nodeA, nodeB;
  
        cache.put(A, "k", "v");
        cache.put(A_B, "k", "v");
  
        nodeA = cache.getRoot().getChildDirect(A);// should work
        nodeB = cache.getRoot().getChildDirect(A_B);// should work
  
        assertEquals(A_B, nodeB.getFqn());
  
        nodeB = nodeA.getChildDirect(B);// should work
        assertEquals(A_B, nodeB.getFqn());
        cache.getRoot().removeChildDirect(A_B);// should work
  
        nodeA.removeChildDirect(B);// should work
        cache.getRoot().removeChildDirect(A);// should work
  
        try
        {
           cache.getRoot().addChildDirect(A_B);// should fail
           fail("Should have failed");
        }
        catch (UnsupportedOperationException e)
        {
           // expected
        }
        nodeA = cache.getRoot().addChildDirect(A);// should work
        nodeA.addChildDirect(B);// should work
     }
  
     public void testDataImmutabilityAndDefensiveCopy()
     {
        // put some stuff in the root node
        root.put("k", "v");
        Map dataDirect = root.getDataDirect();
        Set keysDirect = root.getKeysDirect();
  
        try
        {
           dataDirect.remove("k");
           fail("getDataDirect() should return an unmodifiable collection object");
        }
        catch (UnsupportedOperationException uoe)
        {
           // good; should be immutable
        }
  
        try
        {
           keysDirect.clear();
           fail("getKeysDirect() should return an unmodifiable collection object");
        }
        catch (UnsupportedOperationException uoe)
        {
           // good; should be immutable
        }
  
        // now test defensive copy
        root.put("k2", "v2");
  
        assertTrue("root.put() should have succeeded", root.getDataDirect().containsKey("k2"));
        assertTrue("getDataDirect() should have made a defensive copy of the data collection object", !dataDirect.containsKey("k2"));
        assertTrue("getKeysDirect() should have made a defensive copy of the data collection object", !keysDirect.contains("k2"));
     }
  
     public void testChildrenImmutabilityAndDefensiveCopy()
     {
        // put some stuff in the root node
        Object childName = "childName";
        Object newChild = "newChild";
        root.addChild(new Fqn(childName));
        Map childrenMapDirect = root.getChildrenMapDirect();
        Set childrenDirect = root.getChildrenDirect();
        Set childrenNamesDirect = root.getChildrenNamesDirect();
  
        try
        {
           childrenMapDirect.clear();
           fail("getChildrenMapDirect() should return an unmodifiable collection object");
        }
        catch (UnsupportedOperationException uoe)
        {
           // good; should be immutable
        }
  
        try
        {
           childrenDirect.clear();
           fail("getChildrenDirect() should return an unmodifiable collection object");
        }
        catch (UnsupportedOperationException uoe)
        {
           // good; should be immutable
        }
  
        try
        {
           childrenNamesDirect.clear();
           fail("getChildrenNamesDirect() should return an unmodifiable collection object");
        }
        catch (UnsupportedOperationException uoe)
        {
           // good; should be immutable
        }
  
        // now test defensive copy
        root.addChild(new Fqn(newChild));
  
        assertTrue("root.addChild() should have succeeded", root.getChildrenNamesDirect().contains(newChild));
        assertTrue("getChildrenMapDirect() should have made a defensive copy of the data collection object", !childrenMapDirect.containsKey(newChild));
        assertTrue("getChildrenDirect() should have made a defensive copy of the data collection object", !childrenDirect.contains(newChild));
        assertTrue("getChildrenNamesDirect() should have made a defensive copy of the data collection object", !childrenNamesDirect.contains(newChild));
  
     }
  
     public void testNullCollections()
     {
        // nothing in root, make sure we see no nulls.
        assertNotNull("Should not be null", root.getDataDirect());
        assertTrue("Should be empty", root.getDataDirect().isEmpty());
  
        assertNotNull("Should not be null", root.getKeysDirect());
        assertTrue("Should be empty", root.getKeysDirect().isEmpty());
  
        assertNotNull("Should not be null", root.getChildrenMapDirect());
        assertTrue("Should be empty", root.getChildrenMapDirect().isEmpty());
  
        assertNotNull("Should not be null", root.getChildrenDirect());
        assertTrue("Should be empty", root.getChildrenDirect().isEmpty());
  
        assertNotNull("Should not be null", root.getChildrenNamesDirect());
        assertTrue("Should be empty", root.getChildrenNamesDirect().isEmpty());
     }
  
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list