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 InstanceDataObjectModuleTest4 extends InstanceDataObjectModuleTestHid { 48 49 public InstanceDataObjectModuleTest4(String name) { 50 super(name); 51 } 52 53 56 public void testReloadDotInstanceSwitchesLookupByNewClass() throws Exception { 57 twiddle(m1, TWIDDLE_ENABLE); 58 ClassLoader l1 = null, l2 = null; 59 try { 60 l1 = m1.getClassLoader(); 61 Class c1 = l1.loadClass("test1.SomeAction"); 62 assertEquals("Correct loader", l1, c1.getClassLoader()); 63 assertTrue("SomeAction<1> instance found after module installation", 64 existsSomeAction(c1)); 65 66 ClassLoader g1 = Lookup.getDefault().lookup(ClassLoader .class); 67 ERR.log("Before reload: " + g1); 68 twiddle(m1, TWIDDLE_RELOAD); 69 ClassLoader g2 = Lookup.getDefault().lookup(ClassLoader .class); 70 ERR.log("After reload: " + g2); 71 l2 = m1.getClassLoader(); 73 assertTrue("ClassLoader really changed", l1 != l2); 74 Class c2 = l2.loadClass("test1.SomeAction"); 75 assertTrue("Class really changed", c1 != c2); 76 77 assertTrue("Glboal Class loaders really changed", g1 != g2); 78 79 80 LoaderPoolNode.waitFinished(); 81 ERR.log("After waitFinished"); 82 assertTrue("SomeAction<1> instance not found after module reload", 83 !existsSomeAction(c1)); 84 assertTrue("SomeAction<2> instance found after module reload", 85 existsSomeAction(c2)); 86 } finally { 87 ERR.log("Verify why it failed"); 88 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("Services/Misc/inst-1.instance"); 89 ERR.log("File object found: " + fo); 90 if (fo != null) { 91 DataObject obj = DataObject.find(fo); 92 ERR.log("data object found: " + obj); 93 InstanceCookie ic = (InstanceCookie)obj.getCookie(InstanceCookie.class); 94 ERR.log("InstanceCookie: " + ic); 95 if (ic != null) { 96 ERR.log("value: " + ic.instanceCreate()); 97 ERR.log(" cl : " + ic.instanceCreate().getClass().getClassLoader()); 98 ERR.log(" l1 : " + l1); 99 ERR.log(" l2 : " + l2); 100 } 101 } 102 103 ERR.log("Before disable"); 104 twiddle(m1, TWIDDLE_DISABLE); 105 } 106 } 107 108 111 public void testReloadSettingsSwitchesLookupByNewClass() throws Exception { 112 assertTrue("There is initially nothing in lookup", 113 !existsSomeAction(Action .class)); 114 twiddle(m2, TWIDDLE_ENABLE); 115 try { 116 ClassLoader l1 = m2.getClassLoader(); 117 Class c1 = l1.loadClass("test2.SomeAction"); 118 assertEquals("Correct loader", l1, c1.getClassLoader()); 119 assertTrue("SomeAction<1> instance found after module installation", 120 existsSomeAction(c1)); 121 122 ERR.log("Before reload"); 123 twiddle(m2, TWIDDLE_RELOAD); 124 ERR.log("After reload"); 125 ClassLoader l2 = m2.getClassLoader(); 126 assertTrue("ClassLoader really changed", l1 != l2); 127 Class c2 = l2.loadClass("test2.SomeAction"); 128 assertTrue("Class really changed", c1 != c2); 129 LoaderPoolNode.waitFinished(); 131 ERR.log("After waitFinished"); 132 133 assertTrue("SomeAction<1> instance not found after module reload", 134 !existsSomeAction(c1)); 135 assertTrue("SomeAction<2> instance found after module reload", 136 existsSomeAction(c2)); 137 } finally { 138 ERR.log("Finally disable"); 139 twiddle(m2, TWIDDLE_DISABLE); 140 } 141 } 142 143 } 144 | Popular Tags |