KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > lookup > InstanceDataObjectModuleTest5


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
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 JavaDoc;
33 import java.util.Iterator JavaDoc;
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 /** A test.
44  * @author Jesse Glick
45  * @see InstanceDataObjectModuleTestHid
46  */

47 public class InstanceDataObjectModuleTest5 extends InstanceDataObjectModuleTestHid {
48
49     public InstanceDataObjectModuleTest5(String JavaDoc name) {
50         super(name);
51     }
52     
53     public void testReloadSettingsSwitchesLookupByNewClass() throws Exception JavaDoc {
54         ERR.log("before twidle enabled");
55         twiddle(m2, TWIDDLE_ENABLE);
56         ERR.log("Ok twidle enable");
57         ClassLoader JavaDoc l1 = null;
58         ClassLoader JavaDoc l2 = null;
59         try {
60             l1 = m2.getClassLoader();
61             Class JavaDoc 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 JavaDoc 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