KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > test > LastModifiedTests


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
23  * Test cases for getting and setting file last modified time.
24  *
25  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
26  */

27 public class LastModifiedTests
28     extends AbstractProviderTestCase
29 {
30     /**
31      * Returns the capabilities required by the tests of this test case.
32      */

33     protected Capability[] getRequiredCaps()
34     {
35         return new Capability[]{
36             Capability.GET_LAST_MODIFIED
37         };
38     }
39
40     /**
41      * Tests getting the last modified time of a file.
42      */

43     public void testGetLastModified() throws Exception JavaDoc
44     {
45         // Try a file.
46
final FileObject file = getReadFolder().resolveFile("file1.txt");
47         file.getContent().getLastModifiedTime();
48
49         // TODO - switch this on
50
// Try a folder
51
//final FileObject folder = getReadFolder().resolveFile( "dir1" );
52
//folder.getContent().getLastModifiedTime();
53
}
54
55     /**
56      * Tests setting the last modified time of file.
57      */

58     public void testSetLastModified() throws Exception JavaDoc
59     {
60         final long now = System.currentTimeMillis();
61
62         if (getReadFolder().getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE))
63         {
64             // Try a file
65
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                 // on linux ext3 the above check is not necessarily true
74
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             // Try a folder
88
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                 // on linux ext3 the above check is not necessarily true
97
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