Lines 41-51
Link Here
|
41 |
|
41 |
|
42 |
package org.openide.filesystems; |
42 |
package org.openide.filesystems; |
43 |
|
43 |
|
|
|
44 |
import java.beans.PropertyVetoException; |
44 |
import java.util.ArrayList; |
45 |
import java.util.ArrayList; |
45 |
import java.util.Collections; |
46 |
import java.util.Collections; |
46 |
import java.util.Iterator; |
47 |
import java.util.Iterator; |
47 |
import java.util.List; |
48 |
import java.util.List; |
48 |
import org.netbeans.junit.NbTestCase; |
49 |
import org.netbeans.junit.NbTestCase; |
|
|
50 |
import org.openide.filesystems.test.TestFileUtils; |
49 |
|
51 |
|
50 |
// XXX should only *unused* mask files be listed when propagateMasks? |
52 |
// XXX should only *unused* mask files be listed when propagateMasks? |
51 |
// XXX write similar test for ParsingLayerCacheManager (simulate propagateMasks) |
53 |
// XXX write similar test for ParsingLayerCacheManager (simulate propagateMasks) |
Lines 249-252
Link Here
|
249 |
|
251 |
|
250 |
// XXX test create -> mask -> recreate in same MFS |
252 |
// XXX test create -> mask -> recreate in same MFS |
251 |
|
253 |
|
|
|
254 |
@SuppressWarnings("deprecation") // for debugging only |
255 |
private static void setSystemName(FileSystem fs, String s) throws PropertyVetoException { |
256 |
fs.setSystemName(s); |
257 |
} |
258 |
public void testWeightedOverrides() throws Exception { // #141925 |
259 |
FileSystem wr = FileUtil.createMemoryFileSystem(); |
260 |
setSystemName(wr, "wr"); |
261 |
FileSystem fs1 = FileUtil.createMemoryFileSystem(); |
262 |
setSystemName(fs1, "fs1"); |
263 |
FileObject f = TestFileUtils.writeFile(fs1.getRoot(), "d/f", "1"); |
264 |
f.setAttribute("a", 1); |
265 |
FileSystem fs2 = FileUtil.createMemoryFileSystem(); |
266 |
setSystemName(fs2, "fs2"); |
267 |
f = TestFileUtils.writeFile(fs2.getRoot(), "d/f", "2"); |
268 |
f.setAttribute("a", 2); |
269 |
// Test behavior with no weights: first layer wins. |
270 |
FileSystem mfs = new MultiFileSystem(new FileSystem[] {wr, fs1, fs2}); |
271 |
f = mfs.findResource("d/f"); |
272 |
assertEquals(1, f.getAttribute("a")); |
273 |
assertEquals("1", TestFileUtils.readFile(f)); |
274 |
mfs = new MultiFileSystem(new FileSystem[] {wr, fs2, fs1}); |
275 |
f = mfs.findResource("d/f"); |
276 |
assertEquals(2, f.getAttribute("a")); |
277 |
assertEquals("2", TestFileUtils.readFile(f)); |
278 |
// Now test that weighted layer wins over unweighted regardless of order. |
279 |
fs2.findResource("d/f").setAttribute("weight", 100); |
280 |
mfs = new MultiFileSystem(new FileSystem[] {wr, fs1, fs2}); |
281 |
f = mfs.findResource("d/f"); |
282 |
assertEquals(2, f.getAttribute("a")); |
283 |
assertEquals("2", TestFileUtils.readFile(f)); |
284 |
mfs = new MultiFileSystem(new FileSystem[] {wr, fs2, fs1}); |
285 |
f = mfs.findResource("d/f"); |
286 |
assertEquals(2, f.getAttribute("a")); |
287 |
assertEquals("2", TestFileUtils.readFile(f)); |
288 |
// And that a higher weight beats a lower weight. |
289 |
fs1.findResource("d/f").setAttribute("weight", 200); |
290 |
mfs = new MultiFileSystem(new FileSystem[] {wr, fs1, fs2}); |
291 |
f = mfs.findResource("d/f"); |
292 |
assertEquals(1, f.getAttribute("a")); |
293 |
assertEquals("1", TestFileUtils.readFile(f)); |
294 |
mfs = new MultiFileSystem(new FileSystem[] {wr, fs2, fs1}); |
295 |
f = mfs.findResource("d/f"); |
296 |
assertEquals(1, f.getAttribute("a")); |
297 |
assertEquals("1", TestFileUtils.readFile(f)); |
298 |
// Now test writable layer which should always win regardless of weights. |
299 |
mfs = new MultiFileSystem(new FileSystem[] {wr, fs1, fs2}); |
300 |
f = mfs.findResource("d/f"); |
301 |
f.setAttribute("a", 0); |
302 |
TestFileUtils.writeFile(mfs.getRoot(), "d/f", "0"); |
303 |
f = wr.findResource("d/f"); |
304 |
// Oddly, it is null: assertEquals(0, f.getAttribute("a")); |
305 |
assertEquals("0", TestFileUtils.readFile(f)); |
306 |
mfs = new MultiFileSystem(new FileSystem[] {wr, fs1, fs2}); |
307 |
f = mfs.findResource("d/f"); |
308 |
assertEquals(0, f.getAttribute("a")); |
309 |
assertEquals("0", TestFileUtils.readFile(f)); |
310 |
} |
311 |
|
252 |
} |
312 |
} |