Lines 47-57
import java.net.URL;
Link Here
|
47 |
import java.net.URL; |
47 |
import java.net.URL; |
48 |
import java.util.ArrayList; |
48 |
import java.util.ArrayList; |
49 |
import java.util.List; |
49 |
import java.util.List; |
|
|
50 |
import java.util.Map; |
50 |
|
51 |
|
51 |
public class XMLFileSystemTestHid extends TestBaseHid { |
52 |
public class XMLFileSystemTestHid extends TestBaseHid { |
|
|
53 |
/** Factory for all filesystems that want to use TCK in this class. |
54 |
*/ |
55 |
public static interface Factory { |
56 |
/** Creates a filesystem representing XML files at given URLs |
57 |
* |
58 |
* @param testName name of the test |
59 |
* @param layers URLs of layers to parse |
60 |
* @return new filesystem that represents those layers |
61 |
*/ |
62 |
public FileSystem createLayerSystem(String testName, URL[] layers) throws IOException; |
63 |
|
64 |
/** Assigns new URLs to existing filesystem. |
65 |
* |
66 |
* @param fs the filesystem produced by {@link #createLayerSystem(java.lang.String, java.net.URL[])} |
67 |
* @param layers new URLs that the filesystem shall switch to |
68 |
* @return true if successful, false if this operation is not supported |
69 |
*/ |
70 |
public boolean setXmlUrl(FileSystem fs, URL[] layers) throws IOException; |
71 |
} |
52 |
|
72 |
|
53 |
private String[] resources = new String[] {"a/b/c"}; |
73 |
private String[] resources = new String[] {"a/b/c"}; |
54 |
XMLFileSystem xfs = null; |
74 |
FileSystem xfs = null; |
55 |
|
75 |
|
56 |
public XMLFileSystemTestHid(String testName) { |
76 |
public XMLFileSystemTestHid(String testName) { |
57 |
super(testName); |
77 |
super(testName); |
Lines 70-90
public class XMLFileSystemTestHid extend
Link Here
|
70 |
FileChangeAdapter fcl = new FileChangeAdapter(); |
90 |
FileChangeAdapter fcl = new FileChangeAdapter(); |
71 |
a.addFileChangeListener(fcl); |
91 |
a.addFileChangeListener(fcl); |
72 |
|
92 |
|
73 |
resources = new String[] {"a/b/c","a/b1/c"}; |
93 |
resources = new String[] {"a/b/c","a/b1/c"}; |
74 |
xfs.setXmlUrl(createXMLLayer().toURL()); |
94 |
|
|
|
95 |
if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, createXMLLayer().toURL())) { |
96 |
// OK, unsupported |
97 |
return; |
98 |
} |
75 |
|
99 |
|
76 |
FileObject b1 = xfs.findResource("a/b1"); |
100 |
FileObject b1 = xfs.findResource("a/b1"); |
77 |
assertNotNull(b1); |
101 |
assertNotNull(b1); |
78 |
assertTrue(b1.isFolder()); |
102 |
assertTrue(b1.isFolder()); |
79 |
} |
103 |
} |
80 |
|
104 |
|
|
|
105 |
@Override |
81 |
protected void setUp() throws Exception { |
106 |
protected void setUp() throws Exception { |
|
|
107 |
File f = createXMLLayer(); |
108 |
xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); |
109 |
this.testedFS = xfs; |
110 |
this.allTestedFS = new FileSystem[] { xfs }; |
82 |
super.setUp(); |
111 |
super.setUp(); |
83 |
|
|
|
84 |
File f = createXMLLayer(); |
85 |
xfs = new XMLFileSystem (); |
86 |
xfs.setXmlUrl(f.toURL()); |
87 |
this.testedFS = xfs; |
88 |
} |
112 |
} |
89 |
|
113 |
|
90 |
private File createXMLLayer() throws IOException { |
114 |
private File createXMLLayer() throws IOException { |
Lines 113-125
public class XMLFileSystemTestHid extend
Link Here
|
113 |
|
137 |
|
114 |
|
138 |
|
115 |
|
139 |
|
116 |
xfs = new XMLFileSystem (f.toURL()); |
140 |
xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); |
117 |
|
141 |
|
118 |
FileObject fo = xfs.findResource ("TestModule/sample.txt"); |
142 |
FileObject fo = xfs.findResource ("TestModule/sample.txt"); |
119 |
assertEquals ("Four bytes there", 4, fo.getSize ()); |
143 |
assertEquals ("Four bytes there", 4, fo.getSize ()); |
120 |
registerDefaultListener (fo); |
144 |
registerDefaultListener (fo); |
121 |
|
145 |
|
122 |
xfs.setXmlUrl (f2.toURL ()); |
146 |
if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) { |
|
|
147 |
// OK, unsupported |
148 |
return; |
149 |
} |
123 |
|
150 |
|
124 |
assertEquals ("Six bytes there", 6, fo.getSize ()); |
151 |
assertEquals ("Six bytes there", 6, fo.getSize ()); |
125 |
|
152 |
|
Lines 149-161
public class XMLFileSystemTestHid extend
Link Here
|
149 |
|
176 |
|
150 |
|
177 |
|
151 |
|
178 |
|
152 |
xfs = new XMLFileSystem (f.toURL()); |
179 |
xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); |
153 |
|
180 |
|
154 |
FileObject fo = xfs.findResource ("TestModule/sample.txt"); |
181 |
FileObject fo = xfs.findResource ("TestModule/sample.txt"); |
155 |
assertEquals ("Four bytes there", 4, fo.getSize ()); |
182 |
assertEquals ("Four bytes there", 4, fo.getSize ()); |
156 |
registerDefaultListener (fo); |
183 |
registerDefaultListener (fo); |
157 |
|
184 |
|
158 |
xfs.setXmlUrl (f2.toURL ()); |
185 |
if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) { |
|
|
186 |
// OK, unsupported |
187 |
return; |
188 |
} |
159 |
|
189 |
|
160 |
assertEquals ("Six bytes there", 6, fo.getSize ()); |
190 |
assertEquals ("Six bytes there", 6, fo.getSize ()); |
161 |
|
191 |
|
Lines 186-198
public class XMLFileSystemTestHid extend
Link Here
|
186 |
|
216 |
|
187 |
|
217 |
|
188 |
|
218 |
|
189 |
xfs = new XMLFileSystem (f.toURL()); |
219 |
xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); |
190 |
|
220 |
|
191 |
FileObject fo = xfs.findResource ("TestModule/sample.txt"); |
221 |
FileObject fo = xfs.findResource ("TestModule/sample.txt"); |
192 |
assertEquals("Old value is in the attribute", "old", fo.getAttribute("value")); |
222 |
assertEquals("Old value is in the attribute", "old", fo.getAttribute("value")); |
193 |
registerDefaultListener (fo); |
223 |
registerDefaultListener (fo); |
194 |
|
224 |
|
195 |
xfs.setXmlUrl (f2.toURL ()); |
225 |
if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) { |
|
|
226 |
// OK, unsupported |
227 |
return; |
228 |
} |
196 |
|
229 |
|
197 |
assertEquals("New value is in the attribute", "new", fo.getAttribute("value")); |
230 |
assertEquals("New value is in the attribute", "new", fo.getAttribute("value")); |
198 |
fileAttributeChangedAssert("Change in the content", 1); |
231 |
fileAttributeChangedAssert("Change in the content", 1); |
Lines 217-229
public class XMLFileSystemTestHid extend
Link Here
|
217 |
|
250 |
|
218 |
|
251 |
|
219 |
|
252 |
|
220 |
xfs = new XMLFileSystem(f.toURL()); |
253 |
xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); |
221 |
|
254 |
|
222 |
FileObject fo = xfs.findResource("TestModule/sample.txt"); |
255 |
FileObject fo = xfs.findResource("TestModule/sample.txt"); |
223 |
assertEquals("Four bytes there", 4, fo.getSize()); |
256 |
assertEquals("Four bytes there", 4, fo.getSize()); |
224 |
registerDefaultListener(fo); |
257 |
registerDefaultListener(fo); |
225 |
|
258 |
|
226 |
xfs.setXmlUrl(f2.toURL()); |
259 |
if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) { |
|
|
260 |
// OK, unsupported |
261 |
return; |
262 |
} |
227 |
|
263 |
|
228 |
assertFalse("Valid no more", fo.isValid()); |
264 |
assertFalse("Valid no more", fo.isValid()); |
229 |
assertEquals("Empty now", 0, fo.getSize()); |
265 |
assertEquals("Empty now", 0, fo.getSize()); |
Lines 246-252
public class XMLFileSystemTestHid extend
Link Here
|
246 |
Thread.sleep(3000); |
282 |
Thread.sleep(3000); |
247 |
assertTrue(f2.createNewFile()); |
283 |
assertTrue(f2.createNewFile()); |
248 |
} |
284 |
} |
249 |
xfs = new XMLFileSystem(f.toURL()); |
285 |
xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL()); |
250 |
FileObject fo = xfs.findResource ("TestModule/sample.txt"); |
286 |
FileObject fo = xfs.findResource ("TestModule/sample.txt"); |
251 |
assertNotNull(fo); |
287 |
assertNotNull(fo); |
252 |
assertEquals(fo.lastModified().getTime(), f.lastModified()); |
288 |
assertEquals(fo.lastModified().getTime(), f.lastModified()); |
Lines 268-273
public class XMLFileSystemTestHid extend
Link Here
|
268 |
return f; |
304 |
return f; |
269 |
} |
305 |
} |
270 |
|
306 |
|
|
|
307 |
|
308 |
public void testAttribute08 () throws Exception { |
309 |
URL fsURLDef = this.getClass().getResource ("data/Attributes.xml"); |
310 |
assertTrue ("Cannot create XML FS for testing purposes", fsURLDef != null); |
311 |
FileSystem fs = FileSystemFactoryHid.createXMLSystem(getName(), this, fsURLDef); |
312 |
FileObject fo = fs.findResource("testMethodValue"); |
313 |
assertTrue ("Cannot acces FileObject named testMethodValue", fo != null); |
314 |
|
315 |
String testName = "test1"; |
316 |
Object obj = fo.getAttribute(testName); |
317 |
assertTrue ("methodValue failed", obj != null); |
318 |
assertTrue ("methodValue doesn't keep order ", |
319 |
obj.equals(getObjectViaMethodValue1 (fo, testName))); |
320 |
|
321 |
testName = "test2"; |
322 |
obj = fo.getAttribute(testName); |
323 |
assertTrue ("methodValue failed", obj != null); |
324 |
assertTrue ("methodValue doesn't keep order ", |
325 |
obj.equals(getObjectViaMethodValue2 (testName, fo))); |
326 |
|
327 |
testName = "test3"; |
328 |
obj = fo.getAttribute(testName); |
329 |
assertTrue ("methodValue failed", obj != null); |
330 |
assertTrue ("methodValue doesn't keep order ", |
331 |
obj.equals(getObjectViaMethodValue3 (fo))); |
332 |
|
333 |
testName = "test4"; |
334 |
obj = fo.getAttribute(testName); |
335 |
assertTrue ("methodValue failed", obj != null); |
336 |
assertTrue ("methodValue doesn't keep order ", |
337 |
obj.equals(getObjectViaMethodValue4 (testName))); |
338 |
|
339 |
testName = "test5"; |
340 |
obj = fo.getAttribute(testName); |
341 |
assertTrue ("methodValue failed", obj != null); |
342 |
assertTrue ("methodValue doesn't keep order ", |
343 |
obj.equals(getObjectViaMethodValue5 ())); |
344 |
|
345 |
testName = "test6"; |
346 |
obj = fo.getAttribute(testName); |
347 |
assertTrue ("methodValue failed", obj != null); |
348 |
assertEquals("even works for java.util.Map", "Ahoj1", obj); |
349 |
|
350 |
testName = "test7"; |
351 |
obj = fo.getAttribute(testName); |
352 |
assertTrue ("methodValue failed", obj != null); |
353 |
assertEquals("works for map and string", "Ahoj1test7", obj); |
354 |
|
355 |
testName = "testLoc"; |
356 |
obj = fo.getAttribute(testName); |
357 |
assertNotNull("Value returned", obj); |
358 |
assertEquals("works for bundle key", "Hello World!", obj); |
359 |
} |
360 |
|
271 |
|
361 |
|
272 |
public void testChangeOfAnAttributeInLayerIsFiredIfThereIsRealChange() throws Exception { |
362 |
public void testChangeOfAnAttributeInLayerIsFiredIfThereIsRealChange() throws Exception { |
273 |
XMLFileSystem fs = new XMLFileSystem(); |
363 |
XMLFileSystem fs = new XMLFileSystem(); |
Lines 333-362
public class XMLFileSystemTestHid extend
Link Here
|
333 |
public List<FileEvent> change = new ArrayList<FileEvent>(); |
423 |
public List<FileEvent> change = new ArrayList<FileEvent>(); |
334 |
|
424 |
|
335 |
|
425 |
|
|
|
426 |
@Override |
336 |
public void fileRenamed(FileRenameEvent fe) { |
427 |
public void fileRenamed(FileRenameEvent fe) { |
337 |
events.add(fe); |
428 |
events.add(fe); |
338 |
} |
429 |
} |
339 |
|
430 |
|
|
|
431 |
@Override |
340 |
public void fileAttributeChanged(FileAttributeEvent fe) { |
432 |
public void fileAttributeChanged(FileAttributeEvent fe) { |
341 |
events.add(fe); |
433 |
events.add(fe); |
342 |
} |
434 |
} |
343 |
|
435 |
|
|
|
436 |
@Override |
344 |
public void fileFolderCreated(FileEvent fe) { |
437 |
public void fileFolderCreated(FileEvent fe) { |
345 |
events.add(fe); |
438 |
events.add(fe); |
346 |
} |
439 |
} |
347 |
|
440 |
|
|
|
441 |
@Override |
348 |
public void fileDeleted(FileEvent fe) { |
442 |
public void fileDeleted(FileEvent fe) { |
349 |
events.add(fe); |
443 |
events.add(fe); |
350 |
} |
444 |
} |
351 |
|
445 |
|
|
|
446 |
@Override |
352 |
public void fileDataCreated(FileEvent fe) { |
447 |
public void fileDataCreated(FileEvent fe) { |
353 |
events.add(fe); |
448 |
events.add(fe); |
354 |
} |
449 |
} |
355 |
|
450 |
|
|
|
451 |
@Override |
356 |
public void fileChanged(FileEvent fe) { |
452 |
public void fileChanged(FileEvent fe) { |
357 |
change.add(fe); |
453 |
change.add(fe); |
358 |
} |
454 |
} |
359 |
|
455 |
|
360 |
} |
456 |
} |
|
|
457 |
private static String getObjectViaMethodValue1 (FileObject fo, String testName) { |
458 |
return fo.getPath()+testName; |
459 |
} |
460 |
|
461 |
private static String getObjectViaMethodValue1 (String testName, FileObject fo) { |
462 |
return testName+fo.getPath(); |
463 |
} |
464 |
|
465 |
private static String getObjectViaMethodValue1 (FileObject fo) { |
466 |
return fo.getPath(); |
467 |
} |
468 |
|
469 |
private static String getObjectViaMethodValue1 (String testName) { |
470 |
return testName; |
471 |
} |
472 |
|
473 |
private static String getObjectViaMethodValue1 () { |
474 |
return ""; |
475 |
} |
476 |
/// |
477 |
private static String getObjectViaMethodValue2 (String testName, FileObject fo) { |
478 |
return testName+fo.getPath(); |
479 |
} |
480 |
|
481 |
private static String getObjectViaMethodValue2 (FileObject fo) { |
482 |
return fo.getPath(); |
483 |
} |
484 |
|
485 |
private static String getObjectViaMethodValue2 (String testName) { |
486 |
return testName; |
487 |
} |
488 |
|
489 |
private static String getObjectViaMethodValue2 () { |
490 |
return ""; |
491 |
} |
492 |
/// |
493 |
private static String getObjectViaMethodValue3 (FileObject fo) { |
494 |
return fo.getPath(); |
495 |
} |
496 |
|
497 |
private static String getObjectViaMethodValue3 (String testName) { |
498 |
return testName; |
499 |
} |
500 |
|
501 |
private static String getObjectViaMethodValue3 () { |
502 |
return ""; |
503 |
} |
504 |
/// |
505 |
private static String getObjectViaMethodValue4 (String testName) { |
506 |
return testName; |
507 |
} |
508 |
|
509 |
private static String getObjectViaMethodValue4 () { |
510 |
return ""; |
511 |
} |
512 |
/// |
513 |
private static String getObjectViaMethodValue5 () { |
514 |
return ""; |
515 |
} |
516 |
|
517 |
private static Object getObjectViaMethodValue6 (Map attrs) { |
518 |
try { |
519 |
attrs.keySet().iterator().remove(); |
520 |
return "UnsupportedOperationException"; |
521 |
} catch (UnsupportedOperationException ex) { |
522 |
// ok |
523 |
} |
524 |
try { |
525 |
attrs.put("value1", "nothing"); |
526 |
return "UnsupportedOperationException"; |
527 |
} catch (UnsupportedOperationException ex) { |
528 |
// ok |
529 |
} |
530 |
try { |
531 |
attrs.remove("value1"); |
532 |
return "UnsupportedOperationException"; |
533 |
} catch (UnsupportedOperationException ex) { |
534 |
// ok |
535 |
} |
536 |
|
537 |
|
538 |
return attrs.get("value1"); |
539 |
} |
540 |
private static Object getObjectViaMethodValue7 (Map<String,Object> attrs, String attrName) { |
541 |
assertEquals(9, attrs.keySet().size()); |
542 |
try { |
543 |
attrs.entrySet().remove(null); |
544 |
return "UnsupportedOperationException"; |
545 |
} catch (UnsupportedOperationException ex) { |
546 |
// ok |
547 |
} |
548 |
|
549 |
|
550 |
return attrs.get("value1") + attrName; |
551 |
} |
361 |
|
552 |
|
362 |
} |
553 |
} |