1 19 20 package org.openide.loaders; 21 22 import java.net.URL ; 23 import org.netbeans.junit.NbTestCase; 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.FileSystem; 26 import org.openide.filesystems.FileUtil; 27 import org.openide.filesystems.Repository; 28 import org.openide.filesystems.URLMapper; 29 import org.openide.util.Lookup; 30 import org.openide.util.lookup.Lookups; 31 import org.openide.util.lookup.ProxyLookup; 32 33 36 public class DataShadowBrokenAreNotTestedTest extends NbTestCase { 37 38 static { 39 System.setProperty("org.openide.util.Lookup", Lkp.class.getName()); 40 } 41 42 public DataShadowBrokenAreNotTestedTest(String name) { 43 super(name); 44 } 45 46 protected void setUp() throws Exception { 47 48 FileSystem lfs = Repository.getDefault().getDefaultFileSystem(); 49 50 FileObject[] delete = lfs.getRoot().getChildren(); 51 for (int i = 0; i < delete.length; i++) { 52 delete[i].delete(); 53 } 54 55 UM.cnt = 0; 56 } 57 58 public void testNoURLMapperQueried() throws Exception { 59 FileSystem lfs = Repository.getDefault().getDefaultFileSystem(); 60 FileObject fo = FileUtil.createData(lfs.getRoot(), getName() + "/folder/original.txt"); 61 assertNotNull(fo); 62 63 assertEquals("No queries to UM yet", 0, UM.cnt); 64 DataObject original = DataObject.find(fo); 65 66 assertEquals("No queries to UM after creation of data object", 0, UM.cnt); 67 } 68 69 public void testQueriedWhenBrokenShadowsExists() throws Exception { 70 71 76 77 FileSystem lfs = Repository.getDefault().getDefaultFileSystem(); 78 FileObject f1 = FileUtil.createData(lfs.getRoot(), getName() + "/folder/original.txt"); 79 assertNotNull(f1); 80 FileObject f2 = FileUtil.createData(lfs.getRoot(), getName() + "/any/folder/original.txt"); 81 assertNotNull(f2); 82 83 assertEquals("No queries to UM yet", 0, UM.cnt); 84 DataObject original = DataObject.find(f1); 85 assertEquals("No queries to UM still", 0, UM.cnt); 86 DataShadow s = original.createShadow(original.getFolder()); 87 assertEquals("One query to create the shadow and one to create the instance", 2, UM.cnt); 88 original.delete(); 89 assertEquals("One additional query to delete", 3, UM.cnt); 90 DataObject brokenShadow = DataObject.find(s.getPrimaryFile()); 91 assertEquals("Creating one broken shadow", 5, UM.cnt); 92 93 DataObject original2 = DataObject.find(f2); 94 assertEquals("Additional query per very data object creation", 6, UM.cnt); 95 } 96 97 private static final class UM extends URLMapper { 98 public static int cnt; 99 100 public URL getURL(FileObject fo, int type) { 101 cnt++; 102 return null; 103 } 104 105 public FileObject[] getFileObjects(URL url) { 106 cnt++; 107 return null; 108 } 109 } 110 111 public static final class Lkp extends ProxyLookup { 112 public Lkp() { 113 super(new Lookup[] { 114 Lookups.singleton(new UM()), 115 Lookups.metaInfServices(Lkp.class.getClassLoader()), 116 }); 117 } 118 } 119 120 } 121 | Popular Tags |