KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > ui > customizer > J2SEProjectPropertiesTest


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.modules.java.j2seproject.ui.customizer;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.TreeMap JavaDoc;
25 import org.netbeans.api.project.ProjectManager;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.modules.java.j2seproject.J2SEProject;
28 import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator;
29 import org.netbeans.spi.project.support.ant.AntProjectHelper;
30 import org.netbeans.spi.project.support.ant.EditableProperties;
31 import org.openide.filesystems.FileUtil;
32
33 public class J2SEProjectPropertiesTest extends NbTestCase {
34
35     public J2SEProjectPropertiesTest(String JavaDoc name) {
36         super(name);
37     }
38
39     private J2SEProject p;
40     private J2SEProjectProperties pp;
41
42     protected void setUp() throws Exception JavaDoc {
43         super.setUp();
44         clearWorkDir();
45         J2SEProjectGenerator.createProject(getWorkDir(), "test", null, null);
46         p = (J2SEProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(getWorkDir()));
47         pp = new J2SEProjectProperties(p, p.getUpdateHelper(), p.evaluator(), /* XXX unneeded probably */null, null);
48     }
49
50     public void testRunConfigs() throws Exception JavaDoc {
51         Map JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,String JavaDoc>> m = pp.readRunConfigs();
52         assertEquals("{null={run.jvmargs=}}", m.toString());
53         // Define a new config and set some arguments.
54
Map JavaDoc<String JavaDoc,String JavaDoc> c = new TreeMap JavaDoc<String JavaDoc,String JavaDoc>();
55         c.put("application.args", "foo");
56         m.put("foo", c);
57         storeRunConfigs(m);
58         m = pp.readRunConfigs();
59         assertEquals("{null={run.jvmargs=}, foo={application.args=foo}}", m.toString());
60         // Define args in default config.
61
m.get(null).put("application.args", "bland");
62         storeRunConfigs(m);
63         m = pp.readRunConfigs();
64         assertEquals("{null={application.args=bland, run.jvmargs=}, foo={application.args=foo}}", m.toString());
65         // Reset to default in foo config.
66
m.get("foo").put("application.args", null);
67         storeRunConfigs(m);
68         m = pp.readRunConfigs();
69         assertEquals("{null={application.args=bland, run.jvmargs=}, foo={}}", m.toString());
70         // Override as blank in foo config.
71
m.get("foo").put("application.args", "");
72         storeRunConfigs(m);
73         m = pp.readRunConfigs();
74         assertEquals("{null={application.args=bland, run.jvmargs=}, foo={application.args=}}", m.toString());
75     }
76
77     private void storeRunConfigs(Map JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,String JavaDoc>> m) throws IOException JavaDoc {
78         EditableProperties prj = p.getUpdateHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
79         EditableProperties prv = p.getUpdateHelper().getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
80         pp.storeRunConfigs(m, prj, prv);
81         p.getUpdateHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, prj);
82         p.getUpdateHelper().putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, prv);
83         ProjectManager.getDefault().saveProject(p);
84     }
85
86 }
87
Popular Tags