KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projects > TestPlatforms


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 /*
21  * TestCreatePlatforms.java
22  * NetBeans JUnit based test
23  *
24  * Created on 14 September 2004, 15:37
25  */

26
27 package projects;
28
29 import java.io.InputStream JavaDoc;
30
31 import java.net.InetAddress JavaDoc;
32 import java.net.UnknownHostException JavaDoc;
33 import java.util.Properties JavaDoc;
34 import org.netbeans.jellytools.JellyTestCase;
35
36 import org.netbeans.junit.*;
37 import junit.framework.*;
38
39 import org.netbeans.api.java.platform.JavaPlatformManager;
40 import org.netbeans.api.java.platform.JavaPlatform;
41
42 /**
43  *
44  */

45 public class TestPlatforms extends JellyTestCase {
46
47     public static final String JavaDoc JDK13_NAME = "JDK1.3";
48     public static final String JavaDoc JDK14_NAME = "JDK1.4";
49     public static final String JavaDoc JDK15_NAME = "JDK1.5";
50     
51     public TestPlatforms(java.lang.String JavaDoc testName) {
52         super(testName);
53     }
54     
55     public static void main(java.lang.String JavaDoc[] args) {
56         junit.textui.TestRunner.run(suite());
57     }
58     
59     public static Test suite() {
60         //TestSuite suite = new NbTestSuite(TestCreatePlatforms.class);
61
TestSuite suite = new NbTestSuite();
62         suite.addTest(new TestPlatforms("testCreatePlatforms"));
63         suite.addTest(new TestPlatforms("testAvailablePlatforms"));
64         return suite;
65     }
66     
67     // -------------------------------------------------------------------------
68

69     public void testAvailablePlatforms() {
70         
71         JavaPlatformManager platMan = JavaPlatformManager.getDefault();
72         JavaPlatform platforms[] = platMan.getInstalledPlatforms();
73         String JavaDoc[] platNames = new String JavaDoc[platforms.length];
74         for (int i = 0; i < platforms.length; i++) {
75             System.out.println("Display Name: " + platforms[i].getDisplayName());
76             platNames[i] = platforms[i].getDisplayName();
77         }
78         // there should be test if all added platforms are really added in IDE
79

80     }
81     
82     // TODO Javadoc can be also added to platform
83
public void testCreatePlatforms() {
84         
85         // learn hostname
86
String JavaDoc hostName = null;
87         try {
88             hostName = InetAddress.getLocalHost().getHostName();
89         } catch (UnknownHostException JavaDoc uhe) {
90             fail("Cannot get hostname: " + uhe.getMessage()); // NOI18N
91
}
92         hostName = hostName.replace('-', '_');
93         
94         // load platforms.properties file
95
InputStream JavaDoc is = this.getClass().getResourceAsStream("platforms.properties");
96         Properties JavaDoc props = new Properties JavaDoc();
97         try {
98             props.load(is);
99         } catch (java.io.IOException JavaDoc ioe) {
100             fail("Cannot load platforms properties: " + ioe.getMessage()); // NOI18N
101
}
102         
103         // get folder from prop file
104
String JavaDoc folderJDK13Path = props.getProperty(hostName + "_jdk13_folder");
105         TestProjectUtils.addPlatform(JDK13_NAME, folderJDK13Path);
106         String JavaDoc folderJDK14Path = props.getProperty(hostName + "_jdk14_folder");
107         TestProjectUtils.addPlatform(JDK14_NAME, folderJDK14Path);
108         String JavaDoc folderJDK15Path = props.getProperty(hostName + "_jdk15_folder");
109         TestProjectUtils.addPlatform(JDK15_NAME, folderJDK15Path);
110         
111     }
112     
113 }
114
Popular Tags