1 19 20 package org.netbeans.modules.j2ee.clientproject.api; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.modules.j2ee.clientproject.test.TestUtil; 27 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 28 import org.netbeans.spi.project.support.ant.AntProjectHelper; 29 import org.netbeans.spi.project.support.ant.EditableProperties; 30 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 34 38 public class AppClientProjectGeneratorTest extends NbTestCase { 39 40 private String serverID; 41 42 private static final String [] createdFiles = { 43 "build.xml", 44 "nbproject/build-impl.xml", 45 "nbproject/genfiles.properties", 46 "nbproject/project.xml", 47 "nbproject/project.properties", 48 "nbproject/private/private.properties", 49 "src/conf", 50 "src/conf/MANIFEST.MF", 51 "src/java", 52 "test" 53 }; 54 55 private static final String [] createdFilesExtSources = { 56 "build.xml", 57 "nbproject/build-impl.xml", 58 "nbproject/genfiles.properties", 59 "nbproject/project.xml", 60 "nbproject/project.properties", 61 "nbproject/private/private.properties", 62 }; 63 64 private static final String [] createdProperties = { 65 "build.classes.dir", 66 "build.classes.excludes", 67 "build.dir", 68 "build.ear.classes.dir", 69 "build.generated.dir", 70 "build.sysclasspath", 71 "build.test.classes.dir", 72 "build.test.results.dir", 73 "debug.classpath", 74 "debug.test.classpath", 75 "dist.dir", 76 "dist.ear.jar", 77 "dist.jar", 78 "dist.javadoc.dir", 79 "j2ee.appclient.mainclass.args", 80 "j2ee.platform", 81 "j2ee.server.type", 82 "jar.compress", 83 "jar.name", 84 "javac.classpath", 85 "javac.compilerargs", 86 "javac.deprecation", 87 "javac.source", 88 "javac.target", 89 "javac.test.classpath", 90 "javadoc.additionalparam", 91 "javadoc.author", 92 "javadoc.encoding", 93 "javadoc.noindex", 94 "javadoc.nonavbar", 95 "javadoc.notree", 96 "javadoc.private", 97 "javadoc.splitindex", 98 "javadoc.use", 99 "javadoc.version", 100 "javadoc.windowtitle", 101 "main.class", 102 "manifest.file", 103 "meta.inf", 104 "platform.active", 105 "resource.dir", 106 "run.classpath", 107 "run.jvmargs", 108 "run.test.classpath", 109 "source.root", 110 "src.dir", 111 "test.src.dir" 112 }; 113 114 private static final String [] createdPropertiesExtSources = { 115 "build.classes.dir", 116 "build.classes.excludes", 117 "build.dir", 118 "build.ear.classes.dir", 119 "build.generated.dir", 120 "build.sysclasspath", 121 "build.test.classes.dir", 122 "build.test.results.dir", 123 "debug.classpath", 124 "debug.test.classpath", 125 "dist.dir", 126 "dist.ear.jar", 127 "dist.jar", 128 "dist.javadoc.dir", 129 "j2ee.appclient.mainclass.args", 130 "j2ee.platform", 131 "j2ee.server.type", 132 "jar.compress", 133 "jar.name", 134 "javac.classpath", 135 "javac.compilerargs", 136 "javac.deprecation", 137 "javac.source", 138 "javac.target", 139 "javac.test.classpath", 140 "javadoc.additionalparam", 141 "javadoc.author", 142 "javadoc.encoding", 143 "javadoc.noindex", 144 "javadoc.nonavbar", 145 "javadoc.notree", 146 "javadoc.private", 147 "javadoc.splitindex", 148 "javadoc.use", 149 "javadoc.version", 150 "javadoc.windowtitle", 151 "manifest.file", 152 "meta.inf", 153 "platform.active", 154 "resource.dir", 155 "run.classpath", 156 "run.jvmargs", 157 "run.test.classpath", 158 "src.dir", 160 "test.src.dir" 161 }; 162 163 public AppClientProjectGeneratorTest(String name) { 164 super(name); 165 } 166 167 protected void setUp() throws Exception { 168 super.setUp(); 169 TestUtil.makeScratchDir(this); 170 serverID = TestUtil.registerSunAppServer(this); 171 } 172 173 public void testCreateProject() throws Exception { 174 File root = new File (getWorkDir(), "projects"); 175 File proj = new File (root, "TestCreateACProject"); 176 AntProjectHelper aph = AppClientProjectGenerator.createProject(proj, "test-project", 177 "test.MyMain", J2eeModule.JAVA_EE_5, serverID); 178 assertNotNull(aph); 179 FileObject fo = aph.getProjectDirectory(); 180 for (int i=0; i<createdFiles.length; i++) { 181 assertNotNull(createdFiles[i]+" file/folder cannot be found", fo.getFileObject(createdFiles[i])); 182 } 183 EditableProperties props = aph.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 184 @SuppressWarnings ("unchecked") 185 List <Object > l = new ArrayList <Object >(props.keySet()); 186 for (int i=0; i<createdProperties.length; i++) { 187 assertNotNull(createdProperties[i]+" property cannot be found in project.properties", props.getProperty(createdProperties[i])); 188 l.remove(createdProperties[i]); 189 } 190 assertEquals("Found unexpected property: "+l,createdProperties.length, props.keySet().size()); 191 } 192 193 public void testImportProject() throws Exception { 194 File root = new File (getWorkDir(), "projects"); 195 File proj = new File (root, "ProjectDir"); 196 File rootToImport = TestUtil.copyFolder(getWorkDir(), new File (getDataDir(), "projects/importTest")); 197 File srcRoot = new File (rootToImport, "src/java"); 198 File confRoot = new File (rootToImport, "src/conf"); 199 File testRoot = new File (proj, "test"); 200 AntProjectHelper helper = AppClientProjectGenerator.importProject(proj, 201 "test-project-ext-src", new File [] {srcRoot}, new File [] {testRoot}, 202 confRoot, null, J2eeModule.JAVA_EE_5, serverID); 203 assertNotNull(helper); 204 FileObject importedDirFO = FileUtil.toFileObject(proj); 205 for (int i=0; i<createdFilesExtSources.length; i++) { 206 assertNotNull(createdFilesExtSources[i]+" file/folder cannot be found", importedDirFO.getFileObject(createdFilesExtSources[i])); 207 } 208 assertNotNull("MANIFEST.MF was created", new File (confRoot, "MANIFEST.MF")); 209 EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 210 @SuppressWarnings ("unchecked") 211 List <Object > l = new ArrayList <Object >(props.keySet()); 212 int extFileRefCount = 0; 213 for (int i=0; i<createdPropertiesExtSources.length; i++) { 214 String propName = createdPropertiesExtSources[i]; 215 String propValue = props.getProperty(propName); 216 assertNotNull(propName+" property cannot be found in project.properties", propValue); 217 l.remove(propName); 218 if ("manifest.file".equals(propName)) { 219 assertEquals("Invalid value of manifest.file property.", "${meta.inf}/MANIFEST.MF", propValue); 220 } else if ("src.dir".equals (propName)) { 221 PropertyEvaluator eval = helper.getStandardPropertyEvaluator(); 222 assertTrue("Value of the external source dir should be file reference",propValue.startsWith("${file.reference.")); 225 if (l.remove (propValue.subSequence(2,propValue.length()-1))) { 226 extFileRefCount++; 227 } 228 File file = helper.resolveFile(eval.evaluate(propValue)); 229 assertEquals("Invalid value of src.dir property.", srcRoot, file); 230 } else if ("test.src.dir".equals(propName)) { 231 PropertyEvaluator eval = helper.getStandardPropertyEvaluator(); 232 assertTrue("Value of the external test dir should be file reference",propValue.startsWith("${file.reference.")); 235 if (l.remove (propValue.subSequence(2,propValue.length()-1))) { 236 extFileRefCount++; 237 } 238 File file = helper.resolveFile(eval.evaluate(propValue)); 239 assertEquals("Invalid value of test.src.dir property.", testRoot, file); 240 } 241 } 242 assertEquals("Found unexpected property: "+l,createdPropertiesExtSources.length, props.keySet().size() - extFileRefCount); 243 } 244 245 public void testSetPlatform() throws Exception { 246 File root = new File (getWorkDir(), "projects"); 247 File proj = new File (root, "ImportProjectsNBDir"); 248 File importRoot = new File (getDataDir(), "projects/importTest"); 249 File srcRoot = new File (importRoot, "src/java"); 250 File confRoot = new File (importRoot, "src/conf"); 251 File libDir = new File (root, "libs"); 252 libDir.mkdirs(); 253 AntProjectHelper helper = AppClientProjectGenerator.importProject(proj, 254 "test-project-ext-src2", new File [] {srcRoot}, new File [] {}, 255 confRoot, libDir, J2eeModule.JAVA_EE_5, serverID); 256 assertNotNull(helper); 257 EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 258 assertEquals("default_platform", ep.getProperty("platform.active")); 259 assertEquals("${default.javac.source}", ep.getProperty("javac.source")); 260 assertEquals("${default.javac.target}", ep.getProperty("javac.target")); 261 AppClientProjectGenerator.setPlatform(helper, "ExplicitPlatform", "1.4"); 262 ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 263 assertEquals("ExplicitPlatform", ep.getProperty("platform.active")); 264 assertEquals("1.4", ep.getProperty("javac.source")); 265 assertEquals("1.4", ep.getProperty("javac.target")); 266 } 267 268 } 269 | Popular Tags |