1 16 package org.apache.commons.vfs.test; 17 18 import org.apache.commons.vfs.Capability; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.Selectors; 21 22 import java.io.OutputStream ; 23 24 29 public class ProviderRenameTests 30 extends AbstractProviderTestCase 31 { 32 35 protected Capability[] getRequiredCaps() 36 { 37 return new Capability[] 38 { 39 Capability.CREATE, 40 Capability.DELETE, 41 Capability.GET_TYPE, 42 Capability.LIST_CHILDREN, 43 Capability.READ_CONTENT, 44 Capability.WRITE_CONTENT, 45 Capability.RENAME 46 }; 47 } 48 49 52 protected FileObject createScratchFolder() throws Exception 53 { 54 FileObject scratchFolder = getWriteFolder(); 55 56 scratchFolder.delete(Selectors.EXCLUDE_SELF); 58 scratchFolder.createFolder(); 59 60 return scratchFolder; 61 } 62 63 66 public void testRenameFile() throws Exception 67 { 68 final FileObject scratchFolder = createScratchFolder(); 69 70 final FileObject file = scratchFolder.resolveFile("file1.txt"); 72 assertTrue(!file.exists()); 73 74 final String content = "Here is some sample content for the file. Blah Blah Blah."; 76 77 final OutputStream os = file.getContent().getOutputStream(); 78 try 79 { 80 os.write(content.getBytes("utf-8")); 81 } 82 finally 83 { 84 os.close(); 85 } 86 assertSameContent(content, file); 87 88 89 91 FileObject fileMove = scratchFolder.resolveFile("file1move.txt"); 92 assertTrue(!fileMove.exists()); 93 94 file.moveTo(fileMove); 95 96 assertTrue(!file.exists()); 97 assertTrue(fileMove.exists()); 98 99 assertSameContent(content, fileMove); 100 101 assertTrue(fileMove.exists()); 103 assertTrue(fileMove.delete()); 104 } 105 } 106 | Popular Tags |