1 19 20 package org.netbeans.modules.java.j2seproject.api; 21 22 import java.io.File ; 23 import junit.framework.TestCase; 24 import junit.framework.*; 25 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.io.OutputStream ; 29 30 import java.util.Properties ; 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 51 public class J2SEProjectConfigurationsTest extends NbTestCase { 52 53 public J2SEProjectConfigurationsTest(String testName) { 54 super(testName); 55 } 56 57 60 public void testCreateConfigurationFiles() throws Exception { 61 62 System.out.println("createConfigurationFiles"); 63 64 File 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 configName = "TestConfig"; 73 74 Properties sharedProps = new Properties (); 75 sharedProps.put("sharedPropName", "sharedPropValue"); 76 sharedProps.put("$sharedPropNameSpecial", "sharedPropValueSpecial"); 77 sharedProps.put("sharedPropName2", "${sharedPropName}"); 78 79 Properties privateProps = new Properties (); 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 loadedSharedProps = new Properties (); 89 loadedSharedProps.load(sharedPropsFO.getInputStream()); 90 assertEquals(sharedProps, loadedSharedProps); 91 92 FileObject privatePropsFO = prjDirFO.getFileObject("nbproject/private/configs/" + configName + ".properties"); 93 Properties loadedPrivateProps = new Properties (); 94 loadedPrivateProps.load(privatePropsFO.getInputStream()); 95 assertEquals(privateProps, loadedPrivateProps); 96 97 configName = "Test_Config2"; 98 99 sharedProps = new Properties (); 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 (); 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 |