[jboss-cvs] JBossAS SVN: r66212 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 17 05:14:23 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-10-17 05:14:22 -0400 (Wed, 17 Oct 2007)
New Revision: 66212

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java
Log:
Add some more tests and add fixes to Scott's additions to the tests

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java	2007-10-17 07:04:22 UTC (rev 66211)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java	2007-10-17 09:14:22 UTC (rev 66212)
@@ -115,6 +115,7 @@
       return child;
    }
 
+   @Override
    public boolean exists() throws IOException
    {
       return true;
@@ -126,14 +127,33 @@
       {
          throw new RuntimeException("Cannot set contents for non-leaf node");
       }
+      initCacheLastModified();
       this.contents = contents;
    }
    
+   @Override
    protected void initCacheLastModified()
    {
       this.cachedLastModified = System.currentTimeMillis();
    }
 
+   @Override
+   public long getSize() throws IOException
+   {
+      if (contents != null)
+      {
+         return contents.length;
+      }
+      return 0;
+   }
+   
+   @Override
+   public long getLastModified() throws IOException
+   {
+      return cachedLastModified;
+   }
+
+   @Override
    public InputStream openStream() throws IOException
    {
       if (contents != null)

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java	2007-10-17 07:04:22 UTC (rev 66211)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/MemoryTestCase.java	2007-10-17 09:14:22 UTC (rev 66212)
@@ -25,6 +25,8 @@
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
 
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
@@ -32,7 +34,6 @@
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VFSContextFactory;
 import org.jboss.virtual.spi.VFSContextFactoryLocator;
-import org.jboss.virtual.spi.VirtualFileHandler;
 
 import junit.framework.TestCase;
 
@@ -147,6 +148,10 @@
          VFSContext ctx = mfactory.createRoot(root);
          URL url = new URL("vfsmemory://aopdomain/org/acme/test/Test.class");
          mfactory.putFile(url,  new byte[] {'a', 'b', 'c'});
+         URL url2 = new URL("vfsmemory://aopdomain/org/acme/test/Test2.class");
+         mfactory.putFile(url2,  new byte[] {'a', 'b', 'c'});
+         URL url3 = new URL("vfsmemory://aopdomain/org/acme/test/Test3.class");
+         mfactory.putFile(url3,  new byte[] {'a', 'b', 'c'});
          
          VFS vfs = ctx.getVFS();
          VirtualFile file = vfs.getVirtualFile(root, "/org/acme/test/Test.class");
@@ -154,10 +159,29 @@
          
          VirtualFile file2 = vfs.getVirtualFile(root, "/org");
          assertNotNull(file2);
-         VirtualFile file3 = file2.findChild("/acme/test/Test.class");
-         assertNotNull(file3);
+         VirtualFile test = file2.findChild("/acme/test/Test.class");
+         assertNotNull(test);
+         assertSame(file.getHandler(), test.getHandler());
          
-         assertSame(file.getHandler(), file3.getHandler());
+         //acme
+         List<VirtualFile> children = file2.getChildren();
+         assertEquals(1,children.size());
+         VirtualFile child = children.get(0);
+         //test
+         children = child.getChildren();
+         assertEquals(1,children.size());
+         child = children.get(0);
+         //test/*.class
+         children = child.getChildren();
+         assertEquals(3,children.size());
+         HashMap<String, VirtualFile> childMap = new HashMap<String, VirtualFile>();  
+         for (VirtualFile cur : children)
+         {
+            childMap.put(cur.getName(), cur);
+         }
+         assertNotNull(childMap.get("Test.class"));
+         assertNotNull(childMap.get("Test2.class"));
+         assertNotNull(childMap.get("Test3.class"));
       }
       finally
       {
@@ -165,6 +189,64 @@
       }
    }
 
+   public void testLeaf() throws Exception
+   {
+      MemoryContextFactory mfactory = MemoryContextFactory.getInstance();
+      URL root = new URL("vfsmemory://aopdomain");
+      try
+      {
+         VFSContext ctx = mfactory.createRoot(root);
+         URL url = new URL("vfsmemory://aopdomain/org/acme/leaf");
+         mfactory.putFile(url,  new byte[] {'a', 'b', 'c'});
+
+         URL url2 = new URL("vfsmemory://aopdomain/org/acme/leaf/shouldnotwork");
+         try
+         {
+            mfactory.putFile(url2,  new byte[] {'d', 'e', 'f'});
+            fail("It should not have been possible to add a child to a leaf node");
+         }
+         catch(Exception e)
+         {
+         }
+         
+         VirtualFile classFile = VFS.getVirtualFile(new URL("vfsmemory://aopdomain"), "org/acme/leaf");
+         assertNotNull(classFile);
+         try
+         {
+            VirtualFile classFile2 = VFS.getVirtualFile(new URL("vfsmemory://aopdomain"), "org/acme/leaf/shouldnotwork");
+            fail("It should not have been possible to find a child of a leaf node");
+         }
+         catch (Exception expected)
+         {
+         }
+         
+         
+         try
+         {
+            URL url3 = new URL("vfsmemory://aopdomain/org/acme");
+            mfactory.putFile(url3, new byte[] {'1', '2', '3'});
+            fail("Should not have been possible to set contents for a non-leaf node");
+         }
+         catch (Exception expected)
+         {
+         }
+         
+         try
+         {
+            URL url4 = new URL("vfsmemory://aopdomain/org");
+            mfactory.putFile(url4, new byte[] {'1', '2', '3'});
+            fail("Should not have been possible to set contents for a non-leaf node");
+         }
+         catch (Exception expected)
+         {
+         }
+      }
+      finally
+      {
+         mfactory.deleteRoot(root);
+      }
+   }
+   
    protected void setUp()
    {
       VFS.init();




More information about the jboss-cvs-commits mailing list