1 19 20 package org.netbeans.core.startup.layers; 21 22 import java.net.URL ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.List ; 26 import junit.textui.TestRunner; 27 import org.netbeans.junit.NbTestSuite; 28 import org.openide.filesystems.FileAttributeEvent; 29 import org.openide.filesystems.FileChangeListener; 30 import org.openide.filesystems.FileEvent; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileRenameEvent; 33 import org.openide.filesystems.FileSystem; 34 import org.openide.filesystems.MultiFileSystem; 35 39 public class BinaryCacheManagerTest extends CacheManagerTestBaseHid 40 implements CacheManagerTestBaseHid.ManagerFactory { 41 42 public BinaryCacheManagerTest(String name) { 43 super(name); 44 } 45 46 public static void main(String [] args) { 47 if (System.getProperty("nbjunit.workdir") == null) { 48 System.setProperty("nbjunit.workdir", System.getProperty("java.io.tmpdir")); 50 } 51 System.setProperty("org.openide.util.Lookup", "-"); 52 System.setProperty("org.netbeans.core.projects.cache", "0"); 53 TestRunner.run(new NbTestSuite(BinaryCacheManagerTest.class)); 54 } 55 56 protected void setUp() throws Exception { 57 super.setUp(); 58 clearWorkDir(); 59 } 60 61 public LayerCacheManager createManager() throws Exception { 65 return new BinaryCacheManager(getWorkDir()); 66 } 67 68 public boolean supportsTimestamps () { 69 return true; 70 } 71 72 73 77 public void testFastReplacement() throws Exception { 78 clearWorkDir(); 79 LayerCacheManager m = new BinaryCacheManager(getWorkDir()); 80 assertFalse(m.cacheExists()); 81 List urls = new ArrayList (Arrays.asList(new URL [] { 83 BinaryCacheManagerTest.class.getResource("data/layer2.xml"), 84 BinaryCacheManagerTest.class.getResource("data/layer1.xml"), 85 })); 86 FileSystem f = m.store(urls); 87 assertTrue(m.cacheExists()); 88 FixedFileSystem base = new FixedFileSystem("ffs", "FFS"); 89 base.add("baz/thongy", new FixedFileSystem.Instance(false, null, null, null, (URL )null)); 90 final MFS mfs = new MFS(new FileSystem[] {base, f}); 91 FileObject baz = mfs.findResource("baz"); 92 assertNotNull(baz); 93 assertEquals(2, baz.getChildren().length); 94 FileObject thingy = mfs.findResource("baz/thingy"); 95 assertNotNull(thingy); 96 L l = new L (); 97 baz.addFileChangeListener(l); 98 urls.remove(0); 100 f = m.store(urls); 101 final FileSystem[] fss = new FileSystem[] {base, f}; 102 mfs.runAtomicAction(new FileSystem.AtomicAction() { 103 public void run() { 104 mfs._setDelegates(fss); 105 } 106 }); 107 assertEquals(2, baz.getChildren().length); 108 assertTrue(thingy.isValid()); 109 assertEquals(0, l.ac); 110 assertEquals(0, l.c); 111 assertEquals(0, l.dc); 112 assertEquals(0, l.d); 113 assertEquals(0, l.fc); 114 assertEquals(0, l.r); 115 urls.remove(0); 116 f = m.store(urls); 117 final FileSystem[] fss2 = new FileSystem[] {base, f}; 118 mfs.runAtomicAction(new FileSystem.AtomicAction() { 119 public void run() { 120 mfs._setDelegates(fss2); 121 } 122 }); 123 assertEquals(1, baz.getChildren().length); 124 assertFalse(thingy.isValid()); 125 assertEquals(0, l.ac); 126 assertEquals(0, l.c); 127 assertEquals(0, l.dc); 128 assertEquals(1, l.d); 129 assertEquals(0, l.fc); 130 assertEquals(0, l.r); 131 } 132 133 private static final class MFS extends MultiFileSystem { 135 public MFS(FileSystem[] fss) { 136 super(fss); 137 } 138 public void _setDelegates(FileSystem[] fss) { 139 setDelegates(fss); 140 } 141 } 142 143 private static final class L implements FileChangeListener { 144 public int ac = 0, c = 0, dc = 0, d = 0, fc = 0, r = 0; 145 public void fileAttributeChanged(FileAttributeEvent fe) { 146 System.err.println("ac: " + fe.getFile().getPath()); 147 ac++; 148 } 149 public void fileChanged(FileEvent fe) { 150 System.err.println("c: " + fe.getFile().getPath()); 151 c++; 152 } 153 public void fileDataCreated(FileEvent fe) { 154 System.err.println("dc: " + fe.getFile().getPath()); 155 dc++; 156 } 157 public void fileDeleted(FileEvent fe) { 158 System.err.println("d: " + fe.getFile().getPath()); 159 d++; 160 } 161 public void fileFolderCreated(FileEvent fe) { 162 System.err.println("fc: " + fe.getFile().getPath()); 163 fc++; 164 } 165 public void fileRenamed(FileRenameEvent fe) { 166 System.err.println("r: " + fe.getFile().getPath()); 167 r++; 168 } 169 } 170 171 } 172 | Popular Tags |