1 19 20 package org.netbeans.modules.java.j2seproject.ui.customizer; 21 22 import java.io.IOException ; 23 import java.util.Map ; 24 import java.util.TreeMap ; 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 name) { 36 super(name); 37 } 38 39 private J2SEProject p; 40 private J2SEProjectProperties pp; 41 42 protected void setUp() throws Exception { 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(), null, null); 48 } 49 50 public void testRunConfigs() throws Exception { 51 Map <String ,Map <String ,String >> m = pp.readRunConfigs(); 52 assertEquals("{null={run.jvmargs=}}", m.toString()); 53 Map <String ,String > c = new TreeMap <String ,String >(); 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 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 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 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 <String ,Map <String ,String >> m) throws IOException { 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 |