KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > api > J2SEProjectConfigurationsTest


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.j2seproject.api;
21
22 import java.io.File JavaDoc;
23 import junit.framework.TestCase;
24 import junit.framework.*;
25
26 import java.io.IOException JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.OutputStream JavaDoc;
29
30 import java.util.Properties JavaDoc;
31
32 import org.netbeans.api.project.Project;
33 import org.netbeans.api.project.ProjectManager;
34 import org.netbeans.junit.NbTestCase;
35 import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator;
36 import org.netbeans.spi.project.support.ant.AntProjectHelper;
37
38 import org.openide.filesystems.FileObject;
39 import org.openide.filesystems.FileSystem;
40 import org.openide.filesystems.FileUtil;
41 import org.openide.modules.SpecificationVersion;
42
43 import org.openide.util.Mutex;
44 import org.openide.util.MutexException;
45
46 /**
47  * Test of class org.netbeans.modules.java.j2seproject.api.J2SEProjectConfigurations
48  *
49  * @author Milan Kubec
50  */

51 public class J2SEProjectConfigurationsTest extends NbTestCase {
52     
53     public J2SEProjectConfigurationsTest(String JavaDoc testName) {
54         super(testName);
55     }
56     
57     /**
58      * Test of createConfigurationFiles method
59      */

60     public void testCreateConfigurationFiles() throws Exception JavaDoc {
61         
62         System.out.println("createConfigurationFiles");
63         
64         File JavaDoc proj = getWorkDir();
65         clearWorkDir();
66         
67         J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.5"));
68         AntProjectHelper aph = J2SEProjectGenerator.createProject(proj, "TestProject", null, "manifest.mf");
69         
70         Project prj = ProjectManager.getDefault().findProject(aph.getProjectDirectory());
71         
72         String JavaDoc configName = "TestConfig";
73         
74         Properties JavaDoc sharedProps = new Properties JavaDoc();
75         sharedProps.put("sharedPropName", "sharedPropValue");
76         sharedProps.put("$sharedPropNameSpecial", "sharedPropValueSpecial");
77         sharedProps.put("sharedPropName2", "${sharedPropName}");
78         
79         Properties JavaDoc privateProps = new Properties JavaDoc();
80         privateProps.put("privatePropName", "privatePropValue");
81         privateProps.put("privatePropName2", "${privatePropName}");
82         
83         J2SEProjectConfigurations.createConfigurationFiles(prj, configName, sharedProps, privateProps);
84         
85         FileObject prjDirFO = prj.getProjectDirectory();
86         
87         FileObject sharedPropsFO = prjDirFO.getFileObject("nbproject/configs/" + configName + ".properties");
88         Properties JavaDoc loadedSharedProps = new Properties JavaDoc();
89         loadedSharedProps.load(sharedPropsFO.getInputStream());
90         assertEquals(sharedProps, loadedSharedProps);
91         
92         FileObject privatePropsFO = prjDirFO.getFileObject("nbproject/private/configs/" + configName + ".properties");
93         Properties JavaDoc loadedPrivateProps = new Properties JavaDoc();
94         loadedPrivateProps.load(privatePropsFO.getInputStream());
95         assertEquals(privateProps, loadedPrivateProps);
96         
97         configName = "Test_Config2";
98         
99         sharedProps = new Properties JavaDoc();
100         sharedProps.put("sharedPropName", "sharedPropValue");
101         sharedProps.put("$sharedPropNameSpecial", "sharedPropValueSpecial");
102         sharedProps.put("sharedPropName2", "${sharedPropName}");
103         
104         J2SEProjectConfigurations.createConfigurationFiles(prj, configName, sharedProps, null);
105         
106         sharedPropsFO = prjDirFO.getFileObject("nbproject/configs/" + configName + ".properties");
107         loadedSharedProps = new Properties JavaDoc();
108         loadedSharedProps.load(sharedPropsFO.getInputStream());
109         assertEquals(sharedProps, loadedSharedProps);
110         
111         privatePropsFO = prjDirFO.getFileObject("nbproject/private/configs/" + configName + ".properties");
112         assertNull(privatePropsFO);
113         
114     }
115     
116 }
117
Popular Tags