I'm trying to use commons-vfs as a filesystem wrapper in order to more easily unit test some code that needs to touch the filesystem. Right now I'm just getting familiar with the API. What I would like to do is create a virtual filesystem, and add a couple of files (a folder and then a file in that folder to the root).
Here's a test class I've written to testdrive the API:
public class CommonsVfsLearningSpikeTest extends Base {
FileSystemManager fsManager;
FileObject rootVFS;
@Before public void createFixture() throws Exception{
this.fsManager = VFS.getManager();
this.rootVFS = fsManager.createVirtualFileSystem("rootVfs");
}
@Test public void testCreationOfDefaultFileSystem() throws Exception {
assertNotNull(fsManager);
}
@Test public void testCreationOfVFS() throws Exception {
//root file has an empty base name
assertEquals("", rootVFS.getName().getBaseName());
}
@Test public void testCreationOfChildrenFiles() throws Exception {
FileObject childFolder = rootVFS.resolveFile("childFolder");
childFolder.createFolder();
assertNotNull(childFolder );
FileObject childFile = rootVFS.resolveFile("childFolder/childFile");
childFile.createFile();
assertNotNull(childFile);
}
}
Currently I'm getting the following error:
[junit] Testcase: testCreationOfChildrenFiles(com.usengineeringsolutions.bridgewatch.vfs.CommonsVfsLearningSpikeTest): Caused an ERROR [junit] Incorrect file system URI "file:///" in name "file:///rootVfs/childFolder", was expecting "/rootVfs/". [junit] org.apache.commons.vfs.FileSystemException: Incorrect file system URI "file:///" in name "file:///rootVfs/childFolder", was expecting "/rootVfs/". [junit] at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:274) [junit] at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:267) [junit] at org.apache.commons.vfs.provider.AbstractFileObject.resolveFile(AbstractFileObject.java:670) [junit] at com.usengineeringsolutions.bridgewatch.vfs.CommonsVfsLearningSpikeTest.testCreationOfChildrenFiles(CommonsVfsLearningSpikeTest.java:27) [junit] [junit]