commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1658868 - /commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java
Date Wed, 11 Feb 2015 02:15:42 GMT
Author: ecki
Date: Wed Feb 11 02:15:41 2015
New Revision: 1658868

URL: http://svn.apache.org/r1658868
Log:
[tests] more seperate last modified tests, added todo for VFS-563

Modified:
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java?rev=1658868&r1=1658867&r2=1658868&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java
Wed Feb 11 02:15:41 2015
@@ -16,19 +16,21 @@
  */
 package org.apache.commons.vfs2.test;
 
-import junit.framework.AssertionFailedError;
+import static org.junit.Assert.assertNotEquals;
+
+import java.util.Date;
 
 import org.apache.commons.vfs2.Capability;
 import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemException;
 import org.junit.Assert;
 
 /**
  * Test cases for getting and setting file last modified time.
- *
  */
 public class LastModifiedTests extends AbstractProviderTestCase
 {
-    private void asssertDelta(final String message, final long expected, final long actual,
final long delta)
+    private void assertDelta(final String message, final long expected, final long actual,
final long delta)
     {
         if (expected == actual)
         {
@@ -36,7 +38,7 @@ public class LastModifiedTests extends A
         }
         if (!(Math.abs(expected - actual) <= delta))
         {
-            Assert.fail(String.format("%s expected=%d, actual=%d, delta=%d", message, Long.valueOf(expected),
Long.valueOf(actual), Long.valueOf(delta)));
+            Assert.fail(String.format("%s expected=%d (%s), actual=%d (%s), delta=%d", message,
Long.valueOf(expected), new Date(expected).toString(), Long.valueOf(actual), new Date(actual).toString(),
Long.valueOf(delta)));
         }
     }
 
@@ -51,71 +53,75 @@ public class LastModifiedTests extends A
     }
 
     /**
+     * Tests FileSystem#getLastModTimeAccuracy for sane values.
+     * @throws FileSystemException if error occurred
+     */
+    public void testGetAccurary() throws FileSystemException
+    {
+        final FileObject file = getReadFolder().resolveFile("file1.txt");
+        final long lastModTimeAccuracy = (long)file.getFileSystem().getLastModTimeAccuracy();
+        // System.out.println("Accuracy on " + file.getFileSystem().getRootURI() + " is "
+ lastModTimeAccuracy + " as told by " + file.getFileSystem().getClass().getCanonicalName());
+        assertTrue("Accuracy must be positive",  lastModTimeAccuracy >= 0);
+        assertTrue("Accuracy must be < 2m",  lastModTimeAccuracy < 2 * 60 * 1000);
// just any sane limit
+    }
+
+    /**
+     * Tests getting the last modified time of a folder.
+     * @throws FileSystemException if error occurred
+     */
+    public void testGetLastModifiedFolder() throws FileSystemException
+    {
+        final FileObject file = getReadFolder().resolveFile("dir1");
+        assertNotEquals(0L,  file.getContent().getLastModifiedTime());
+    }
+
+    /**
      * Tests getting the last modified time of a file.
+     * @throws FileSystemException if error occurred
      */
-    public void testGetLastModified() throws Exception
+    public void testGetLastModifiedFile() throws FileSystemException
     {
-        // Try a file.
         final FileObject file = getReadFolder().resolveFile("file1.txt");
-        file.getContent().getLastModifiedTime();
+        assertNotEquals(0L,  file.getContent().getLastModifiedTime());
+    }
+
+    /**
+     * Tests setting the last modified time of a folder.
+     * @throws FileSystemException if error occurred
+     */
+    public void testSetLastModifiedFolder() throws FileSystemException
+    {
+        final long yesterday = System.currentTimeMillis() - 24*60*60*1000;
 
-        // TODO - switch this on
-        // Try a folder
-        // final FileObject folder = getReadFolder().resolveFile( "dir1" );
-        // folder.getContent().getLastModifiedTime();
+        if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER))
+        {
+            // Try a folder
+            final FileObject folder = getReadFolder().resolveFile("dir1");
+            folder.getContent().setLastModifiedTime(yesterday);
+            final long lastModTimeAccuracy = (long)folder.getFileSystem().getLastModTimeAccuracy();
+            // folder.refresh(); TODO: does not work with SSH VFS-563
+            final long lastModifiedTime = folder.getContent().getLastModifiedTime();
+            assertDelta("set/getLastModified on Folder", yesterday, lastModifiedTime, lastModTimeAccuracy);
+        }
     }
 
     /**
      * Tests setting the last modified time of file.
+     * @throws FileSystemException if error occurred
      */
-    public void testSetLastModified() throws Exception
+    public void testSetLastModifiedFile() throws FileSystemException
     {
-        final long now = System.currentTimeMillis();
+        final long yesterday = System.currentTimeMillis() - 24*60*60*1000;
 
         if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE))
         {
             // Try a file
             final FileObject file = getReadFolder().resolveFile("file1.txt");
-            file.getContent().setLastModifiedTime(now);
-            final double lastModTimeAccuracy = file.getFileSystem().getLastModTimeAccuracy();
+            file.getContent().setLastModifiedTime(yesterday);
+            final long lastModTimeAccuracy = (long)file.getFileSystem().getLastModTimeAccuracy();
+            // folder.refresh(); TODO: does not work with SSH VFS-563
             final long lastModifiedTime = file.getContent().getLastModifiedTime();
-            try
-            {
-                assertEquals("Check 1", now, lastModifiedTime, lastModTimeAccuracy);
-            } catch (final AssertionFailedError e)
-            {
-                // on linux ext3 the above check is not necessarily true
-                if (lastModTimeAccuracy < 1000L)
-                {
-                    asssertDelta("Check 2", now, lastModifiedTime, 1000L);
-                } else
-                {
-                    throw e;
-                }
-            }
-        }
-
-        if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER))
-        {
-            // Try a folder
-            final FileObject folder = getReadFolder().resolveFile("dir1");
-            folder.getContent().setLastModifiedTime(now);
-            final double lastModTimeAccuracy = folder.getFileSystem().getLastModTimeAccuracy();
-            final long lastModifiedTime = folder.getContent().getLastModifiedTime();
-            try
-            {
-                assertEquals("Check 3", now, lastModifiedTime, lastModTimeAccuracy);
-            } catch (final AssertionFailedError e)
-            {
-                // on linux ext3 the above check is not necessarily true
-                if (lastModTimeAccuracy < 1000L)
-                {
-                    asssertDelta("Check 4", now, lastModifiedTime, 1000L);
-                } else
-                {
-                    throw e;
-                }
-            }
+            assertDelta("set/getLastModified on File", yesterday, lastModifiedTime, lastModTimeAccuracy);
         }
     }
 }



Mime
View raw message