KickJava   Java API By Example, From Geeks To Geeks.

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


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 module with generated
34  * @author Jaroslav Tulach
35  */

36 public class PlatformDependencySatisfiedTest extends SetupHid {
37     private File JavaDoc moduleJarFile;
38
39     public PlatformDependencySatisfiedTest(String JavaDoc name) {
40         super(name);
41     }
42     
43     protected void setUp() throws Exception JavaDoc {
44         super.setUp();
45         System.setProperty("org.netbeans.core.modules.NbInstaller.noAutoDeps", "true");
46         Main.getModuleSystem (); // init module system
47

48         File JavaDoc tmp = File.createTempFile ("PlatformDependencySatisfiedModule", ".jar");
49         moduleJarFile = tmp;
50
51         // clean the operatingSystem field
52
java.lang.reflect.Field JavaDoc f;
53         f = org.openide.util.Utilities.class.getDeclaredField("operatingSystem");
54         f.setAccessible(true);
55         f.set(null, new Integer JavaDoc(-1));
56     }
57     
58     public void testWindows2000() throws Exception JavaDoc {
59         System.setProperty("os.name", "Windows 2000");
60         assertTrue("We are on windows", org.openide.util.Utilities.isWindows());
61         
62         assertEnableModule("org.openide.modules.os.Windows", true);
63         assertEnableModule("org.openide.modules.os.MacOSX", false);
64         assertEnableModule("org.openide.modules.os.Unix", false);
65         assertEnableModule("org.openide.modules.os.PlainUnix", false);
66         assertEnableModule("org.openide.modules.os.Garbage", false);
67         assertEnableModule("org.openide.modules.os.OS2", false);
68     }
69     
70     public void testMacOSX() throws Exception JavaDoc {
71         System.setProperty("os.name", "Mac OS X");
72         assertTrue("We are on mac", (org.openide.util.Utilities.getOperatingSystem() & org.openide.util.Utilities.OS_MAC) != 0);
73         
74         assertEnableModule("org.openide.modules.os.Windows", false);
75         assertEnableModule("org.openide.modules.os.MacOSX", true);
76         assertEnableModule("org.openide.modules.os.Unix", true);
77         assertEnableModule("org.openide.modules.os.PlainUnix", false);
78         assertEnableModule("org.openide.modules.os.Garbage", false);
79         assertEnableModule("org.openide.modules.os.OS2", false);
80     }
81
82     public void testDarwin() throws Exception JavaDoc {
83         System.setProperty("os.name", "Darwin");
84         assertTrue("We are on mac", (org.openide.util.Utilities.getOperatingSystem() & org.openide.util.Utilities.OS_MAC) != 0);
85         
86         assertEnableModule("org.openide.modules.os.Windows", false);
87         assertEnableModule("org.openide.modules.os.MacOSX", true);
88         assertEnableModule("org.openide.modules.os.Unix", true);
89         assertEnableModule("org.openide.modules.os.PlainUnix", false);
90         assertEnableModule("org.openide.modules.os.Garbage", false);
91         assertEnableModule("org.openide.modules.os.OS2", false);
92     }
93     
94     public void testLinux() throws Exception JavaDoc {
95         System.setProperty("os.name", "Fedora Linux");
96         assertTrue("We are on linux", (org.openide.util.Utilities.getOperatingSystem() & org.openide.util.Utilities.OS_LINUX) != 0);
97         
98         assertEnableModule("org.openide.modules.os.Windows", false);
99         assertEnableModule("org.openide.modules.os.MacOSX", false);
100         assertEnableModule("org.openide.modules.os.Unix", true);
101         assertEnableModule("org.openide.modules.os.PlainUnix", true);
102         assertEnableModule("org.openide.modules.os.Garbage", false);
103         assertEnableModule("org.openide.modules.os.OS2", false);
104     }
105
106     public void testBSD() throws Exception JavaDoc {
107         System.setProperty("os.name", "FreeBSD X1.4");
108         assertTrue("We are on unix", org.openide.util.Utilities.isUnix());
109         
110         assertEnableModule("org.openide.modules.os.Windows", false);
111         assertEnableModule("org.openide.modules.os.MacOSX", false);
112         assertEnableModule("org.openide.modules.os.Unix", true);
113         assertEnableModule("org.openide.modules.os.PlainUnix", true);
114         assertEnableModule("org.openide.modules.os.Garbage", false);
115         assertEnableModule("org.openide.modules.os.OS2", false);
116     }
117
118     public void testOS2() throws Exception JavaDoc {
119         System.setProperty("os.name", "OS/2");
120         assertEquals ("We are on os/2", org.openide.util.Utilities.OS_OS2, org.openide.util.Utilities.getOperatingSystem());
121         
122         assertEnableModule("org.openide.modules.os.Windows", false);
123         assertEnableModule("org.openide.modules.os.MacOSX", false);
124         assertEnableModule("org.openide.modules.os.Unix", false);
125         assertEnableModule("org.openide.modules.os.PlainUnix", false);
126         assertEnableModule("org.openide.modules.os.Garbage", false);
127         assertEnableModule("org.openide.modules.os.OS2", true);
128     }
129     
130     /** */
131     private void assertEnableModule(String JavaDoc req, boolean enable) throws Exception JavaDoc {
132         Manifest man = new Manifest ();
133         man.getMainAttributes ().putValue ("Manifest-Version", "1.0");
134         man.getMainAttributes ().putValue ("OpenIDE-Module", "org.test.PlatformDependency/1");
135         man.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
136         
137         man.getMainAttributes ().putValue ("OpenIDE-Module-Requires", req);
138         
139         JarOutputStream os = new JarOutputStream (new FileOutputStream (moduleJarFile), man);
140         os.putNextEntry (new JarEntry ("empty/test.txt"));
141         os.close ();
142         
143         
144         final FakeEvents ev = new FakeEvents();
145         org.netbeans.core.startup.NbInstaller installer = new org.netbeans.core.startup.NbInstaller(ev);
146         ModuleManager mgr = new ModuleManager(installer, ev);
147         ModuleFormatSatisfiedTest.addOpenideModules(mgr);
148         installer.registerManager(mgr);
149         mgr.mutexPrivileged().enterWriteAccess();
150         try {
151             Module m1 = mgr.create(moduleJarFile, null, false, false, false);
152             
153             
154             if (enable) {
155                 assertEquals(Collections.EMPTY_SET, m1.getProblems());
156                 mgr.enable(m1);
157                 mgr.disable(m1);
158             } else {
159                 assertFalse("We should not be able to enable the module", m1.getProblems().isEmpty());
160             }
161             mgr.delete(m1);
162         } finally {
163             mgr.mutexPrivileged().exitWriteAccess();
164         }
165     }
166
167 }
168
Popular Tags