[jboss-cvs] JBossAS SVN: r87130 - in projects/jboss-deployers/trunk: deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 10 10:39:44 EDT 2009


Author: alesj
Date: 2009-04-10 10:39:44 -0400 (Fri, 10 Apr 2009)
New Revision: 87130

Modified:
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/OverrideSynchAdapter.java
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java
   projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/BootstrapDeployersTest.java
   projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java
Log:
[JBAS-6722]; add, delete, update, touch tests.

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/BootstrapDeployersTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/BootstrapDeployersTest.java	2009-04-10 14:04:57 UTC (rev 87129)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/BootstrapDeployersTest.java	2009-04-10 14:39:44 UTC (rev 87130)
@@ -25,6 +25,7 @@
 import java.security.CodeSource;
 import java.security.ProtectionDomain;
 import java.util.List;
+import java.io.IOException;
 
 import junit.framework.AssertionFailedError;
 
@@ -89,7 +90,7 @@
       return (BootstrapDeployersTestDelegate) super.getDelegate();
    }
    
-   protected VFSDeployment createVFSDeployment(String root, String child) throws Exception
+   protected VirtualFile createDeploymentRoot(String root, String child) throws IOException
    {
       URL resourceRoot = getClass().getResource(root);
       if (resourceRoot == null)
@@ -97,9 +98,15 @@
       VirtualFile deployment = VFS.getVirtualFile(resourceRoot, child);
       if (deployment == null)
          fail("Child not found " + child + " from " + resourceRoot);
+      return deployment;
+   }
+
+   protected VFSDeployment createVFSDeployment(String root, String child) throws Exception
+   {
+      VirtualFile deployment = createDeploymentRoot(root, child);
       return createVFSDeployment(deployment);
    }
-   
+
    protected VFSDeployment createVFSDeployment(VirtualFile root) throws Exception
    {
       VFSDeploymentFactory factory = VFSDeploymentFactory.getInstance();

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java	2009-04-10 14:04:57 UTC (rev 87129)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/SynchModificationTestCase.java	2009-04-10 14:39:44 UTC (rev 87130)
@@ -21,6 +21,13 @@
  */
 package org.jboss.test.deployers.vfs.structure.modified.test;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.BufferedWriter;
+import java.io.OutputStreamWriter;
+import java.net.URI;
+
 import junit.framework.Test;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.modified.OverrideSynchAdapter;
@@ -29,6 +36,7 @@
 import org.jboss.test.deployers.vfs.structure.modified.support.XmlIncludeVirtualFileFilter;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VFSUtils;
 
 /**
  * Test file synch.
@@ -72,12 +80,64 @@
 
    public void testWAR() throws Exception
    {
-      VFSDeploymentUnit deploymentUnit = assertDeploy("/synch/war", "simple.war");
+      VirtualFile originalRoot = createDeploymentRoot("/synch/war", "simple.war");
+      VFSDeploymentUnit deploymentUnit = assertDeploy(originalRoot);
       try
       {
-         VirtualFile root = deploymentUnit.getRoot();
+         VirtualFile tempRoot = deploymentUnit.getRoot();
          StructureModificationChecker checker = createStructureModificationChecker();
-         assertFalse(checker.hasStructureBeenModified(root));
+         assertFalse(checker.hasStructureBeenModified(originalRoot));
+
+         // add new file
+         URI rootURI = VFSUtils.getRealURL(originalRoot).toURI();
+         File rootFile = new File(rootURI);
+         File newFile = newFile(rootFile, "newfile.txt");
+         try
+         {
+            assertNull(tempRoot.getChild("newfile.txt"));                        
+            assertFalse(checker.hasStructureBeenModified(originalRoot));
+            assertNotNull(tempRoot.getChild("newfile.txt"));
+
+            // try deleting this one now
+            assertTrue(newFile.delete());
+            assertFalse(checker.hasStructureBeenModified(originalRoot));
+            assertNull(tempRoot.getChild("newfile.txt"));
+         }
+         finally
+         {
+            if (newFile.exists())
+               assertTrue(newFile.delete());
+         }
+
+         // update some file
+         File updateFile = new File(rootFile, "test.jsp");
+         assertTrue(updateFile.exists());
+         assertTrue(updateFile.setLastModified(System.currentTimeMillis()));
+         @SuppressWarnings("deprecation")
+         VirtualFile testJsp = tempRoot.findChild("test.jsp");
+         long tempTimestamp = testJsp.getLastModified();
+         assertFalse(checker.hasStructureBeenModified(originalRoot));
+         assertTrue(tempTimestamp < testJsp.getLastModified());
+
+         // update something outside recurse filter
+         VirtualFile someProps = originalRoot.getChild("WEB-INF/classes/some.properties");
+         assertNotNull(someProps);
+         updateFile = new File(VFSUtils.getRealURL(someProps).toURI());
+         assertTrue(updateFile.exists());
+         assertTrue(updateFile.setLastModified(System.currentTimeMillis()));
+         @SuppressWarnings("deprecation")
+         VirtualFile tempProps = tempRoot.findChild("WEB-INF/classes/some.properties");
+         tempTimestamp = tempProps.getLastModified();
+         assertFalse(checker.hasStructureBeenModified(originalRoot));
+         assertEquals(tempTimestamp, tempProps.getLastModified());
+
+         // check we don't update for nothing
+         @SuppressWarnings("deprecation")
+         VirtualFile xhtml = tempRoot.findChild("test.xhtml");
+         long xhtmlTimestamp = xhtml.getLastModified();
+         assertFalse(checker.hasStructureBeenModified(originalRoot));
+         assertEquals(xhtmlTimestamp, xhtml.getLastModified());
+
       }
       finally
       {
@@ -99,4 +159,20 @@
          undeploy(deploymentUnit);
       }
    }
+
+   protected File newFile(File parent, String name) throws IOException
+   {
+      File newFile = new File(parent, name);
+      FileOutputStream fos = new FileOutputStream(newFile);
+      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos));
+      try
+      {
+         writer.write("sometext");
+         return newFile;
+      }
+      finally
+      {
+         writer.close();
+      }
+   }
 }
\ No newline at end of file

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/OverrideSynchAdapter.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/OverrideSynchAdapter.java	2009-04-10 14:04:57 UTC (rev 87129)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/OverrideSynchAdapter.java	2009-04-10 14:39:44 UTC (rev 87130)
@@ -27,6 +27,7 @@
 import java.net.URISyntaxException;
 
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
 
 /**
  * Override synch adapter.
@@ -52,7 +53,8 @@
    {
       try
       {
-         URI uri = fileToOverride.toURI();
+         // get uri before we delete the file
+         URI uri = VFSUtils.getRealURL(fileToOverride).toURI();
          if (fileToOverride.delete())
          {
             File newFile = new File(uri);

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java	2009-04-10 14:04:57 UTC (rev 87129)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/UpdateDeleteVisitor.java	2009-04-10 14:39:44 UTC (rev 87130)
@@ -63,11 +63,22 @@
       {
          Long previous = getCache().getCacheValue(originalPathName);
          long lastModified = child.getLastModified();
-         if (previous != null && lastModified > previous)
+
+         boolean updateCache = false;
+         if (previous == null)
          {
+            updateCache = true;
+         }
+         else if (lastModified > previous)
+         {
             lastModified = getSynchAdapter().update(file, child);
+            updateCache = true;
          }
-         getCache().putCacheValue(originalPathName, lastModified);
+
+         if (updateCache)
+         {
+            getCache().putCacheValue(originalPathName, lastModified);
+         }
       }
    }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list