1 16 package org.apache.commons.vfs.test; 17 18 import junit.framework.AssertionFailedError; 19 import org.apache.commons.vfs.Capability; 20 import org.apache.commons.vfs.FileObject; 21 22 27 public class LastModifiedTests 28 extends AbstractProviderTestCase 29 { 30 33 protected Capability[] getRequiredCaps() 34 { 35 return new Capability[]{ 36 Capability.GET_LAST_MODIFIED 37 }; 38 } 39 40 43 public void testGetLastModified() throws Exception 44 { 45 final FileObject file = getReadFolder().resolveFile("file1.txt"); 47 file.getContent().getLastModifiedTime(); 48 49 } 54 55 58 public void testSetLastModified() throws Exception 59 { 60 final long now = System.currentTimeMillis(); 61 62 if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE)) 63 { 64 final FileObject file = getReadFolder().resolveFile("file1.txt"); 66 file.getContent().setLastModifiedTime(now); 67 try 68 { 69 assertEquals(now, file.getContent().getLastModifiedTime(), file.getFileSystem().getLastModTimeAccuracy()); 70 } 71 catch (AssertionFailedError e) 72 { 73 if (file.getFileSystem().getLastModTimeAccuracy() < 1000L) 75 { 76 assertEquals(now, file.getContent().getLastModifiedTime(), 1000L); 77 } 78 else 79 { 80 throw e; 81 } 82 } 83 } 84 85 if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER)) 86 { 87 final FileObject folder = getReadFolder().resolveFile("dir1"); 89 folder.getContent().setLastModifiedTime(now); 90 try 91 { 92 assertEquals(now, folder.getContent().getLastModifiedTime(), folder.getFileSystem().getLastModTimeAccuracy()); 93 } 94 catch (AssertionFailedError e) 95 { 96 if (folder.getFileSystem().getLastModTimeAccuracy() < 1000L) 98 { 99 assertEquals(now, folder.getContent().getLastModifiedTime(), 1000L); 100 } 101 else 102 { 103 throw e; 104 } 105 } 106 } 107 } 108 } 109 | Popular Tags |