Lines 324-329
Link Here
|
324 |
value.equals((String)fo3.getAttribute(attrName)) ); |
324 |
value.equals((String)fo3.getAttribute(attrName)) ); |
325 |
fileDataCreatedAssert("parent should fire fileDataCreated",1); |
325 |
fileDataCreatedAssert("parent should fire fileDataCreated",1); |
326 |
} |
326 |
} |
|
|
327 |
|
328 |
public void testCreateAndOpen() throws Exception { |
329 |
checkSetUp(); |
330 |
FileObject f; |
331 |
try { |
332 |
f = getTestFolder1(root).createFolder("createAndOpen"); |
333 |
} catch (IOException iex) { |
334 |
fsAssert("If read only FS, then OK to fail", |
335 |
fs.isReadOnly()); |
336 |
return; |
337 |
} |
338 |
final FileObject fold = f; |
339 |
|
340 |
class L extends FileChangeAdapter { |
341 |
String dataCreated; |
342 |
String changed; |
343 |
|
344 |
@Override |
345 |
public synchronized void fileDataCreated(FileEvent fe) { |
346 |
try { |
347 |
FileObject ch = fold.getFileObject("child.txt"); |
348 |
assertNotNull("Child found", ch); |
349 |
|
350 |
dataCreated = ch.asText(); |
351 |
notifyAll(); |
352 |
} catch (IOException ex) { |
353 |
throw new IllegalStateException(ex); |
354 |
} |
355 |
} |
356 |
|
357 |
@Override |
358 |
public synchronized void fileChanged(FileEvent fe) { |
359 |
try { |
360 |
FileObject ch = fold.getFileObject("child.txt"); |
361 |
assertNotNull("Child found", ch); |
362 |
|
363 |
changed = ch.asText(); |
364 |
notifyAll(); |
365 |
} catch (IOException ex) { |
366 |
throw new IllegalStateException(ex); |
367 |
} |
368 |
} |
369 |
|
370 |
|
371 |
public synchronized void waitEvents() throws InterruptedException { |
372 |
for (int i = 0; i < 100; i++) { |
373 |
if (changed != null && dataCreated != null) { |
374 |
break; |
375 |
} |
376 |
wait(100); |
377 |
} |
378 |
} |
379 |
} |
380 |
|
381 |
L l = new L(); |
382 |
fold.addFileChangeListener(l); |
383 |
assertEquals("No children", 0, fold.getChildren().length); |
384 |
|
385 |
OutputStream os = fold.createAndOpen("child.txt"); |
386 |
os.write("Ahoj".getBytes()); |
387 |
os.close(); |
388 |
|
389 |
FileObject ch = fold.getFileObject("child.txt"); |
390 |
assertNotNull("Child found", ch); |
391 |
assertEquals("Right content now", "Ahoj", ch.asText()); |
392 |
|
393 |
l.waitEvents(); |
394 |
assertEquals("Right content when changed", "Ahoj", l.changed); |
395 |
assertEquals("Right content when created", "Ahoj", l.dataCreated); |
396 |
} |
327 |
|
397 |
|
328 |
/** Test of copy method, of class org.openide.filesystems.FileObject. */ |
398 |
/** Test of copy method, of class org.openide.filesystems.FileObject. */ |
329 |
public void testCopy1_FS() throws IOException { |
399 |
public void testCopy1_FS() throws IOException { |