1 19 20 package org.openide.loaders; 21 22 import org.openide.filesystems.*; 23 24 import java.beans.*; 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.util.ArrayList ; 28 import java.util.Arrays ; 29 30 import org.netbeans.junit.*; 31 32 37 public class DataFolderRefreshTest extends LoggingTestCaseHid { 38 private ArrayList hold = new ArrayList (); 39 private org.openide.ErrorManager err; 40 41 private FileObject root; 42 43 44 public DataFolderRefreshTest (String name) { 45 super (name); 46 } 47 48 protected void setUp () throws Exception { 49 err = org.openide.ErrorManager.getDefault().getInstance("TEST-" + getName()); 50 51 registerIntoLookup(new FolderInstanceTest.Pool()); 52 53 DataLoaderPool pool = DataLoaderPool.getDefault (); 54 assertNotNull (pool); 55 assertEquals (FolderInstanceTest.Pool.class, pool.getClass ()); 56 57 clearWorkDir (); 58 59 root = FileUtil.createFolder( 60 Repository.getDefault().getDefaultFileSystem().getRoot(), 61 "dir" 62 ); 63 64 FileUtil.createData(root, "s1.simple"); 65 FileUtil.createData(root, "s2.simple"); 66 } 67 68 public void testIsChangeFired() throws Exception { 69 DataLoader l = DataLoader.getLoader(DataLoaderOrigTest.SimpleUniFileLoader.class); 70 err.log("Add loader: " + l); 71 FolderInstanceTest.Pool.setExtra(l); 72 err.log("Loader added"); 73 74 DataFolder f = DataFolder.findFolder(root); 75 class C implements PropertyChangeListener { 76 PropertyChangeEvent ev; 77 78 public void propertyChange(PropertyChangeEvent evt) { 79 assertNull("Only one event", this.ev); 80 this.ev = evt; 81 } 82 } 83 84 C c = new C(); 85 f.addPropertyChangeListener(c); 86 87 DataObject[] arr = f.getChildren(); 88 89 assertEquals("Two objects", 2, arr.length); 90 assertEquals("Loader1", arr[0].getLoader(), l); 91 assertEquals("Loader2", arr[1].getLoader(), l); 92 93 FolderInstanceTest.Pool.setExtra(null); 94 95 arr = f.getChildren(); 96 97 assertNotNull("A change event delivered", c.ev); 98 assertEquals("children", DataFolder.PROP_CHILDREN, c.ev.getPropertyName()); 99 100 101 assertEquals("Two objects", 2, arr.length); 102 assertEquals("Loader1", arr[0].getLoader(), DataLoaderPool.getDefaultFileLoader()); 103 assertEquals("Loader2", arr[1].getLoader(), DataLoaderPool.getDefaultFileLoader()); 104 } 105 } 106 | Popular Tags |