use of org.apache.derby.impl.io.vfmem.DataStore 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.DataStore 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.
}
}
use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.
the class VirtualFileTest method testRenameToSimple.
public void testRenameToSimple() {
DataStore store = getStore();
VirtualFile vFile = new VirtualFile("originalFile", store);
assertFalse(vFile.canWrite());
vFile.createNewFile();
assertTrue(vFile.canWrite());
VirtualFile newFile = new VirtualFile("newFile", store);
assertFalse(newFile.exists());
assertTrue(vFile.renameTo(newFile));
assertFalse(vFile.exists());
assertFalse(vFile.canWrite());
assertTrue(newFile.exists());
}
use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.
the class VirtualFileTest method testGetParentRelative.
public void testGetParentRelative() {
DataStore store = getStore();
VirtualFile vFile = new VirtualFile(PathUtilTest.join(NON_EXISTING_DIRS), store);
int count = 0;
StorageFile parent = vFile.getParentDir();
while (parent != null) {
count++;
parent = parent.getParentDir();
}
assertEquals(4, count);
}
use of org.apache.derby.impl.io.vfmem.DataStore in project derby by apache.
the class VirtualFileTest method testCreateDirInRoot.
public void testCreateDirInRoot() {
DataStore store = getStore();
VirtualFile vFile = new VirtualFile("seg0", store);
assertFalse(vFile.exists());
vFile.mkdir();
assertTrue(vFile.exists());
assertTrue(vFile.isDirectory());
}
Aggregations