1 19 20 package org.netbeans.core.startup; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Collections ; 25 import java.util.jar.JarFile ; 26 import java.util.jar.Manifest ; 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 36 public class NbInstallerTest9 extends SetupHid { 37 38 public NbInstallerTest9(String name) { 39 super(name); 40 } 41 42 public static void main(String [] args) { 43 System.setProperty("org.netbeans.core.modules", "0"); 45 if (System.getProperty("nbjunit.workdir") == null) { 47 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 { 54 super.setUp(); 55 clearWorkDir(); 56 File workdir = getWorkDir(); 57 String [] jarnames = new String [] { 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 (jars, jarnames[i]), new File (workdir, jarnames[i])); 64 } 65 } 66 67 69 public void testManifestCaching() throws Exception { 70 File workdir = getWorkDir(); 71 System.setProperty("netbeans.user", workdir.getAbsolutePath()); 72 ModuleInstaller inst = new org.netbeans.core.startup.NbInstaller(new FakeEvents()); 73 File littleJar = new File (workdir, "little-manifest.jar"); 74 assertEquals(getManifest(littleJar), inst.loadManifest(littleJar)); 76 File mediumJar = new File (workdir, "medium-manifest.jar"); 77 assertEquals(getManifest(mediumJar), inst.loadManifest(mediumJar)); 78 File bigJar = new File (workdir, "big-manifest.jar"); 79 assertEquals(getManifest(bigJar), inst.loadManifest(bigJar)); 80 inst.load(Collections.EMPTY_LIST); 82 File allManifestsDat = new File (new File (new File (workdir, "var"), "cache"), "all-manifests.dat"); 83 assertTrue("File " + allManifestsDat + " exists", allManifestsDat.isFile()); 84 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 getManifest(File jar) throws IOException { 92 JarFile jf = new JarFile (jar); 93 try { 94 return jf.getManifest(); 95 } finally { 96 jf.close(); 97 } 98 } 99 100 } 101 | Popular Tags |