1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.PrintStream ; 25 import java.util.HashSet ; 26 import java.util.Set ; 27 import junit.framework.*; 28 import org.apache.tools.ant.Project; 29 import org.netbeans.junit.*; 30 31 35 public class TestDistFilterTest extends NbTestCase { 36 private static final String ORG_OPENIDE_UNIT = "unit/platform5/org-openide"; 37 private static final String ORG_OPENIDE_FS = "unit/platform5/org-openide-fs"; 38 private static final String ORG_OPENIDE_LOADERS = "unit/platform5/org-openide-loaders"; 39 private static final String ORG_OPENIDE_LOADERS_QA = "qa-functional/platform5/org-openide-loaders"; 40 private static final String ORG_OPENIDE_FS_QA = "qa-functional/platform5/org-openide-fs"; 41 private static final String ORG_OPENIDE_NO_LOADERS = "unit/platform5/org-openide-no-loaders"; 42 public TestDistFilterTest(java.lang.String testName) { 43 super(testName); 44 } 45 46 public void testDistFilter() throws IOException { 47 TestDistFilter filter = new TestDistFilter(); 48 filter.setTestDistDir(getWorkDir()); 49 createModule(ORG_OPENIDE_UNIT,createConfig("unstable","code")); 50 filter.setAttribs("stable"); 51 filter.setHarness("junit"); 52 Project prj = getProject(); 53 filter.setProject(prj); 54 filter.setTesttype("unit"); 55 56 filter.setTestListProperty("list.prop"); 57 filter.execute(); 58 assertProperty(prj,"list.prop",new String []{}); 59 60 createModule(ORG_OPENIDE_UNIT,createConfig("stable","code")); 61 62 filter.setTestListProperty("list.prop1"); 63 filter.execute(); 64 assertProperty(prj,"list.prop1",new String []{ORG_OPENIDE_UNIT}); 65 66 createModule(ORG_OPENIDE_FS,createConfig("stable","ide")); 67 filter.setTestListProperty("list.prop2"); 68 filter.execute(); 69 assertProperty(prj,"list.prop2",new String []{ORG_OPENIDE_UNIT}); 70 71 filter.setTestListProperty("list.prop3"); 72 createModule(ORG_OPENIDE_LOADERS,createConfig("stable","code")); 73 filter.execute(); 74 assertProperty(prj,"list.prop3",new String []{ORG_OPENIDE_UNIT,ORG_OPENIDE_LOADERS}); 75 76 createModule(ORG_OPENIDE_FS_QA,createConfig("stable","code")); 77 filter.setTestListProperty("list.prop4"); 78 filter.execute(); 79 assertProperty(prj,"list.prop4",new String []{ORG_OPENIDE_UNIT,ORG_OPENIDE_LOADERS}); 80 81 filter.setTestListProperty("list.prop5"); 82 createModule(ORG_OPENIDE_LOADERS,createConfig("unstable","code")); 83 filter.execute(); 84 assertProperty(prj,"list.prop5",new String []{ORG_OPENIDE_UNIT}); 85 86 filter.setHarness("xtest"); 87 filter.setTestListProperty("list.prop6"); 88 filter.execute(); 89 assertProperty(prj,"list.prop6",new String []{ORG_OPENIDE_UNIT,ORG_OPENIDE_FS}); 90 91 filter.setTestListProperty("list.prop7"); 92 filter.setTesttype("qa-functional"); 93 filter.execute(); 94 assertProperty(prj,"list.prop7",new String []{ORG_OPENIDE_FS_QA}); 95 } 96 97 public void testAllTestTypes() throws Exception { 98 TestDistFilter filter = new TestDistFilter(); 99 filter.setTestDistDir(getWorkDir()); 100 Project prj = getProject(); 101 filter.setProject(prj); 102 filter.setTesttype("all"); 103 filter.setHarness("xtest"); 104 createModule(ORG_OPENIDE_UNIT,createConfig("stable","code")); 105 createModule(ORG_OPENIDE_FS_QA,createConfig("stable","code")); 106 filter.setTestListProperty("list.prop"); 107 filter.execute(); 108 assertProperty(prj,"list.prop",new String []{ORG_OPENIDE_UNIT,ORG_OPENIDE_FS_QA}); 109 } 110 111 public void testComplexAttribs() throws Exception { 112 TestDistFilter filter = new TestDistFilter(); 113 filter.setTestDistDir(getWorkDir()); 114 Project prj = getProject(); 115 createModule(ORG_OPENIDE_UNIT,createConfig("stable|xx , aa","code")); 116 filter.setProject(prj); 117 filter.setTesttype("all"); 118 filter.setHarness("xtest"); 119 filter.setAttribs("stable"); 120 filter.setTestListProperty("list.prop"); 121 filter.execute(); 122 assertProperty(prj,"list.prop",new String []{ORG_OPENIDE_UNIT}); 123 124 filter.setAttribs("xx"); 125 filter.setTestListProperty("list.prop2"); 126 filter.execute(); 127 assertProperty(prj,"list.prop2",new String []{ORG_OPENIDE_UNIT}); 128 129 filter.setAttribs("aa"); 130 filter.setTestListProperty("list.prop3"); 131 filter.execute(); 132 assertProperty(prj,"list.prop3",new String []{ORG_OPENIDE_UNIT}); 133 134 filter.setAttribs(""); 135 filter.setTestListProperty("list.prop4"); 136 filter.execute(); 137 assertProperty(prj,"list.prop4",new String []{ORG_OPENIDE_UNIT}); 138 139 filter.setAttribs(null); 140 filter.setTestListProperty("list.prop5"); 141 filter.execute(); 142 assertProperty(prj,"list.prop5",new String []{ORG_OPENIDE_UNIT}); 143 144 filter.setAttribs("nonsence"); 145 filter.setTestListProperty("list.prop6"); 146 filter.execute(); 147 assertProperty(prj,"list.prop6",new String []{}); 148 } 149 public void testComplexAttribs2 () throws IOException { 150 TestDistFilter filter = new TestDistFilter(); 151 filter.setTestDistDir(getWorkDir()); 152 Project prj = getProject(); 153 filter.setProject(prj); 154 createModule(ORG_OPENIDE_LOADERS_QA,createConfig("validation or full or ds or i18n or dspool","code")); 155 filter.setAttribs("validation"); 156 filter.setHarness("xtest"); 157 filter.setTesttype("qa-functional"); 158 filter.setTestListProperty("list.prop1"); 159 filter.execute(); 160 assertProperty(prj,"list.prop1",new String []{ORG_OPENIDE_LOADERS_QA}); 161 162 } 163 public void testRequiredModules() throws IOException { 164 TestDistFilter filter = new TestDistFilter(); 165 filter.setTestDistDir(getWorkDir()); 166 filter.setAttribs("stable"); 167 filter.setHarness("junit"); 168 Project prj = getProject(); 169 filter.setProject(prj); 170 filter.setTesttype("unit"); 171 172 String FS = "modules/org-openide-filesystems.jar"; 173 String LOADERS = "modules/org-openide-loaders.jar"; 174 createModule(ORG_OPENIDE_UNIT,createConfig("stable","code"),LOADERS); 175 createModule(ORG_OPENIDE_FS,createConfig("stable","code"),FS); 176 createModule(ORG_OPENIDE_LOADERS,createConfig("stable","code"),FS + ":" + LOADERS ); 177 createModule(ORG_OPENIDE_NO_LOADERS,createConfig("stable","code"),FS); 178 filter.setRequiredModules("org-openide-filesystems.jar"); 179 filter.setTestListProperty("list.prop"); 180 filter.execute(); 181 assertProperty(prj,"list.prop",new String []{ORG_OPENIDE_FS,ORG_OPENIDE_LOADERS,ORG_OPENIDE_NO_LOADERS}); 182 183 filter.setRequiredModules(null); 184 filter.setTestListProperty("list.prop1"); 185 filter.execute(); 186 assertProperty(prj,"list.prop1",new String []{ORG_OPENIDE_UNIT,ORG_OPENIDE_FS,ORG_OPENIDE_LOADERS,ORG_OPENIDE_NO_LOADERS}); 187 188 filter.setRequiredModules(""); 189 filter.setTestListProperty("list.prop11"); 190 filter.execute(); 191 assertProperty(prj,"list.prop11",new String []{ORG_OPENIDE_UNIT,ORG_OPENIDE_FS,ORG_OPENIDE_LOADERS,ORG_OPENIDE_NO_LOADERS}); 192 193 filter.setRequiredModules("org-openide-loaders.jar"); 194 filter.setTestListProperty("list.prop2"); 195 filter.execute(); 196 assertProperty(prj,"list.prop2",new String []{ORG_OPENIDE_UNIT,ORG_OPENIDE_LOADERS}); 197 198 filter.setRequiredModules("none.jar"); 199 filter.setTestListProperty("list.prop3"); 200 filter.execute(); 201 assertProperty(prj,"list.prop3",new String []{}); 202 203 filter.setRequiredModules("org-openide-loaders.jar,org-openide-filesystems.jar"); 204 filter.setTestListProperty("list.prop4"); 205 filter.execute(); 206 assertProperty(prj,"list.prop4",new String []{ORG_OPENIDE_LOADERS,ORG_OPENIDE_UNIT,ORG_OPENIDE_FS,ORG_OPENIDE_NO_LOADERS}); 207 208 } 209 210 private String createConfig(String attribs,String executor) { 211 return "<?xml version='1.0' encoding='UTF-8'?>\n" + 212 "<!DOCTYPE mconfig PUBLIC '-//NetBeans//DTD XTest cfg 1.0//EN' 'http://www.netbeans.org/dtds/xtest-cfg-1_0.dtd'>\n" + 213 "<mconfig name='Configuration of refactoring unit tests'>\n" + 214 "<testbag testattribs='" + attribs + "' executor='" + executor + "' name='Refactoring unit tests'>\n" + 215 "<testset dir='unit/src'>\n" + 216 "<patternset>\n" + 217 "<include name='org/netbeans/test/refactoring/encapsulate/EncapsulateTest.class'/>\n" + 218 "</patternset>\n" + 219 "</testset>\n" + 220 "</testbag>\n" + 221 "</mconfig>\n"; 222 } 223 224 private void createModule(String path, String xml) throws IOException { 225 File dir = new File (getWorkDir(),path); 226 dir.mkdirs(); 227 File cfg = new File (dir,(path.startsWith("unit")) ? "cfg-unit.xml" : "cfg-qa-functional.xml"); 228 PrintStream ps = new PrintStream (cfg); 229 try { 230 ps.print(xml); 231 } finally { 232 ps.close(); 233 } 234 } 235 236 private Project getProject() throws IOException { 237 Project project = new Project(); 238 project.setBaseDir(getWorkDir()); 239 return project; 240 } 241 242 private void assertProperty(Project prj, String propName, String modules[]) throws IOException { 243 String listModules = prj.getProperty(propName); 244 assertNotNull("prop " + propName + " was not defined",listModules); 245 log(" listModules " + listModules); 246 String arrayModules[] = (listModules.length() == 0) ? new String [0] :listModules.split(":"); 247 Set set1 = new HashSet (); 248 for (int i = 0 ; i < arrayModules.length ; i++) { 249 String module = arrayModules[i]; 250 if (module.length() == 1 && i < arrayModules.length + 1) { 251 module = module + ":" + arrayModules[++i]; 253 } 254 log(i + " = " + module ); 255 set1.add(new File (module)); 256 } 257 Set set2 = new HashSet (); 258 for (int i = 0 ; i < modules.length ; i++) { 259 set2.add(new File (getWorkDir(),modules[i])); 260 } 261 assertEquals("paths length",set2.size(),set1.size()); 262 assertEquals("Different paths: ", set2,set1); 263 } 264 265 private void createModule(String path, String xml, String runcp) throws IOException { 266 createModule(path,xml); 267 File dir = new File (getWorkDir(),path); 268 File props = new File (dir,"test.properties"); 269 PrintStream ps = new PrintStream (props); 270 try { 271 ps.println("test.unit.run.cp=" + runcp); 272 } finally { 273 ps.close(); 274 } 275 } 276 } 277 | Popular Tags |