You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2012/05/16 20:09:18 UTC
svn commit: r1339292 -
/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderRenameTests.java
Author: ggregory
Date: Wed May 16 18:09:18 2012
New Revision: 1339292
URL: http://svn.apache.org/viewvc?rev=1339292&view=rev
Log:
Test for [VFS-298] FTP: Exception is thrown when renaming a file.
Modified:
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderRenameTests.java
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderRenameTests.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderRenameTests.java?rev=1339292&r1=1339291&r2=1339292&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderRenameTests.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/ProviderRenameTests.java Wed May 16 18:09:18 2012
@@ -16,10 +16,13 @@
*/
package org.apache.commons.vfs2.test;
+import java.io.IOException;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import org.apache.commons.vfs2.Capability;
import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.Selectors;
/**
@@ -60,17 +63,27 @@ public class ProviderRenameTests
return scratchFolder;
}
- /**
- * Tests create-delete-create-a-file sequence on the same file system.
- */
- public void testRenameFile() throws Exception
+ private void moveFile(final FileObject scratchFolder, final FileObject file, final String content)
+ throws FileSystemException, Exception
{
- final FileObject scratchFolder = createScratchFolder();
+ FileObject fileMove = scratchFolder.resolveFile("file1move.txt");
+ assertTrue(!fileMove.exists());
+
+ file.moveTo(fileMove);
- // Create direct child of the test folder
- final FileObject file = scratchFolder.resolveFile("file1.txt");
assertTrue(!file.exists());
+ assertTrue(fileMove.exists());
+
+ assertSameContent(content, fileMove);
+ // Delete the file.
+ assertTrue(fileMove.exists());
+ assertTrue(fileMove.delete());
+ }
+
+ private String createTestFile(final FileObject file) throws FileSystemException, IOException,
+ UnsupportedEncodingException, Exception
+ {
// Create the source file
final String content = "Here is some sample content for the file. Blah Blah Blah.";
@@ -84,22 +97,44 @@ public class ProviderRenameTests
os.close();
}
assertSameContent(content, file);
+ return content;
+ }
+ /**
+ * Tests create-delete-create-a-file sequence on the same file system.
+ */
+ public void testRenameFile() throws Exception
+ {
+ final FileObject scratchFolder = createScratchFolder();
- // Make sure we can move the new file to another file on the same filesystem
+ // Create direct child of the test folder
+ final FileObject file = scratchFolder.resolveFile("file1.txt");
+ assertTrue(!file.exists());
- FileObject fileMove = scratchFolder.resolveFile("file1move.txt");
- assertTrue(!fileMove.exists());
+ final String content = createTestFile(file);
- file.moveTo(fileMove);
+ // Make sure we can move the new file to another file on the same file system
+ moveFile(scratchFolder, file, content);
+ }
+ /**
+ * Moves a file from a child folder to a parent folder to test what happens when the original folder is now empty.
+ *
+ * See [VFS-298] FTP: Exception is thrown when renaming a file.
+ */
+ public void testRenameFileAndLeaveFolderEmpty() throws Exception
+ {
+ final FileObject scratchFolder = createScratchFolder();
+ final FileObject folder = scratchFolder.resolveFile("folder");
+ folder.createFolder();
+ assertTrue(folder.exists());
+ final FileObject file = folder.resolveFile("file1.txt");
assertTrue(!file.exists());
- assertTrue(fileMove.exists());
- assertSameContent(content, fileMove);
+ final String content = createTestFile(file);
- // Delete the file.
- assertTrue(fileMove.exists());
- assertTrue(fileMove.delete());
- }
+ // Make sure we can move the new file to another file on the same file system
+ moveFile(scratchFolder, file, content);
+ assertTrue(folder.getChildren().length == 0);
+ }
}