001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: * and Distribution License (the License). You may not use this file except in
006: * compliance with the License.
007: *
008: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
009: * or http://www.netbeans.org/cddl.txt.
010: *
011: * When distributing Covered Code, include this CDDL Header Notice in each file
012: * and include the License file at http://www.netbeans.org/cddl.txt.
013: * If applicable, add the following below the CDDL Header, with the fields
014: * enclosed by brackets [] replaced by your own identifying information:
015: * 'Portions Copyrighted [year] [name of copyright owner]'
016: *
017: * The Original Software is NetBeans. The Initial Developer of the Original
018: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
019: * Microsystems, Inc. All Rights Reserved.
020: *
021: * If you wish your version of this file to be governed by only the CDDL
022: * or only the GPL Version 2, indicate your decision by adding
023: * "[Contributor] elects to include this software in this distribution
024: * under the [CDDL or GPL Version 2] license." If you do not indicate a
025: * single choice of license, a recipient has the option to distribute
026: * your version of this file under either the CDDL, the GPL Version 2 or
027: * to extend the choice of license to its licensees as provided above.
028: * However, if you add GPL Version 2 code and therefore, elected the GPL
029: * Version 2 license, then the option applies only if the new code is
030: * made subject to such option by the copyright holder.
031: */
032:
033: package org.netbeans.nbbuild;
034:
035: import java.io.File;
036: import java.io.IOException;
037: import java.io.PrintStream;
038: import java.util.HashSet;
039: import java.util.Set;
040: import junit.framework.*;
041: import org.apache.tools.ant.Project;
042: import org.netbeans.junit.*;
043:
044: /**
045: *
046: * @author pzajac
047: */
048: public class TestDistFilterTest extends NbTestCase {
049: private static final String ORG_OPENIDE_UNIT = "unit/platform5/org-openide";
050: private static final String ORG_OPENIDE_FS = "unit/platform5/org-openide-fs";
051: private static final String ORG_OPENIDE_LOADERS = "unit/platform5/org-openide-loaders";
052: private static final String ORG_OPENIDE_LOADERS_QA = "qa-functional/platform5/org-openide-loaders";
053: private static final String ORG_OPENIDE_FS_QA = "qa-functional/platform5/org-openide-fs";
054: private static final String ORG_OPENIDE_NO_LOADERS = "unit/platform5/org-openide-no-loaders";
055:
056: public TestDistFilterTest(java.lang.String testName) {
057: super (testName);
058: }
059:
060: public void testDistFilter() throws IOException {
061: TestDistFilter filter = new TestDistFilter();
062: filter.setTestDistDir(getWorkDir());
063: createModule(ORG_OPENIDE_UNIT, createConfig("unstable", "code"));
064: filter.setAttribs("stable");
065: filter.setHarness("junit");
066: Project prj = getProject();
067: filter.setProject(prj);
068: filter.setTesttype("unit");
069:
070: filter.setTestListProperty("list.prop");
071: filter.execute();
072: assertProperty(prj, "list.prop", new String[] {});
073:
074: createModule(ORG_OPENIDE_UNIT, createConfig("stable", "code"));
075:
076: filter.setTestListProperty("list.prop1");
077: filter.execute();
078: assertProperty(prj, "list.prop1",
079: new String[] { ORG_OPENIDE_UNIT });
080:
081: createModule(ORG_OPENIDE_FS, createConfig("stable", "ide"));
082: filter.setTestListProperty("list.prop2");
083: filter.execute();
084: assertProperty(prj, "list.prop2",
085: new String[] { ORG_OPENIDE_UNIT });
086:
087: filter.setTestListProperty("list.prop3");
088: createModule(ORG_OPENIDE_LOADERS,
089: createConfig("stable", "code"));
090: filter.execute();
091: assertProperty(prj, "list.prop3", new String[] {
092: ORG_OPENIDE_UNIT, ORG_OPENIDE_LOADERS });
093:
094: createModule(ORG_OPENIDE_FS_QA, createConfig("stable", "code"));
095: filter.setTestListProperty("list.prop4");
096: filter.execute();
097: assertProperty(prj, "list.prop4", new String[] {
098: ORG_OPENIDE_UNIT, ORG_OPENIDE_LOADERS });
099:
100: filter.setTestListProperty("list.prop5");
101: createModule(ORG_OPENIDE_LOADERS, createConfig("unstable",
102: "code"));
103: filter.execute();
104: assertProperty(prj, "list.prop5",
105: new String[] { ORG_OPENIDE_UNIT });
106:
107: filter.setHarness("xtest");
108: filter.setTestListProperty("list.prop6");
109: filter.execute();
110: assertProperty(prj, "list.prop6", new String[] {
111: ORG_OPENIDE_UNIT, ORG_OPENIDE_FS });
112:
113: filter.setTestListProperty("list.prop7");
114: filter.setTesttype("qa-functional");
115: filter.execute();
116: assertProperty(prj, "list.prop7",
117: new String[] { ORG_OPENIDE_FS_QA });
118: }
119:
120: public void testAllTestTypes() throws Exception {
121: TestDistFilter filter = new TestDistFilter();
122: filter.setTestDistDir(getWorkDir());
123: Project prj = getProject();
124: filter.setProject(prj);
125: filter.setTesttype("all");
126: filter.setHarness("xtest");
127: createModule(ORG_OPENIDE_UNIT, createConfig("stable", "code"));
128: createModule(ORG_OPENIDE_FS_QA, createConfig("stable", "code"));
129: filter.setTestListProperty("list.prop");
130: filter.execute();
131: assertProperty(prj, "list.prop", new String[] {
132: ORG_OPENIDE_UNIT, ORG_OPENIDE_FS_QA });
133: }
134:
135: public void testComplexAttribs() throws Exception {
136: TestDistFilter filter = new TestDistFilter();
137: filter.setTestDistDir(getWorkDir());
138: Project prj = getProject();
139: createModule(ORG_OPENIDE_UNIT, createConfig("stable|xx , aa",
140: "code"));
141: filter.setProject(prj);
142: filter.setTesttype("all");
143: filter.setHarness("xtest");
144: filter.setAttribs("stable");
145: filter.setTestListProperty("list.prop");
146: filter.execute();
147: assertProperty(prj, "list.prop",
148: new String[] { ORG_OPENIDE_UNIT });
149:
150: filter.setAttribs("xx");
151: filter.setTestListProperty("list.prop2");
152: filter.execute();
153: assertProperty(prj, "list.prop2",
154: new String[] { ORG_OPENIDE_UNIT });
155:
156: filter.setAttribs("aa");
157: filter.setTestListProperty("list.prop3");
158: filter.execute();
159: assertProperty(prj, "list.prop3",
160: new String[] { ORG_OPENIDE_UNIT });
161:
162: filter.setAttribs("");
163: filter.setTestListProperty("list.prop4");
164: filter.execute();
165: assertProperty(prj, "list.prop4",
166: new String[] { ORG_OPENIDE_UNIT });
167:
168: filter.setAttribs(null);
169: filter.setTestListProperty("list.prop5");
170: filter.execute();
171: assertProperty(prj, "list.prop5",
172: new String[] { ORG_OPENIDE_UNIT });
173:
174: filter.setAttribs("nonsence");
175: filter.setTestListProperty("list.prop6");
176: filter.execute();
177: assertProperty(prj, "list.prop6", new String[] {});
178: }
179:
180: public void testComplexAttribs2() throws IOException {
181: TestDistFilter filter = new TestDistFilter();
182: filter.setTestDistDir(getWorkDir());
183: Project prj = getProject();
184: filter.setProject(prj);
185: createModule(ORG_OPENIDE_LOADERS_QA, createConfig(
186: "validation or full or ds or i18n or dspool", "code"));
187: filter.setAttribs("validation");
188: filter.setHarness("xtest");
189: filter.setTesttype("qa-functional");
190: filter.setTestListProperty("list.prop1");
191: filter.execute();
192: assertProperty(prj, "list.prop1",
193: new String[] { ORG_OPENIDE_LOADERS_QA });
194:
195: }
196:
197: public void testRequiredModules() throws IOException {
198: TestDistFilter filter = new TestDistFilter();
199: filter.setTestDistDir(getWorkDir());
200: filter.setAttribs("stable");
201: filter.setHarness("junit");
202: Project prj = getProject();
203: filter.setProject(prj);
204: filter.setTesttype("unit");
205:
206: String FS = "modules/org-openide-filesystems.jar";
207: String LOADERS = "modules/org-openide-loaders.jar";
208: createModule(ORG_OPENIDE_UNIT, createConfig("stable", "code"),
209: LOADERS);
210: createModule(ORG_OPENIDE_FS, createConfig("stable", "code"), FS);
211: createModule(ORG_OPENIDE_LOADERS,
212: createConfig("stable", "code"), FS + ":" + LOADERS);
213: createModule(ORG_OPENIDE_NO_LOADERS, createConfig("stable",
214: "code"), FS);
215: filter.setRequiredModules("org-openide-filesystems.jar");
216: filter.setTestListProperty("list.prop");
217: filter.execute();
218: assertProperty(prj, "list.prop", new String[] { ORG_OPENIDE_FS,
219: ORG_OPENIDE_LOADERS, ORG_OPENIDE_NO_LOADERS });
220:
221: filter.setRequiredModules(null);
222: filter.setTestListProperty("list.prop1");
223: filter.execute();
224: assertProperty(prj, "list.prop1", new String[] {
225: ORG_OPENIDE_UNIT, ORG_OPENIDE_FS, ORG_OPENIDE_LOADERS,
226: ORG_OPENIDE_NO_LOADERS });
227:
228: filter.setRequiredModules("");
229: filter.setTestListProperty("list.prop11");
230: filter.execute();
231: assertProperty(prj, "list.prop11", new String[] {
232: ORG_OPENIDE_UNIT, ORG_OPENIDE_FS, ORG_OPENIDE_LOADERS,
233: ORG_OPENIDE_NO_LOADERS });
234:
235: filter.setRequiredModules("org-openide-loaders.jar");
236: filter.setTestListProperty("list.prop2");
237: filter.execute();
238: assertProperty(prj, "list.prop2", new String[] {
239: ORG_OPENIDE_UNIT, ORG_OPENIDE_LOADERS });
240:
241: filter.setRequiredModules("none.jar");
242: filter.setTestListProperty("list.prop3");
243: filter.execute();
244: assertProperty(prj, "list.prop3", new String[] {});
245:
246: filter
247: .setRequiredModules("org-openide-loaders.jar,org-openide-filesystems.jar");
248: filter.setTestListProperty("list.prop4");
249: filter.execute();
250: assertProperty(prj, "list.prop4", new String[] {
251: ORG_OPENIDE_LOADERS, ORG_OPENIDE_UNIT, ORG_OPENIDE_FS,
252: ORG_OPENIDE_NO_LOADERS });
253:
254: }
255:
256: private String createConfig(String attribs, String executor) {
257: return "<?xml version='1.0' encoding='UTF-8'?>\n"
258: + "<!DOCTYPE mconfig PUBLIC '-//NetBeans//DTD XTest cfg 1.0//EN' 'http://www.netbeans.org/dtds/xtest-cfg-1_0.dtd'>\n"
259: + "<mconfig name='Configuration of refactoring unit tests'>\n"
260: + "<testbag testattribs='"
261: + attribs
262: + "' executor='"
263: + executor
264: + "' name='Refactoring unit tests'>\n"
265: + "<testset dir='unit/src'>\n"
266: + "<patternset>\n"
267: + "<include name='org/netbeans/test/refactoring/encapsulate/EncapsulateTest.class'/>\n"
268: + "</patternset>\n" + "</testset>\n" + "</testbag>\n"
269: + "</mconfig>\n";
270: }
271:
272: private void createModule(String path, String xml)
273: throws IOException {
274: File dir = new File(getWorkDir(), path);
275: dir.mkdirs();
276: File cfg = new File(dir,
277: (path.startsWith("unit")) ? "cfg-unit.xml"
278: : "cfg-qa-functional.xml");
279: PrintStream ps = new PrintStream(cfg);
280: try {
281: ps.print(xml);
282: } finally {
283: ps.close();
284: }
285: }
286:
287: private Project getProject() throws IOException {
288: Project project = new Project();
289: project.setBaseDir(getWorkDir());
290: return project;
291: }
292:
293: private void assertProperty(Project prj, String propName,
294: String modules[]) throws IOException {
295: String listModules = prj.getProperty(propName);
296: assertNotNull("prop " + propName + " was not defined",
297: listModules);
298: log(" listModules " + listModules);
299: String arrayModules[] = (listModules.length() == 0) ? new String[0]
300: : listModules.split(":");
301: Set set1 = new HashSet();
302: for (int i = 0; i < arrayModules.length; i++) {
303: String module = arrayModules[i];
304: if (module.length() == 1 && i < arrayModules.length + 1) {
305: // module is e:/dd/dd/ on windows
306: module = module + ":" + arrayModules[++i];
307: }
308: log(i + " = " + module);
309: set1.add(new File(module));
310: }
311: Set set2 = new HashSet();
312: for (int i = 0; i < modules.length; i++) {
313: set2.add(new File(getWorkDir(), modules[i]));
314: }
315: assertEquals("paths length", set2.size(), set1.size());
316: assertEquals("Different paths: ", set2, set1);
317: }
318:
319: private void createModule(String path, String xml, String runcp)
320: throws IOException {
321: createModule(path, xml);
322: File dir = new File(getWorkDir(), path);
323: File props = new File(dir, "test.properties");
324: PrintStream ps = new PrintStream(props);
325: try {
326: ps.println("test.unit.run.cp=" + runcp);
327: } finally {
328: ps.close();
329: }
330: }
331: }
|