KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > startup > NbInstallerTest8


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.startup;
21
22 import java.io.*;
23 import java.lang.reflect.Field JavaDoc;
24 import java.lang.reflect.Method JavaDoc;
25 import java.util.*;
26 import org.netbeans.Module;
27 import org.netbeans.ModuleManager;
28 import org.netbeans.core.startup.ModuleHistory;
29 import org.netbeans.junit.*;
30 import junit.textui.TestRunner;
31 import org.netbeans.core.startup.layers.SessionManager;
32 import org.openide.filesystems.FileSystem;
33
34 /** Test the NetBeans module installer implementation.
35  * Broken into pieces to ensure each runs in its own VM.
36  * @author Jesse Glick
37  */

38 public class NbInstallerTest8 extends SetupHid {
39     
40     public NbInstallerTest8(String JavaDoc name) {
41         super(name);
42     }
43     
44     public static void main(String JavaDoc[] args) {
45         // Turn on verbose logging while developing tests:
46
System.setProperty("org.netbeans.core.modules", "0");
47         // In case run standalone, need a work dir.
48
if (System.getProperty("nbjunit.workdir") == null) {
49             // Hope java.io.tmpdir is set...
50
System.setProperty("nbjunit.workdir", System.getProperty("java.io.tmpdir"));
51         }
52         TestRunner.run(new NbTestSuite(NbInstallerTest8.class));
53     }
54     
55     private static File home, user, homeMod, userMod;
56     private File moduleJar;
57     protected void setUp() throws Exception JavaDoc {
58         super.setUp();
59         System.setProperty("org.netbeans.core.modules.NbInstaller.noAutoDeps", "true");
60         // leave NO_COMPAT_AUTO_TRANSITIVE_DEPS=false
61
moduleJar = new File(jars, "look-for-myself.jar");
62     }
63     
64     /** Test #28465: Lookup<ModuleInfo> should be ready soon, even while
65      * modules are still loading. The ModuleInfo need not claim to be enabled
66      * during this time, but it must exist.
67      */

68     public void testEarlyModuleInfoLookup() throws Exception JavaDoc {
69         // Ought to load these modules:
70
ModuleManager mgr = Main.getModuleSystem().getManager();
71         mgr.mutexPrivileged().enterWriteAccess();
72         try {
73             Module m = mgr.get("lookformyself");
74             assertNull(m);
75             m = mgr.create(moduleJar, new ModuleHistory(moduleJar.getAbsolutePath()), false, false, false);
76             assertEquals("look-for-myself.jar can be enabled", Collections.EMPTY_SET, m.getProblems());
77             mgr.enable(m);
78             Class JavaDoc c = m.getClassLoader().loadClass("lookformyself.Loder");
79             Method JavaDoc meth = c.getMethod("foundNow", null);
80             assertTrue("ModuleInfo is found after startup", ((Boolean JavaDoc)meth.invoke(null, null)).booleanValue());
81             Field JavaDoc f = c.getField("foundEarly");
82             assertTrue("ModuleInfo is found during dataloader section initialization", ((Boolean JavaDoc)f.get(null)).booleanValue());
83         } finally {
84             mgr.mutexPrivileged().exitWriteAccess();
85         }
86     }
87     
88 }
89
Popular Tags