1 19 20 package org.netbeans.core.lookup; 21 22 import javax.swing.Action ; 23 import org.netbeans.core.LoaderPoolNode; 24 import org.openide.cookies.InstanceCookie; 25 import org.openide.filesystems.FileAttributeEvent; 26 import org.openide.filesystems.FileChangeListener; 27 import org.openide.filesystems.FileEvent; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileRenameEvent; 30 import org.openide.filesystems.FileUtil; 31 import org.openide.filesystems.Repository; 32 import org.openide.loaders.DataObject; 33 34 38 public class InstanceDataObjectModuleTest8 extends InstanceDataObjectModuleTestHid 39 implements FileChangeListener { 40 41 47 48 private boolean instanceSaved; 49 50 public InstanceDataObjectModuleTest8(String name) { 51 super(name); 52 } 53 54 protected void setUp() throws Exception { 55 Repository.getDefault ().getDefaultFileSystem ().addFileChangeListener (this); 56 assertNotNull("have org-netbeans-modules-settings.jar in CP", InstanceDataObjectModuleTest7.class.getResource("/org/netbeans/modules/settings/resources/Bundle.properties")); 57 super.setUp(); 58 } 59 60 protected void tearDown () throws java.lang.Exception { 61 Repository.getDefault ().getDefaultFileSystem ().removeFileChangeListener (this); 62 super.tearDown (); 63 } 64 65 68 public void testFixedSettingsChangeInstanceAfterFastReload() throws Exception { 69 twiddle(m2, TWIDDLE_ENABLE); 70 DataObject obj1; 71 try { 72 obj1 = findIt("Services/Misc/inst-8.settings"); 73 ERR.log("Found obj1: " + obj1); 74 assertEquals("No saved state for inst-8.settings", null, FileUtil.toFile(obj1.getPrimaryFile())); 75 InstanceCookie inst1 = (InstanceCookie)obj1.getCookie(InstanceCookie.class); 76 ERR.log("There is a cookie: " + inst1); 77 assertNotNull("Had an instance", inst1); 78 Action a1 = (Action )inst1.instanceCreate(); 79 assertEquals("Correct action class", "test2.SomeAction", a1.getClass().getName()); 80 assertTrue("Old version of action", a1.isEnabled()); 81 82 ERR.log("Action created" + a1); 83 84 synchronized (this) { 86 ERR.log("In sync block"); 87 a1.setEnabled(false); 88 ERR.log("setEnabled(false)"); 89 ERR.log("Waiting"); 91 wait (60000); 92 ERR.log("Waiting done"); 93 assertTrue ("Really was saved", instanceSaved); 94 } 95 99 104 ERR.log("Twidle reload"); 105 twiddle(m2, TWIDDLE_RELOAD); 106 ERR.log("TWIDDLE_RELOAD done"); 107 LoaderPoolNode.waitFinished(); 108 ERR.log("pool refeshed"); 109 DataObject obj2 = findIt("Services/Misc/inst-8.settings"); 110 ERR.log("Data object for inst-8: " + obj2); 111 assertSameDataObject ("same data object", obj1, obj2); 112 InstanceCookie inst2 = (InstanceCookie)obj2.getCookie(InstanceCookie.class); 113 ERR.log("Cookie from the object: " + inst2); 114 assertNotNull("Had an instance", inst2); 115 assertTrue("InstanceCookie changed", inst1 != inst2); 116 Action a2 = (Action )inst2.instanceCreate(); 117 ERR.log("Action2 created: " + a2); 118 assertTrue("Action changed", a1 != a2); 119 assertTrue("Correct action", "SomeAction".equals(a2.getValue(Action.NAME))); 120 assertTrue("New version of action", !a2.isEnabled()); 121 } finally { 122 ERR.log("Final disable"); 123 twiddle(m2, TWIDDLE_DISABLE); 124 ERR.log("Final disable done"); 125 } 126 LoaderPoolNode.waitFinished(); 128 ERR.log("loader pool node refreshed"); 129 DataObject obj3 = findIt("Services/Misc/inst-8.settings"); 130 ERR.log("Third data object: " + obj3); 131 assertSameDataObject ("same data object2", obj1, obj3); 132 InstanceCookie inst3 = (InstanceCookie)obj3.getCookie(InstanceCookie.class); 133 ERR.log("Cookie is here: " + inst3); 134 assertNull("Had instance", inst3); 135 } 136 137 138 public void fileAttributeChanged(FileAttributeEvent fe) {} 139 140 public synchronized void fileChanged(FileEvent fe) { 141 if ("inst-8.settings".equals (fe.getFile ().getNameExt ())) { 142 instanceSaved = true; 143 notifyAll (); 144 } 145 } 146 147 public void fileDataCreated(FileEvent fe) {} 148 149 public void fileDeleted(FileEvent fe) { 150 if ("inst-8.settings".equals (fe.getFile ().getNameExt ())) { 151 FileObject isThere = Repository.getDefault ().getDefaultFileSystem ().findResource (fe.getFile ().getPath ()); 152 fail ("File " + fe.getFile () + " should not be deleted as this will discard the data object. Moreover it is expected that similar file is still there: " + isThere); 153 } 154 } 155 156 public void fileFolderCreated(FileEvent fe) {} 157 158 public void fileRenamed(FileRenameEvent fe) {} 159 160 } 161 | Popular Tags |