1 37 package net.sourceforge.cruisecontrol.sourcecontrols; 38 39 import junit.framework.TestCase; 40 import net.sourceforge.cruisecontrol.CruiseControlException; 41 import net.sourceforge.cruisecontrol.Modification; 42 43 import java.io.BufferedInputStream ; 44 import java.io.IOException ; 45 import java.io.InputStream ; 46 import java.text.ParseException ; 47 import java.text.SimpleDateFormat ; 48 import java.util.Collections ; 49 import java.util.Date ; 50 import java.util.List ; 51 52 53 60 public class SnapshotCMTest extends TestCase { 61 62 private Date parseSnaphotOutDateFormat(String dateString) throws ParseException { 63 return new SimpleDateFormat (SnapshotCM.OUT_DATE_FORMAT).parse(dateString); 64 } 65 66 public void testValidate() throws CruiseControlException, IOException { 67 SnapshotCM snaphotCM = new SnapshotCM(); 68 69 try { 70 snaphotCM.validate(); 71 fail("SnapshotCM should throw exceptions when required fields are not set."); 72 } catch (CruiseControlException e) { 73 } 74 75 snaphotCM.setSourcePath("thePath"); 76 77 try { 78 snaphotCM.validate(); 79 } catch (CruiseControlException e) { 80 fail("SnapshotCM should not throw exceptions when required fields are set."); 81 } 82 83 } 85 86 private InputStream loadTestLog(String name) { 87 InputStream testStream = getClass().getResourceAsStream(name); 88 assertNotNull("failed to load resource " + name + " in class " + getClass().getName(), testStream); 89 return testStream; 90 } 91 92 public void testParseStream() throws IOException , ParseException { 93 SnapshotCM snaphotCM = new SnapshotCM(); 94 95 BufferedInputStream input = 96 new BufferedInputStream (loadTestLog("snapshotcm-history.txt")); 97 List modifications = snaphotCM.parseStream(input); 98 input.close(); 99 Collections.sort(modifications); 100 101 assertEquals("Should have returned 3 modifications.", 102 3, 103 modifications.size()); 104 105 Modification mod1 = new Modification("Content"); 106 Modification.ModifiedFile mod1file = mod1.createModifiedFile("build.xml", "/xxx/yyy/cccc/dddd"); 107 mod1file.action = "modified"; 108 mod1.revision = "18"; 109 mod1.modifiedTime = parseSnaphotOutDateFormat("2004/01/06 15:49:38"); 110 mod1.userName = "pacon"; 111 mod1.comment = 112 "Corrected capitalization for all parameters"; 113 114 Modification mod2 = new Modification("Content"); 115 Modification.ModifiedFile mod2file = mod2.createModifiedFile("build.xml", "/xxx/yyy/cccc/dddd"); 116 mod2file.action = "modified"; 117 mod2.revision = "19"; 118 mod2.modifiedTime = parseSnaphotOutDateFormat("2004/01/06 17:00:40"); 119 mod2.userName = "pacon"; 120 mod2.comment = "Removed -D param from SnapshotCM wco and wci commands."; 121 122 Modification mod3 = new Modification("Content"); 123 Modification.ModifiedFile mod3file = 124 mod3.createModifiedFile("wallawalla", "/xxx/yyy/zzzz/scripts/sbin/init.d/"); 125 mod3file.action = "modified"; 126 mod3.revision = "8"; 127 mod3.modifiedTime = parseSnaphotOutDateFormat("2004/01/07 09:51:34"); 128 mod3.userName = "pacon"; 129 mod3.comment = "remove obsolete comment"; 130 131 assertEquals(mod1, modifications.get(0)); 132 assertEquals(mod2, modifications.get(1)); 133 assertEquals(mod3, modifications.get(2)); 134 } 135 } 136 | Popular Tags |