1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package org.objectledge.filesystem;
30
31 import java.io.IOException;
32
33 import junit.framework.TestCase;
34
35 /***
36 *
37 *
38 * @author <a href="Rafal.Krzewski">rafal@caltha.pl</a>
39 * @version $Id: LocalFileSystemProviderTest.java,v 1.7 2004/10/13 10:59:41 rafal Exp $
40 */
41 public class LocalFileSystemProviderTest extends TestCase
42 {
43 protected LocalFileSystemProvider provider;
44
45 /***
46 * Constructor for LocalFileProviderTest.
47 * @param arg0
48 */
49 public LocalFileSystemProviderTest(String arg0)
50 {
51 super(arg0);
52 }
53
54
55
56
57 protected void setUp() throws Exception
58 {
59 super.setUp();
60 provider = new LocalFileSystemProvider("local", "src/test/resources");
61 }
62
63 protected void tearDown() throws Exception
64 {
65 super.tearDown();
66 String[] tab = new String[] { "var/new.file", "var/new.directory1", "var/new.directory2" };
67 for (int i = 0; i < tab.length; i++)
68 {
69 String element = tab[i];
70 if(provider.exists(element))
71 {
72 provider.delete(element);
73 }
74 }
75 }
76
77 public void testGetName()
78 {
79 assertEquals(provider.getName(), "local");
80 }
81
82 public void testIsReadOnly()
83 {
84 assertFalse("Provider is not read only", provider.isReadOnly());
85 }
86
87 public void testCheckPathChars()
88 {
89 assertTrue(provider.checkPathChars("asciiChars"));
90 assertFalse(provider.checkPathChars(""));
91 assertFalse(provider.checkPathChars(null));
92 }
93
94 public void testExists()
95 {
96 assertTrue("File does not exist - check test resources!", provider.exists("file"));
97 assertFalse("File exists - check test resources!", provider.exists("nofile"));
98 }
99
100 public void testIsFile()
101 {
102 assertTrue("The resource is not a file - check test resources!",
103 provider.isFile("file"));
104 assertFalse("The resource is a file - check test resources!",
105 provider.isFile("directory"));
106 }
107
108 public void testIsDirectory()
109 {
110 assertTrue("The resource is not a directory - check test resources!",
111 provider.isDirectory("directory"));
112 assertFalse("The resource is a directory - check test resources!",
113 provider.isDirectory("file"));
114 }
115
116 public void testCanRead()
117 {
118 assertTrue("The resource is not readable - check test resources!",
119 provider.canRead("file"));
120 assertFalse("The resource is readable - check test resources!",
121 provider.canRead("nofile"));
122 }
123
124 private static final String UNREADABLE_PATH = "src/test/resources/unreadablefile";
125
126 public void testCanReadUnreadable()
127 throws Exception
128 {
129 if(System.getProperty("os.name").equals("Linux"))
130 {
131 Runtime.getRuntime().exec("chmod u-r "+UNREADABLE_PATH).waitFor();
132 try
133 {
134 assertTrue("The resource does not exist - check test resources!",
135 provider.exists("unreadablefile"));
136 assertFalse("The resource is readable - check test resources!",
137 provider.canRead("unreadablefile"));
138 }
139 finally
140 {
141 Runtime.getRuntime().exec("chmod u+r "+UNREADABLE_PATH);
142 }
143 }
144 }
145
146 public void testCanWrite()
147 {
148 assertTrue("The resource is not writable - check test resources!",
149 provider.canWrite("file"));
150 assertFalse("The resource is writable - check test resources!",
151 provider.canWrite("nofile"));
152 }
153
154 private static final String UNWRITABLE_PATH = "src/test/resources/unwritablefile";
155
156 public void testCanWriteUnwritable()
157 throws Exception
158 {
159 if(System.getProperty("os.name").equals("Linux"))
160 {
161 Runtime.getRuntime().exec("chmod u-w "+UNWRITABLE_PATH).waitFor();
162 try
163 {
164 assertTrue("The resource does not exist - check test resources!",
165 provider.exists("unwritablefile"));
166 assertFalse("The resource is writable - check test resources!",
167 provider.canWrite("unwritablefile"));
168 }
169 finally
170 {
171 Runtime.getRuntime().exec("chmod u+w "+UNWRITABLE_PATH);
172 }
173 }
174 }
175
176 public void testList()
177 {
178
179 }
180
181 public void testCreateNewFile()
182 throws Exception
183 {
184 assertTrue("This resource shouldn't exist - check test resources!",
185 provider.createNewFile("var/new.file"));
186 assertFalse("This resource should exist - check test resources!",
187 provider.createNewFile("file"));
188 try
189 {
190 provider.createNewFile("var/new.directory1/new.file");
191 fail("The directory shouldn't exist - check test resources!");
192 }
193 catch(IOException e)
194 {
195
196 }
197 }
198
199 public void testMkdirs()
200 throws IOException
201 {
202 try
203 {
204 provider.mkdirs("var/new.directory2");
205 assertTrue("The directory should just have been created!",
206 provider.exists("var/new.directory2"));
207 }
208 catch(UnsupportedCharactersInFilePathException e)
209 {
210 fail("simple ascii characters should be supported: "+e.getMessage());
211 }
212 }
213
214 public void testDelete()
215 {
216
217 }
218
219 public void testRename()
220 {
221
222 }
223
224 public void testGetInputStream()
225 {
226
227 }
228
229 public void testGetOutputStream()
230 {
231
232 }
233
234 public void testGetRandomAccess()
235 {
236
237 }
238
239 public void testLastModified()
240 {
241
242 }
243
244 public void testLength()
245 {
246
247 }
248
249 public void testGetFile()
250 {
251
252 }
253
254 }