1 19 20 package org.netbeans.core.lookup; 21 22 import org.netbeans.core.LoaderPoolNode; 23 import org.netbeans.junit.*; 24 import junit.textui.TestRunner; 25 26 import java.io.File ; 27 import org.netbeans.Module; 28 import org.netbeans.ModuleManager; 29 import org.netbeans.core.NbTopManager; 30 import org.netbeans.core.startup.ModuleHistory; 31 import org.openide.util.Lookup; 32 import javax.swing.Action ; 33 import java.util.Iterator ; 34 import org.openide.loaders.DataObject; 35 import org.openide.filesystems.FileObject; 36 import org.openide.filesystems.Repository; 37 import org.openide.util.Mutex; 38 import org.openide.cookies.InstanceCookie; 39 import org.openide.util.MutexException; 40 import org.openide.util.LookupListener; 41 import org.openide.util.LookupEvent; 42 43 47 public class InstanceDataObjectModuleTest5 extends InstanceDataObjectModuleTestHid { 48 49 public InstanceDataObjectModuleTest5(String name) { 50 super(name); 51 } 52 53 public void testReloadSettingsSwitchesLookupByNewClass() throws Exception { 54 ERR.log("before twidle enabled"); 55 twiddle(m2, TWIDDLE_ENABLE); 56 ERR.log("Ok twidle enable"); 57 ClassLoader l1 = null; 58 ClassLoader l2 = null; 59 try { 60 l1 = m2.getClassLoader(); 61 Class c1 = l1.loadClass("test2.SomeAction"); 62 assertEquals("Correct loader", l1, c1.getClassLoader()); 63 assertTrue("SomeAction<1> instance found after module installation", 64 existsSomeAction(c1)); 65 66 ERR.log("Action successfully checked, reload"); 67 twiddle(m2, TWIDDLE_RELOAD); 68 ERR.log("Twidle reload"); 69 l2 = m2.getClassLoader(); 70 assertTrue("ClassLoader really changed", l1 != l2); 71 Class c2 = l2.loadClass("test2.SomeAction"); 72 assertTrue("Class really changed", c1 != c2); 73 74 ERR.log("After successful checks that there was a reload changes"); 75 76 LoaderPoolNode.waitFinished(); 77 78 ERR.log("Waiting for pool node to update itself"); 79 80 assertTrue("SomeAction<1> instance not found after module reload", 81 !existsSomeAction(c1)); 82 assertTrue("SomeAction<2> instance found after module reload", 83 existsSomeAction(c2)); 84 } finally { 85 ERR.log("Verify why it failed"); 86 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("Services/Misc/inst-2.settings"); 87 ERR.log("File object found: " + fo); 88 if (fo != null) { 89 DataObject obj = DataObject.find(fo); 90 ERR.log("data object found: " + obj); 91 InstanceCookie ic = (InstanceCookie)obj.getCookie(InstanceCookie.class); 92 ERR.log("InstanceCookie: " + ic); 93 if (ic != null) { 94 ERR.log("value: " + ic.instanceCreate()); 95 ERR.log(" cl : " + ic.instanceCreate().getClass().getClassLoader()); 96 ERR.log(" l1 : " + l1); 97 ERR.log(" l2 : " + l2); 98 } 99 } 100 ERR.log("Disabling"); 101 twiddle(m2, TWIDDLE_DISABLE); 102 ERR.log("Disabled"); 103 } 104 } 105 106 } 107 | Popular Tags |