File tmpRoot = File.createTempFile("vfs", ".root");
tmpRoot.delete();
tmpRoot.mkdir();
File tmp = File.createTempFile("testFileContextZipDelete", ".jar", tmpRoot);
VFS vfs = VFS.getVFS(tmpRoot.toURI().toURL());
Manifest mf = new Manifest();
mf.getMainAttributes().putValue("Created-By", getClass().getName() + "." + "testEntryModified");
FileOutputStream fos = new FileOutputStream(tmp);
JarOutputStream jos = new JarOutputStream(fos, mf);
try
{
jos.setComment("testJarURLs");
jos.setLevel(0);
jos.flush();
}
finally
{
jos.close();
}
// children() exist
List<VirtualFile> children = vfs.getChildren();
assertTrue(tmpRoot + ".getChildren().size() == 1", children.size() == 1);
// specific child exists()
VirtualFile tmpVF = vfs.getChild(tmp.getName());
assertTrue(tmp + ".exists()", tmpVF.exists());
// test jar entry
// specific zip entry exists(), delete() not, exists()
VirtualFile entryVF = tmpVF.getChild("META-INF");
assertTrue(entryVF.getName() + " .exists()", entryVF.exists());
assertFalse(entryVF.getName() + " .delete() == false", entryVF.delete());
assertTrue(entryVF.getName() + " .exists()", entryVF.exists());
// children() exist
children = tmpVF.getChildren();
assertTrue(tmpVF + ".getChildren().size() == 1", children.size() == 1);
// getChild() returns not-null
entryVF = tmpVF.getChild("META-INF");
assertNotNull(tmpVF + ".getChild('META-INF') != null", entryVF);
// continue with jar
// specific child delete(), exists() not
assertTrue(tmp + ".delete()", tmpVF.delete());
assertFalse(tmp + ".exists() == false", tmpVF.exists());
// children() don't exist
children = vfs.getChildren();
assertTrue(tmpRoot + ".getChildren().size() == 0", children.size() == 0);
// getChild() returns null
tmpVF = vfs.getChild(tmp.getName());
assertNull(tmpRoot + ".getChild('" + tmp.getName() + "') == null", tmpVF);
// directory delete()
assertTrue(tmpRoot + ".delete()", vfs.getRoot().delete());
}