1 37 package net.sourceforge.cruisecontrol.sourcecontrols; 38 39 import java.io.File ; 40 import java.text.ParseException ; 41 import java.text.SimpleDateFormat ; 42 import java.util.ArrayList ; 43 import java.util.Date ; 44 import java.util.List ; 45 import java.util.Map ; 46 47 import junit.framework.TestCase; 48 import net.sourceforge.cruisecontrol.CruiseControlException; 49 import net.sourceforge.cruisecontrol.Modification; 50 51 55 public class VssTest extends TestCase { 56 57 private Vss vss; 58 59 private static final String DATE_TIME_STRING = "Date: 6/20/01 Time: 10:36a"; 60 private static final String ALTERNATE_DATE_TIME_STRING = "Date: 20/6/01 Time: 10:36"; 61 62 protected void setUp() { 63 vss = new Vss(); 64 } 65 66 protected void tearDown() { 67 vss = null; 68 } 69 70 public void testValidate() { 71 try { 72 vss.validate(); 73 fail("Vss should throw exceptions when required fields are not set."); 74 } catch (CruiseControlException e) { 75 assertTrue(true); 76 } 77 78 vss.setVsspath("vsspath"); 79 vss.setLogin("login"); 80 81 try { 82 vss.validate(); 83 assertTrue(true); 84 } catch (CruiseControlException e) { 85 fail("Vss should not throw exceptions when required fields are set."); 86 } 87 } 88 89 public void testParseUserSingleCharName() { 90 String testName = "1"; 91 assertEquals(testName, vss.parseUser(createVSSLine(testName, DATE_TIME_STRING))); 92 } 93 94 public void testParseDateSingleCharName() { 95 String testName = "1"; 96 try { 97 assertEquals( 98 vss.getVssDateTimeFormat().parse(DATE_TIME_STRING.trim() + "m"), 99 vss.parseDate(createVSSLine(testName, DATE_TIME_STRING))); 100 101 } catch (ParseException e) { 102 fail("Could not parse date string: " + e.getMessage()); 103 } 104 } 105 106 109 public void testParseDateAlternate() { 110 String testName = "1"; 111 vss.setDateFormat("dd/MM/yy"); 112 vss.setTimeFormat("HH:mm"); 113 try { 114 assertEquals( 115 vss.getVssDateTimeFormat().parse(ALTERNATE_DATE_TIME_STRING.trim()), 116 vss.parseDate(createVSSLine(testName, ALTERNATE_DATE_TIME_STRING))); 117 } catch (ParseException e) { 118 fail("Could not parse date string: " + e.getMessage()); 119 } 120 } 121 122 128 public void testParseDateStrangeDate() { 129 String strangeDateLine = "User: Aaggarwa Date: 6/20/:1 Time: 10:36a"; 130 try { 131 assertEquals( 132 vss.getVssDateTimeFormat().parse(DATE_TIME_STRING.trim() + "m"), 133 vss.parseDate(strangeDateLine)); 134 } catch (ParseException e) { 135 fail("Could not parse strange date string: " + e.getMessage()); 136 } 137 } 138 139 public void testParseUser10CharName() { 140 String testName = "1234567890"; 141 assertEquals(testName, vss.parseUser(createVSSLine(testName, DATE_TIME_STRING))); 142 } 143 144 public void testParseUser20CharName() { 145 String testName = "12345678900987654321"; 146 assertEquals(testName, vss.parseUser(createVSSLine(testName, DATE_TIME_STRING))); 147 } 148 149 public void testHandleEntryWithLabel() { 150 151 154 List entry = new ArrayList (); 155 entry.add("***** DateChooser.java *****"); 156 entry.add("Version 8"); 157 entry.add("Label: \"Completely new version!\""); 158 entry.add("User: Arass Date: 10/21/02 Time: 12:48p"); 159 entry.add("Checked in $/code/development/src/org/ets/cbtidg/common/gui"); 160 entry.add("Comment: This is where I add a completely new, but alot nicer version of the date chooser."); 161 162 Modification modification = vss.handleEntry(entry); 163 assertEquals("DateChooser.java", modification.getFileName()); 164 165 assertEquals("/code/development/src/org/ets/cbtidg/common/gui", modification.getFolderName()); 166 assertEquals( 167 "Comment: This is where I add a completely new, but alot nicer version of the date chooser.", 168 modification.comment); 169 assertEquals("Arass", modification.userName); 170 171 Modification.ModifiedFile modfile = (Modification.ModifiedFile) modification.files.get(0); 172 assertEquals("checkin", modfile.action); 173 } 174 175 public void testHandleEntryCheckinWithComment() { 176 List entry = new ArrayList (); 177 entry.add("***** ttyp_direct.properties *****"); 178 entry.add("Version 10"); 179 entry.add("User: Etucker Date: 7/03/01 Time: 3:24p"); 180 entry.add("Checked in $/Eclipse/src/main/com/itxc/eclipse/some/path/here"); 181 entry.add("Comment: updated country codes for Colombia and Slovokia"); 182 183 Modification mod = vss.handleEntry(entry); 184 assertEquals(mod.getFileName(), "ttyp_direct.properties"); 185 assertEquals(mod.getFolderName(), "/Eclipse/src/main/com/itxc/eclipse/some/path/here"); 186 assertEquals(mod.comment, "Comment: updated country codes for Colombia and Slovokia"); 187 assertEquals(mod.userName, "Etucker"); 188 189 Modification.ModifiedFile modfile = (Modification.ModifiedFile) mod.files.get(0); 190 assertEquals(modfile.action, "checkin"); 191 } 192 193 public void testHandleEntryShared() { 194 List entry = new ArrayList (); 195 vss.setVsspath("\\vsspath"); 196 entry.add("***** a *****"); 197 entry.add("Version 19"); 198 entry.add("User: Etucker Date: 7/03/01 Time: 11:16a"); 199 entry.add("$/Users/jfredrick/test1/b/move.file.2 shared"); 200 201 Modification mod = vss.handleEntry(entry); 202 assertEquals(mod.getFileName(), "$/Users/jfredrick/test1/b/move.file.2"); 203 assertEquals(mod.userName, "Etucker"); 204 assertEquals(mod.getFolderName(), "$\\vsspath\\a"); 205 206 Modification.ModifiedFile modfile = (Modification.ModifiedFile) mod.files.get(0); 207 assertEquals(modfile.action, "share"); 208 } 209 210 public void testHandleEntryDirBranched() { 211 212 List entry = new ArrayList (); 213 vss.setVsspath("\\vsspath"); 214 entry.add("***** core *****"); 215 entry.add("Version 19"); 216 entry.add("User: Etucker Date: 7/03/01 Time: 11:16a"); 217 entry.add("SessionIdGenerator.java branched"); 218 219 Modification mod = vss.handleEntry(entry); 220 assertEquals(mod.getFileName(), "SessionIdGenerator.java"); 221 assertEquals(mod.userName, "Etucker"); 222 assertEquals(mod.getFolderName(), "$\\vsspath\\core"); 223 assertEquals(mod.type, "vss"); 224 225 Modification.ModifiedFile modfile = (Modification.ModifiedFile) mod.files.get(0); 226 assertEquals(modfile.action, "branch"); 227 } 228 229 public void testHandleEntryFileBranched() { 230 231 List entry = new ArrayList (); 232 vss.setVsspath("\\vsspath"); 233 entry.add("***** branch.file.1 *****"); 234 entry.add("Version 19"); 235 entry.add("User: Etucker Date: 7/03/01 Time: 11:16a"); 236 entry.add("Branched"); 237 238 Modification mod = vss.handleEntry(entry); 239 assertNull(mod); 240 241 } 242 243 244 public void testHandleEntryAdded() { 245 List entry = new ArrayList (); 246 vss.setVsspath("\\vsspath"); 247 entry.add("***** core *****"); 248 entry.add("Version 19"); 249 entry.add("User: Etucker Date: 7/03/01 Time: 11:16a"); 250 entry.add("SessionIdGenerator.java added"); 251 252 Modification mod = vss.handleEntry(entry); 253 assertEquals(mod.getFileName(), "SessionIdGenerator.java"); 254 assertEquals(mod.userName, "Etucker"); 255 assertEquals(mod.getFolderName(), "$\\vsspath\\core"); 256 257 Modification.ModifiedFile modfile = (Modification.ModifiedFile) mod.files.get(0); 258 assertEquals(modfile.action, "add"); 259 } 260 261 public void testHandleEntryAddedInRoot() { 262 266 267 List entry = new ArrayList (); 268 vss.setVsspath("\\vsspath"); 269 entry.add("***************** Version 19 *****************"); 270 entry.add("User: MStave Date: 7/03/01 Time: 11:16a"); 271 entry.add("SessionIdGenerator.java added"); 272 273 Modification mod = vss.handleEntry(entry); 274 assertEquals(mod.getFileName(), "SessionIdGenerator.java"); 275 assertEquals(mod.userName, "MStave"); 276 assertEquals(mod.getFolderName(), "$\\vsspath"); 277 278 Modification.ModifiedFile modfile = (Modification.ModifiedFile) mod.files.get(0); 279 assertEquals(modfile.action, "add"); 280 } 281 282 283 public void testHandleEntryRename() { 284 vss.setPropertyOnDelete("setThis"); 285 List entry = new ArrayList (); 286 entry.add("***** core *****"); 287 entry.add("Version 19"); 288 entry.add("User: Etucker Date: 7/03/01 Time: 11:16a"); 289 entry.add("SessionIdGenerator.java renamed to SessionId.java"); 290 291 Modification modification = vss.handleEntry(entry); 292 assertEquals( 293 "SessionIdGenerator.java renamed to SessionId.java", 294 modification.getFileName()); 295 assertEquals("Etucker", modification.userName); 296 297 Modification.ModifiedFile modfile = (Modification.ModifiedFile) modification.files.get(0); 298 assertEquals("rename", modfile.action); 299 300 Map properties = vss.getProperties(); 301 String setThisValue = (String ) properties.get("setThis"); 302 assertEquals("true", setThisValue); 303 } 304 305 public void testHandleEntryDestroyed() { 306 vss.setPropertyOnDelete("setThis"); 307 List entry = new ArrayList (); 308 entry.add("***** installer_vms *****"); 309 entry.add("Version 42"); 310 entry.add("User: Sfrolich Date: 11/19/02 Time: 1:40p"); 311 entry.add("IBMJDK130AIX_with_xerces.jar.vm destroyed"); 312 313 Modification modification = vss.handleEntry(entry); 314 assertEquals("IBMJDK130AIX_with_xerces.jar.vm", modification.getFileName()); 315 assertEquals("Sfrolich", modification.userName); 316 317 Modification.ModifiedFile modfile = (Modification.ModifiedFile) modification.files.get(0); 318 assertEquals("destroy", modfile.action); 319 320 Map properties = vss.getProperties(); 321 String setThisValue = (String ) properties.get("setThis"); 322 assertEquals("true", setThisValue); 323 } 324 325 public void testHandleEntryLabel() { 326 List entry = new ArrayList (); 327 entry.add("**********************"); 328 entry.add("Label: \"KonaBuild_452\""); 329 entry.add("User: Cm Date: 4/29/03 Time: 12:03a"); 330 entry.add("Labeled"); 331 entry.add("Label comment: AutoBuild KonaBuild_452"); 332 333 Modification modification = vss.handleEntry(entry); 334 assertNull(modification); 335 336 entry = new ArrayList (); 338 entry.add("***************** Version 222 *****************"); 339 entry.add("Label: \"build.83\""); 340 entry.add("User: Fabricator Date: 7/16/03 Time: 10:29a"); 341 entry.add("Labeled"); 342 entry.add(" "); 343 344 modification = vss.handleEntry(entry); 345 assertNull(modification); 346 347 entry = new ArrayList (); 349 entry.add("***** built *****"); 350 entry.add("Version 4"); 351 entry.add("Label: \"autobuild_test\""); 352 entry.add("User: Etucker Date: 6/26/01 Time: 11:53a"); 353 entry.add("Labeled"); 354 355 modification = vss.handleEntry(entry); 356 assertNull(modification); 357 } 358 359 public void testGetCommandLine() throws Exception { 360 vss.setVsspath("vsspath"); 361 vss.setLogin("login,password"); 362 363 Date lastBuild = createDate("2002/08/03 09:30:00"); Date now = createDate("2002/08/04 13:15:00"); String [] expectedCommand = 366 { 367 "ss.exe", 368 "history", 369 "$vsspath", 370 "-R", 371 "-Vd08/04/02;01:15P~08/03/02;09:30A", 372 "-Ylogin,password", 373 "-I-N", 374 "-Ovsspath.tmp" }; 375 String [] actualCommand = vss.getCommandLine(lastBuild, now); 376 for (int i = 0; i < expectedCommand.length; i++) { 377 assertEquals(expectedCommand[i], actualCommand[i]); 378 } 379 380 vss.setDateFormat("dd/MM/yy"); 381 String [] expectedCommandWithDate = 382 { 383 "ss.exe", 384 "history", 385 "$vsspath", 386 "-R", 387 "-Vd04/08/02;01:15P~03/08/02;09:30A", 388 "-Ylogin,password", 389 "-I-N", 390 "-Ovsspath.tmp" }; 391 String [] actualCommandWithDate = vss.getCommandLine(lastBuild, now); 392 for (int i = 0; i < expectedCommandWithDate.length; i++) { 393 assertEquals(expectedCommandWithDate[i], actualCommandWithDate[i]); 394 } 395 396 File execFile = new File ("..", "ss.exe"); 397 vss.setSsDir(".."); 398 System.out.println(execFile.getCanonicalPath()); 399 String [] expectedCommandWithSsdir = 400 { 401 execFile.getCanonicalPath(), 402 "history", 403 "$vsspath", 404 "-R", 405 "-Vd04/08/02;01:15P~03/08/02;09:30A", 406 "-Ylogin,password", 407 "-I-N", 408 "-Ovsspath.tmp" }; 409 String [] actualCommandWithSsdir = vss.getCommandLine(lastBuild, now); 410 for (int i = 0; i < expectedCommandWithSsdir.length; i++) { 411 assertEquals(expectedCommandWithSsdir[i], actualCommandWithSsdir[i]); 412 } 413 414 vss.setTimeFormat("HH:mm"); 415 String [] expectedCommandWithTimeFormat = 416 { 417 execFile.getCanonicalPath(), 418 "history", 419 "$vsspath", 420 "-R", 421 "-Vd04/08/02;13:15~03/08/02;09:30", 422 "-Ylogin,password", 423 "-I-N", 424 "-Ovsspath.tmp" }; 425 String [] actualCommandWithTimeFormat = vss.getCommandLine(lastBuild, now); 426 427 for (int i = 0; i < expectedCommandWithTimeFormat.length; i++) { 428 assertEquals(expectedCommandWithTimeFormat[i], actualCommandWithTimeFormat[i]); 429 } 430 } 431 432 public void testCreateFileNameFromVssPath() { 433 vss.setVsspath("//foo/bar"); 434 assertEquals("foo_bar.tmp", vss.createFileNameFromVssPath()); 435 } 436 437 440 private Date createDate(String dateString) throws ParseException { 441 SimpleDateFormat formatter = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss"); 442 return formatter.parse(dateString); 443 } 444 445 451 private String createVSSLine(String testName, String dateTimeString) { 452 return "User: " + testName + " " + dateTimeString; 453 } 454 455 public static void main(String [] args) { 456 junit.textui.TestRunner.run(VssTest.class); 457 } 458 459 } 460 | Popular Tags |