Example usage for org.apache.commons.vfs FileObject canRenameTo

List of usage examples for org.apache.commons.vfs FileObject canRenameTo

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject canRenameTo.

Prototype

public boolean canRenameTo(FileObject newfile);

Source Link

Document

Queries the file if it is possible to rename it to newfile.

Usage

From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java

public void testFolders() throws Exception {
    // root object
    FileObject rootObject = testRootObject();

    // create folder
    FileObject testFolder = testCreateTestFolder(rootObject);

    // create sub-folders
    FileObject subFolder = testFolder.resolveFile("abc/def/ghi");
    assertFalse(subFolder.exists());/*  w ww.j a  va 2s  . c o  m*/
    subFolder.createFolder();
    assertFolder(subFolder);
    assertSubFolders(testFolder, new String[] { "abc/def/ghi", "abc/def", "abc" });
    assertEntity(rootObject);

    // rename
    FileObject srcFolder = testFolder.resolveFile("abc/def");
    FileObject destFolder = testFolder.resolveFile("abc/xyz");
    assertTrue(testFolder.canRenameTo(destFolder));
    srcFolder.moveTo(destFolder);
    assertFolder(destFolder);
    assertFalse(srcFolder.exists());
    assertSubFolders(testFolder, new String[] { "abc/xyz/ghi", "abc/xyz", "abc" });

    // TODO: test moving a folder to a different parent

    // delete
    assertTrue(testFolder.exists());
    testFolder.delete(Selectors.SELECT_ALL);
    assertFalse(testFolder.exists());
}