KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Locale JavaDoc;
26 import java.util.jar.*;
27 import org.netbeans.Module;
28 import org.netbeans.ModuleManager;
29 import org.netbeans.junit.*;
30 import junit.textui.TestRunner;
31 import org.openide.filesystems.Repository;
32
33 /** Checks whether a modules are provided with ModuleFormat1 token.
34  *
35  * @author Jaroslav Tulach
36  */

37 public class ModuleFormatSatisfiedTest extends SetupHid {
38     private File JavaDoc moduleJarFile;
39
40     public ModuleFormatSatisfiedTest(String JavaDoc name) {
41         super(name);
42     }
43     
44     protected void setUp() throws Exception JavaDoc {
45         super.setUp();
46         System.setProperty("org.netbeans.core.modules.NbInstaller.noAutoDeps", "true");
47         
48         File JavaDoc tmp = File.createTempFile ("ModuleFormatTest", ".jar");
49         moduleJarFile = tmp;
50         
51         Manifest man = new Manifest ();
52         man.getMainAttributes ().putValue ("Manifest-Version", "1.0");
53         man.getMainAttributes ().putValue ("OpenIDE-Module", "org.test.FormatDependency/1");
54         
55         
56         String JavaDoc req = "org.openide.modules.ModuleFormat1";
57         
58         man.getMainAttributes ().putValue ("OpenIDE-Module-Requires", req);
59         
60         JarOutputStream os = new JarOutputStream (new FileOutputStream (tmp), man);
61         os.putNextEntry (new JarEntry ("empty/test.txt"));
62         os.close ();
63     }
64     
65     /** */
66     public void testTryToInstallTheModule () throws Exception JavaDoc {
67         Main.getModuleSystem (); // init module system
68

69         
70         
71         
72         final FakeEvents ev = new FakeEvents();
73         org.netbeans.core.startup.NbInstaller installer = new org.netbeans.core.startup.NbInstaller(ev);
74         ModuleManager mgr = new ModuleManager(installer, ev);
75         installer.registerManager(mgr);
76         mgr.mutexPrivileged().enterWriteAccess();
77         try {
78             addOpenideModules(mgr);
79             Module m1 = mgr.create(moduleJarFile, null, false, false, false);
80             assertEquals(Collections.EMPTY_SET, m1.getProblems());
81             mgr.enable(m1);
82             mgr.disable(m1);
83             mgr.delete(m1);
84         } finally {
85             mgr.mutexPrivileged().exitWriteAccess();
86         }
87     }
88
89     
90     static void addOpenideModules (ModuleManager mgr) throws Exception JavaDoc {
91         ClassLoader JavaDoc l = SetupHid.class.getClassLoader();
92         String JavaDoc openide =
93 "Manifest-Version: 1.0\n" +
94 "OpenIDE-Module: org.openide.modules\n" +
95 "OpenIDE-Module-Localizing-Bundle: org/openide/modules/Bundle.properties\n" +
96 "Specification-Title: NetBeans\n" +
97 "OpenIDE-Module-Specification-Version: 6.2\n" +
98 "\n" +
99 "Name: /org/openide/modules/\n" +
100 "Package-Title: org.openide.modules\n";
101                
102         Manifest mani = new Manifest (new java.io.ByteArrayInputStream JavaDoc (openide.getBytes ()));
103         mgr.enable(mgr.createFixed(mani, null, l));
104      }
105
106     
107 }
108
Popular Tags