1 17 package org.apache.tools.ant.taskdefs.optional.vss; 18 19 import java.io.File ; 20 import java.text.SimpleDateFormat ; 21 import java.util.Calendar ; 22 import java.util.Date ; 23 import java.util.TimeZone ; 24 25 import org.apache.tools.ant.BuildFileTest; 26 import org.apache.tools.ant.Location; 27 import org.apache.tools.ant.Project; 28 import org.apache.tools.ant.taskdefs.Tstamp; 29 import org.apache.tools.ant.types.Commandline; 30 import org.apache.tools.ant.types.Path; 31 32 36 public class MSVSSTest extends BuildFileTest implements MSVSSConstants { 37 38 private Commandline commandline; 39 40 private static final String VSS_SERVER_PATH = "\\\\server\\vss\\srcsafe.ini"; 41 private static final String VSS_PROJECT_PATH = "/SourceRoot/Project"; 42 private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project"; 43 private static final String VSS_USERNAME = "ant"; 44 private static final String VSS_PASSWORD = "rocks"; 45 private static final String LOCAL_PATH = "testdir"; 46 private static final String SRC_FILE = "Class1.java"; 47 private static final String SRC_LABEL = "label1"; 48 private static final String LONG_LABEL = "123456789012345678901234567890"; 49 private static final String SRC_COMMENT = "I fixed a bug"; 50 private static final String VERSION = "007"; 51 private static final String DATE = "00-00-00"; 52 private static final String DATE2 = "01-01-01"; 53 private static final String OUTPUT = "output.log"; 54 private static final String SS_DIR = "c:/winnt".replace('/', File.separatorChar); 55 56 61 public MSVSSTest(String s) { 62 super(s); 63 } 64 65 70 protected void setUp() 71 throws Exception { 72 project = new Project(); 73 project.setBasedir("."); 74 } 75 76 81 protected void tearDown() 82 throws Exception { 83 File file = new File (project.getBaseDir(), LOCAL_PATH); 84 if (file.exists()) { 85 file.delete(); 86 } 87 } 88 89 90 public void testGetCommandLine() { 91 String [] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_GET, DS_VSS_PROJECT_PATH, 92 MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir().getAbsolutePath() 93 + File.separator + LOCAL_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, 94 MSVSS.FLAG_RECURSION, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN 95 + VSS_USERNAME + "," + VSS_PASSWORD, FLAG_FILETIME_UPDATED, FLAG_SKIP_WRITABLE}; 96 97 MSVSSGET vssGet = new MSVSSGET(); 99 vssGet.setProject(project); 100 vssGet.setRecursive(true); 101 vssGet.setLocalpath(new Path(project, LOCAL_PATH)); 102 vssGet.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); 103 vssGet.setVersion(VERSION); 104 vssGet.setQuiet(false); 105 vssGet.setDate(DATE); 106 vssGet.setLabel(SRC_LABEL); 107 vssGet.setVsspath(VSS_PROJECT_PATH); 108 MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated(); 109 cmu.setValue(TIME_UPDATED); 110 vssGet.setFileTimeStamp(cmu); 111 MSVSS.WritableFiles wf = new MSVSS.WritableFiles(); 112 wf.setValue(WRITABLE_SKIP); 113 vssGet.setWritableFiles(wf); 114 115 commandline = vssGet.buildCmdLine(); 116 117 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 118 } 119 120 121 public void testGetExceptions() { 122 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); 123 expectSpecificBuildException("vssget.1", "some cause", "vsspath attribute must be set!"); 124 } 125 126 127 public void testLabelCommandLine1() { 128 String [] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH, 129 MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_YES, 130 MSVSS.FLAG_LABEL + SRC_LABEL, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN 131 + VSS_USERNAME + "," + VSS_PASSWORD}; 132 133 MSVSSLABEL vssLabel = new MSVSSLABEL(); 135 vssLabel.setProject(project); 136 vssLabel.setComment(SRC_COMMENT); 137 vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); 138 vssLabel.setVersion(VERSION); 139 vssLabel.setAutoresponse("Y"); 140 vssLabel.setLabel(SRC_LABEL); 141 vssLabel.setVsspath(VSS_PROJECT_PATH); 142 143 commandline = vssLabel.buildCmdLine(); 144 145 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 146 } 147 148 149 public void testLabelCommandLine2() { 150 String [] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH, 151 MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_DEF, 152 MSVSS.FLAG_LABEL + LONG_LABEL, 153 MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD}; 154 155 MSVSSLABEL vssLabel = new MSVSSLABEL(); 157 vssLabel.setProject(project); 158 vssLabel.setComment(SRC_COMMENT); 159 vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); 160 vssLabel.setLabel(LONG_LABEL + "blahblah"); 161 vssLabel.setVsspath(VSS_PROJECT_PATH); 162 163 commandline = vssLabel.buildCmdLine(); 164 165 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 166 } 167 168 171 public void testLabelExceptions() { 172 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); 173 expectSpecificBuildException("vsslabel.1", "some cause", "vsspath attribute must be set!"); 174 expectSpecificBuildException("vsslabel.2", "some cause", "label attribute must be set!"); 175 } 176 177 178 public void testHistoryCommandLine1() { 179 String [] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, 180 MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_LABEL + LONG_LABEL 181 + MSVSS.VALUE_FROMLABEL + SRC_LABEL, MSVSS.FLAG_LOGIN + VSS_USERNAME 182 + "," + VSS_PASSWORD, MSVSS.FLAG_OUTPUT + project.getBaseDir().getAbsolutePath() 183 + File.separator + OUTPUT}; 184 185 MSVSSHISTORY vssHistory = new MSVSSHISTORY(); 187 vssHistory.setProject(project); 188 189 vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); 190 191 vssHistory.setFromLabel(SRC_LABEL); 192 vssHistory.setToLabel(LONG_LABEL + "blahblah"); 193 vssHistory.setVsspath(VSS_PROJECT_PATH); 194 vssHistory.setRecursive(false); 195 vssHistory.setOutput(new File (project.getBaseDir().getAbsolutePath(), OUTPUT)); 196 197 commandline = vssHistory.buildCmdLine(); 198 199 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 200 } 201 202 203 public void testHistoryCommandLine2() { 204 String [] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, 205 MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + DATE + MSVSS.VALUE_FROMDATE 206 + DATE2, MSVSS.FLAG_RECURSION, MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD}; 207 208 MSVSSHISTORY vssHistory = new MSVSSHISTORY(); 210 vssHistory.setProject(project); 211 vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); 212 vssHistory.setFromDate(DATE2); 213 vssHistory.setToDate(DATE); 214 vssHistory.setVsspath(VSS_PROJECT_PATH); 215 vssHistory.setRecursive(true); 216 217 commandline = vssHistory.buildCmdLine(); 218 219 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 220 } 221 222 223 public void testHistoryCommandLine3() { 224 Tstamp tstamp = new Tstamp(); 226 Location location = new Location("src/etc/testcases/taskdefs/optional/vss/vss.xml"); 227 tstamp.setLocation(location); 228 tstamp.setProject(project); 229 Tstamp.CustomFormat format = tstamp.createFormat(); 230 format.setProperty("today"); 231 format.setPattern("HH:mm:ss z"); 232 format.setTimezone("GMT"); 233 Date date = Calendar.getInstance().getTime(); 234 format.execute(project, date, location); 235 String today = project.getProperty("today"); 236 237 SimpleDateFormat sdf = new SimpleDateFormat ("HH:mm:ss z"); 239 sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); 240 String expected = sdf.format(date); 241 242 MSVSSHISTORY vssHistory = new MSVSSHISTORY(); 244 vssHistory.setProject(project); 245 vssHistory.setLogin(VSS_USERNAME); 246 vssHistory.setToDate(today); 247 vssHistory.setVsspath(VSS_PROJECT_PATH); 248 249 String [] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, 250 MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + expected, MSVSS.FLAG_LOGIN + VSS_USERNAME}; 251 252 commandline = vssHistory.buildCmdLine(); 253 254 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 255 } 256 257 260 public void testHistoryExceptions() { 261 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); 262 expectSpecificBuildException("vsshistory.1", "some cause", "vsspath attribute must be set!"); 263 } 264 265 266 public void testCheckinCommandLine() { 267 String [] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CHECKIN, DS_VSS_PROJECT_PATH, 268 MSVSS.FLAG_AUTORESPONSE_NO, MSVSS.FLAG_WRITABLE, MSVSS.FLAG_LOGIN + VSS_USERNAME, 269 MSVSS.FLAG_COMMENT + SRC_COMMENT}; 270 271 MSVSSCHECKIN vssCheckin = new MSVSSCHECKIN(); 273 vssCheckin.setProject(project); 274 vssCheckin.setComment(SRC_COMMENT); 275 vssCheckin.setLogin(VSS_USERNAME); 276 vssCheckin.setAutoresponse("N"); 277 vssCheckin.setVsspath(VSS_PROJECT_PATH); 278 vssCheckin.setWritable(true); 279 280 commandline = vssCheckin.buildCmdLine(); 281 282 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 283 } 284 285 288 public void testCheckinExceptions() { 289 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); 290 expectSpecificBuildException("vsscheckin.1", "some cause", "vsspath attribute must be set!"); 291 } 292 293 294 public void testCheckoutCommandLine() { 295 String [] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_CHECKOUT, 296 DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION, 297 MSVSS.FLAG_VERSION_DATE + DATE, MSVSS.FLAG_LOGIN + VSS_USERNAME, 298 FLAG_FILETIME_MODIFIED, FLAG_NO_GET}; 299 300 MSVSSCHECKOUT vssCheckout = new MSVSSCHECKOUT(); 302 vssCheckout.setProject(project); 303 vssCheckout.setLogin(VSS_USERNAME); 304 vssCheckout.setVsspath(DS_VSS_PROJECT_PATH); 305 vssCheckout.setRecursive(true); 306 vssCheckout.setDate(DATE); 307 vssCheckout.setLabel(SRC_LABEL); 308 vssCheckout.setSsdir(SS_DIR); 309 MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated(); 310 cmu.setValue(TIME_MODIFIED); 311 vssCheckout.setFileTimeStamp(cmu); 312 vssCheckout.setGetLocalCopy(false); 313 314 commandline = vssCheckout.buildCmdLine(); 315 316 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 317 } 318 319 322 public void testCheckoutExceptions() { 323 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); 324 expectSpecificBuildException("vsscheckout.1", "some cause", "vsspath attribute must be set!"); 325 expectSpecificBuildException("vsscheckout.2", "some cause", "blah is not a legal value for this attribute"); 326 } 327 328 329 public void testAddCommandLine() { 330 String [] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_ADD, 331 project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH, 332 MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION, 333 MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD, MSVSS.FLAG_COMMENT + "-"}; 334 335 MSVSSADD vssAdd = new MSVSSADD(); 337 vssAdd.setProject(project); 338 vssAdd.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); 339 vssAdd.setVsspath(DS_VSS_PROJECT_PATH); 340 vssAdd.setRecursive(true); 341 vssAdd.setSsdir(SS_DIR); 342 vssAdd.setWritable(false); 343 vssAdd.setLocalpath(new Path(project, LOCAL_PATH)); 344 345 commandline = vssAdd.buildCmdLine(); 346 347 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 348 } 349 350 353 public void testAddExceptions() { 354 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); 355 expectSpecificBuildException("vssadd.1", "some cause", "localPath attribute must be set!"); 356 } 357 358 359 public void testCpCommandLine() { 360 String [] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CP, 361 DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_LOGIN + 362 VSS_USERNAME}; 363 364 MSVSSCP vssCp = new MSVSSCP(); 366 vssCp.setProject(project); 367 vssCp.setLogin(VSS_USERNAME); 368 vssCp.setVsspath(DS_VSS_PROJECT_PATH); 369 370 commandline = vssCp.buildCmdLine(); 371 372 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 373 } 374 375 378 public void testCpExceptions() { 379 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); 380 expectSpecificBuildException("vsscp.1", "some cause", "vsspath attribute must be set!"); 381 } 382 383 384 public void testCreateCommandLine() { 385 String [] sTestCmdLine = { MSVSS.SS_EXE, MSVSS.COMMAND_CREATE, 386 DS_VSS_PROJECT_PATH, MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_NO, 387 MSVSS.FLAG_QUIET, MSVSS.FLAG_LOGIN + VSS_USERNAME}; 388 389 MSVSSCREATE vssCreate = new MSVSSCREATE(); 391 vssCreate.setProject(project); 392 vssCreate.setComment(SRC_COMMENT); 393 vssCreate.setLogin(VSS_USERNAME); 394 vssCreate.setVsspath(DS_VSS_PROJECT_PATH); 395 vssCreate.setFailOnError(true); 396 vssCreate.setAutoresponse("N"); 397 vssCreate.setQuiet(true); 398 399 commandline = vssCreate.buildCmdLine(); 400 401 checkCommandLines(sTestCmdLine, commandline.getCommandline()); 402 } 403 404 407 public void testCreateExceptions() { 408 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); 409 expectSpecificBuildException("vsscreate.1", "some cause", "vsspath attribute must be set!"); 410 } 411 412 417 private void checkCommandLines(String [] sTestCmdLine, String [] sGeneratedCmdLine) { 418 int testLength = sTestCmdLine.length; 419 int genLength = sGeneratedCmdLine.length; 420 421 int genIndex = 0; 422 int testIndex = 0; 423 424 while (testIndex < testLength) { 425 try { 426 if (sGeneratedCmdLine[genIndex] == "") { 427 genIndex++; 428 continue; 429 } 430 assertEquals("arg # " + testIndex, 431 sTestCmdLine[testIndex], 432 sGeneratedCmdLine[genIndex]); 433 testIndex++; 434 genIndex++; 435 } catch (ArrayIndexOutOfBoundsException aioob) { 436 fail("missing arg " + sTestCmdLine[testIndex]); 437 } 438 } 439 440 int cnt = 0; 442 for (int i = 0; i < genLength; i++) { 443 if (sGeneratedCmdLine[i] == "") { 444 cnt++; 445 } 446 } 447 if (genLength - cnt > sTestCmdLine.length) { 448 fail("extra args"); 450 } 451 } 452 } 453 | Popular Tags |