use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.
the class VirtualFileTest method testMkdirsInvalidRelative.
public void testMkdirsInvalidRelative() throws IOException {
DataStore store = getStore();
VirtualFile tmp = new VirtualFile("seg0", store);
assertTrue(tmp.mkdir());
tmp = new VirtualFile(PathUtilTest.join("seg0", "datafile"), store);
assertTrue(tmp.createNewFile());
assertTrue(tmp.exists());
assertFalse(tmp.isDirectory());
VirtualFile vFile = new VirtualFile(PathUtilTest.join("seg0", "datafile", "anotherdir"), store);
assertFalse(vFile.mkdir());
assertFalse(vFile.mkdirs());
}
use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.
the class VirtualFileTest method testMkdirsValidAbsolute.
public void testMkdirsValidAbsolute() {
DataStore store = getStore();
VirtualFile vFile = new VirtualFile(PathUtilTest.joinAbs(NON_EXISTING_DIRS), store);
assertTrue(vFile.mkdirs());
}
use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.
the class VirtualFileTest method testDeleteAll.
public void testDeleteAll() throws IOException {
DataStore store = getStore();
String[] dirs = new String[] { "seg0", PathUtilTest.join("seg0", "dir1"), "seg1", PathUtilTest.join("seg0", "dir2") };
for (int i = 0; i < dirs.length; i++) {
assertTrue(new VirtualFile(dirs[i], store).mkdir());
}
String[] files = new String[] { PathUtilTest.join("seg0", "f1"), PathUtilTest.join("seg0", "dir1", "f1"), PathUtilTest.join("seg1", "f1"), PathUtilTest.join("seg0", "f5") };
for (int i = 0; i < files.length; i++) {
assertTrue(new VirtualFile(files[i], store).createNewFile());
}
String root = "seg0";
VirtualFile rootToDelete = new VirtualFile(root, store);
assertTrue(rootToDelete.deleteAll());
for (int i = 0; i < dirs.length; i++) {
assertEquals(!dirs[i].startsWith(root), new VirtualFile(dirs[i], store).exists());
}
for (int i = 0; i < files.length; i++) {
assertEquals(!files[i].startsWith(root), new VirtualFile(files[i], store).exists());
}
}
use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.
the class VirtualFileTest method testGetRAFOnDirectory.
/**
* Opening a random access file on a directory should fail.
*/
public void testGetRAFOnDirectory() {
DataStore store = getStore();
VirtualFile vFile = new VirtualFile("mydir", store);
assertTrue(vFile.mkdir());
assertTrue(vFile.exists());
assertTrue(vFile.isDirectory());
// Try opening in read mode.
try {
vFile.getRandomAccessFile("r");
fail("Opening a RAF on a directory should have failed");
} catch (FileNotFoundException fnfe) {
// Expected.
}
// Try opening in write mode.
try {
vFile.getRandomAccessFile("r");
fail("Opening a RAF on a directory should have failed");
} catch (FileNotFoundException fnfe) {
// Expected.
}
// A few sanity checks.
assertTrue(vFile.exists());
assertTrue(vFile.isDirectory());
}
use of org.apache.derby.impl.io.vfmem.VirtualFile in project derby by apache.
the class VirtualFileTest method testGetRAExistingReadOnly.
/**
* Opens a random access file for a file which has been marked as read-only.
* <p>
* Opening for reading only should work, opening for writing should fail.
*/
public void testGetRAExistingReadOnly() throws FileNotFoundException {
DataStore store = getStore();
VirtualFile vFile = new VirtualFile("aNewFile.txt", store);
assertFalse(vFile.exists());
assertTrue(vFile.createNewFile());
assertTrue(vFile.exists());
assertTrue(vFile.setReadOnly());
assertNotNull(vFile.getRandomAccessFile("r"));
// Try opening in write mode, which should fail.
try {
vFile.getRandomAccessFile("rw");
fail("Should not be able to open a read-only file in write mode");
} catch (FileNotFoundException fnfe) {
// Expected.
}
}
Aggregations