1 19 20 package org.openide.filesystems; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import org.netbeans.junit.NbTestCase; 27 28 31 35 public class MultiFileSystemMaskTest extends NbTestCase { 36 37 public MultiFileSystemMaskTest(String name) { 38 super(name); 39 } 40 41 private static String childrenNames(FileSystem fs) { 43 FileObject folder = fs.findResource("folder"); 44 return childrenNames(folder); 45 } 46 47 private static String childrenNames(FileObject folder) { 48 FileObject[] kids = folder.getChildren(); 49 List <String > l = new ArrayList <String >(); 50 for (int i = 0; i < kids.length; i++) { 51 l.add(kids[i].getNameExt()); 52 } 53 Collections.sort(l); 54 StringBuffer b = new StringBuffer (); 55 Iterator i = l.iterator(); 56 if (i.hasNext()) { 57 b.append(i.next()); 58 while (i.hasNext()) { 59 b.append('/'); 60 b.append(i.next()); 61 } 62 } 63 return b.toString(); 64 } 65 66 69 public void testRepeatedMasks() throws Exception { 70 MultiFileSystem fs = new MultiFileSystem(new FileSystem[] { 71 TestUtilHid.createXMLFileSystem(getName() + "1", new String [] { 72 "folder/file1_hidden", 73 "folder/file2_hidden", 74 }), 75 TestUtilHid.createXMLFileSystem(getName() + "2", new String [] { 76 "folder/file1", 77 "folder/file2", 78 }), 79 TestUtilHid.createXMLFileSystem(getName() + "3", new String [] { 80 "folder/file1", 81 "folder/file3", 82 }), 83 }); 84 fs.setPropagateMasks(false); 85 try { 86 assertEquals("folder/file1_hidden masked two occurrences of folder/file1 and folder/file2_hidden masked one occurrence of folder/file2", 87 "file3", 88 childrenNames(fs)); 89 } finally { 90 TestUtilHid.destroyXMLFileSystem(getName() + "1"); 91 TestUtilHid.destroyXMLFileSystem(getName() + "2"); 92 TestUtilHid.destroyXMLFileSystem(getName() + "3"); 93 } 94 } 95 public void testRepeatedMasksPropagate() throws Exception { 96 MultiFileSystem fs = new MultiFileSystem(new FileSystem[] { 97 TestUtilHid.createXMLFileSystem(getName() + "1", new String [] { 98 "folder/file1_hidden", 99 "folder/file2_hidden", 100 }), 101 TestUtilHid.createXMLFileSystem(getName() + "2", new String [] { 102 "folder/file1", 103 "folder/file2", 104 }), 105 TestUtilHid.createXMLFileSystem(getName() + "3", new String [] { 106 "folder/file1", 107 "folder/file3", 108 }), 109 }); 110 fs.setPropagateMasks(true); 111 try { 112 assertEquals("folder/file1_hidden masked two occurrences of folder/file1 and folder/file2_hidden masked one occurrence of folder/file2", 113 "file1_hidden/file2_hidden/file3", 114 childrenNames(fs)); 115 } finally { 116 TestUtilHid.destroyXMLFileSystem(getName() + "1"); 117 TestUtilHid.destroyXMLFileSystem(getName() + "2"); 118 TestUtilHid.destroyXMLFileSystem(getName() + "3"); 119 } 120 } 121 122 125 public void testOutOfOrderMasks() throws Exception { 126 MultiFileSystem fs = new MultiFileSystem(new FileSystem[] { 127 TestUtilHid.createXMLFileSystem(getName() + "1", new String [] { 128 "folder/file1", 129 "folder/file2", 130 }), 131 TestUtilHid.createXMLFileSystem(getName() + "2", new String [] { 132 "folder/file2_hidden", 133 "folder/file3_hidden", 134 }), 135 TestUtilHid.createXMLFileSystem(getName() + "3", new String [] { 136 "folder/file3", 137 }), 138 }); 139 fs.setPropagateMasks(false); 140 try { 141 assertEquals("folder/file2_hidden did not mask an earlier file but folder/file3_hidden masked a later one", 142 "file1/file2", 143 childrenNames(fs)); 144 } finally { 145 TestUtilHid.destroyXMLFileSystem(getName() + "1"); 146 TestUtilHid.destroyXMLFileSystem(getName() + "2"); 147 TestUtilHid.destroyXMLFileSystem(getName() + "3"); 148 } 149 } 150 178 179 182 public void testParallelMasks() throws Exception { 183 MultiFileSystem fs = new MultiFileSystem(new FileSystem[] { 184 TestUtilHid.createXMLFileSystem(getName() + "1", new String [] { 185 "folder/file1", 186 }), 187 TestUtilHid.createXMLFileSystem(getName() + "2", new String [] { 188 "folder/file2", 189 "folder/file2_hidden", 190 "folder/file3", 191 }), 192 }); 193 fs.setPropagateMasks(false); 194 try { 195 assertEquals("folder/file2_hidden does not mask a file from the same layer", 196 "file1/file2/file3", 197 childrenNames(fs)); 198 } finally { 199 TestUtilHid.destroyXMLFileSystem(getName() + "1"); 200 TestUtilHid.destroyXMLFileSystem(getName() + "2"); 201 } 202 } 203 227 228 230 } 231 | Popular Tags |