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.FileSelectInfo; 21 import org.apache.commons.vfs.FileSelector; 22 import org.apache.commons.vfs.FileType; 23 import org.apache.commons.vfs.FileTypeSelector; 24 import org.apache.commons.vfs.Selectors; 25 26 31 public class ProviderDeleteTests 32 extends AbstractProviderTestCase 33 { 34 private class FileNameSelector implements FileSelector 35 { 36 final String basename; 37 38 private FileNameSelector(String basename) 39 { 40 this.basename = basename; 41 } 42 43 public boolean includeFile(FileSelectInfo fileInfo) throws Exception 44 { 45 return this.basename.equals(fileInfo.getFile().getName().getBaseName()); 46 } 47 48 public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception 49 { 50 return true; 51 } 52 } 53 54 57 protected Capability[] getRequiredCaps() 58 { 59 return new Capability[] 60 { 61 Capability.CREATE, 62 Capability.DELETE, 63 Capability.GET_TYPE, 64 Capability.LIST_CHILDREN, 65 }; 66 } 67 68 71 protected FileObject createScratchFolder() throws Exception 72 { 73 FileObject scratchFolder = getWriteFolder(); 74 75 scratchFolder.delete(Selectors.EXCLUDE_SELF); 77 scratchFolder.createFolder(); 78 79 final FileObject dir1 = scratchFolder.resolveFile("dir1"); 80 dir1.createFolder(); 81 final FileObject dir1file1 = dir1.resolveFile("a.txt"); 82 dir1file1.createFile(); 83 final FileObject dir2 = scratchFolder.resolveFile("dir2"); 84 dir2.createFolder(); 85 final FileObject dir2file1 = dir2.resolveFile("b.txt"); 86 dir2file1.createFile(); 87 88 return scratchFolder; 89 } 90 91 94 public void testDeleteFiles() throws Exception 95 { 96 final FileObject scratchFolder = createScratchFolder(); 97 98 assertEquals(scratchFolder.delete(Selectors.EXCLUDE_SELF), 4); 99 } 100 101 104 public void testDeleteFile() throws Exception 105 { 106 final FileObject scratchFolder = createScratchFolder(); 107 108 final FileObject file = scratchFolder.resolveFile("dir1/a.txt"); 109 110 assertTrue(file.delete()); 111 } 112 113 116 public void testDeleteNonExistantFile() throws Exception 117 { 118 final FileObject scratchFolder = createScratchFolder(); 119 120 final FileObject file = scratchFolder.resolveFile("dir1/aa.txt"); 121 122 assertFalse(file.delete()); 123 } 124 125 128 public void testDeleteAllFiles() throws Exception 129 { 130 final FileObject scratchFolder = createScratchFolder(); 131 132 assertEquals(scratchFolder.delete(new FileTypeSelector(FileType.FILE)), 2); 133 } 134 135 138 public void testDeleteOneFiles() throws Exception 139 { 140 final FileObject scratchFolder = createScratchFolder(); 141 142 assertEquals(scratchFolder.delete(new FileNameSelector("a.txt")), 1); 143 } 144 } 145 | Popular Tags |