KickJava   Java API By Example, From Geeks To Geeks.

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


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.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.jar.JarFile JavaDoc;
26 import java.util.jar.Manifest JavaDoc;
27 import junit.textui.TestRunner;
28 import org.netbeans.ModuleInstaller;
29 import org.netbeans.core.startup.SetupHid.FakeEvents;
30 import org.netbeans.junit.NbTestSuite;
31
32 /** Test the NetBeans module installer implementation.
33  * Broken into pieces to ensure each runs in its own VM.
34  * @author Jesse Glick
35  */

36 public class NbInstallerTest9 extends SetupHid {
37
38     public NbInstallerTest9(String JavaDoc name) {
39         super(name);
40     }
41     
42     public static void main(String JavaDoc[] args) {
43         // Turn on verbose logging while developing tests:
44
System.setProperty("org.netbeans.core.modules", "0");
45         // In case run standalone, need a work dir.
46
if (System.getProperty("nbjunit.workdir") == null) {
47             // Hope java.io.tmpdir is set...
48
System.setProperty("nbjunit.workdir", System.getProperty("java.io.tmpdir"));
49         }
50         TestRunner.run(new NbTestSuite(NbInstallerTest9.class));
51     }
52     
53     protected void setUp() throws Exception JavaDoc {
54         super.setUp();
55         clearWorkDir();
56         File JavaDoc workdir = getWorkDir();
57         String JavaDoc[] jarnames = new String JavaDoc[] {
58             "little-manifest.jar",
59             "medium-manifest.jar",
60             "big-manifest.jar",
61         };
62         for (int i = 0; i < jarnames.length; i++) {
63             copy(new File JavaDoc(jars, jarnames[i]), new File JavaDoc(workdir, jarnames[i]));
64         }
65     }
66     
67     /** Test #26786/#28755: manifest caching can be buggy.
68      */

69     public void testManifestCaching() throws Exception JavaDoc {
70         File JavaDoc workdir = getWorkDir();
71         System.setProperty("netbeans.user", workdir.getAbsolutePath());
72         ModuleInstaller inst = new org.netbeans.core.startup.NbInstaller(new FakeEvents());
73         File JavaDoc littleJar = new File JavaDoc(workdir, "little-manifest.jar");
74         //inst.loadManifest(littleJar).write(System.out);
75
assertEquals(getManifest(littleJar), inst.loadManifest(littleJar));
76         File JavaDoc mediumJar = new File JavaDoc(workdir, "medium-manifest.jar");
77         assertEquals(getManifest(mediumJar), inst.loadManifest(mediumJar));
78         File JavaDoc bigJar = new File JavaDoc(workdir, "big-manifest.jar");
79         assertEquals(getManifest(bigJar), inst.loadManifest(bigJar));
80         // trigger cache saving - this is sort of a hack, there is no API to do it
81
inst.load(Collections.EMPTY_LIST);
82         File JavaDoc allManifestsDat = new File JavaDoc(new File JavaDoc(new File JavaDoc(workdir, "var"), "cache"), "all-manifests.dat");
83         assertTrue("File " + allManifestsDat + " exists", allManifestsDat.isFile());
84         // Create a new NbInstaller, since otherwise it turns off caching...
85
inst = new org.netbeans.core.startup.NbInstaller(new FakeEvents());
86         assertEquals(getManifest(littleJar), inst.loadManifest(littleJar));
87         assertEquals(getManifest(mediumJar), inst.loadManifest(mediumJar));
88         assertEquals(getManifest(bigJar), inst.loadManifest(bigJar));
89     }
90     
91     private static Manifest JavaDoc getManifest(File JavaDoc jar) throws IOException JavaDoc {
92         JarFile JavaDoc jf = new JarFile JavaDoc(jar);
93         try {
94             return jf.getManifest();
95         } finally {
96             jf.close();
97         }
98     }
99     
100 }
101
Popular Tags