1 37 package net.sourceforge.cruisecontrol.sourcecontrols; 38 39 import java.text.ParseException ; 40 import java.text.SimpleDateFormat ; 41 import java.util.ArrayList ; 42 import java.util.Date ; 43 import java.util.List ; 44 import java.util.Locale ; 45 46 import junit.framework.TestCase; 47 import net.sourceforge.cruisecontrol.CruiseControlException; 48 import net.sourceforge.cruisecontrol.Modification; 49 50 54 public class VssJournalTest extends TestCase { 55 private static final String SS_DIR = "/"; 56 private static final String PROPERTY_ON_DELETE = "deletedfiles"; 57 58 private VssJournal element; 59 60 public VssJournalTest(String name) { 61 super(name); 62 } 63 64 protected void setUp() { 65 element = new VssJournal(); 67 element.setSsDir(SS_DIR); 68 element.setLastBuildDate(new Date (0)); 69 element.setPropertyOnDelete(PROPERTY_ON_DELETE); 70 } 71 72 public void testValidate() { 73 VssJournal vj = new VssJournal(); 74 75 try { 76 vj.validate(); 77 fail("VssJournal should throw exceptions when required attributes are not set."); 78 } catch (CruiseControlException e) { 79 assertTrue(true); 80 } 81 82 vj.setJournalFile("journalfile"); 83 vj.setSsDir("ssdir"); 84 85 try { 86 vj.validate(); 87 assertTrue(true); 88 } catch (CruiseControlException e) { 89 fail("VssJournal should not throw exceptions when required attributes are set."); 90 } 91 } 92 93 public void testSubstringToLastSlash() { 94 assertTrue("$/Eclipse/src/main/com/itxc".equals( 95 element.substringToLastSlash("$/Eclipse/src/main/com/itxc/eclipse"))); 96 } 97 98 public void testSubstringFromLastSlash() { 99 assertTrue("eclipse".equals( 100 element.substringFromLastSlash("$/Eclipse/src/main/com/itxc/eclipse"))); 101 } 102 103 public void testIsInSsDir() { 104 VssJournal element1 = new VssJournal(); 105 element1.setSsDir("/somedir"); 106 assertTrue(element1.isInSsDir("$/somedir")); 107 assertTrue(element1.isInSsDir("$/somedir/Hello/There")); 108 assertFalse(element1.isInSsDir("$/somedir2/Another/Directory/page.htm")); 109 assertTrue(element1.isInSsDir("$/SomeDir/Another/Directory/page.htm")); 111 112 element1.setSsDir("/somedir/"); 113 assertTrue(element1.isInSsDir("$/somedir")); 114 assertTrue(element1.isInSsDir("$/somedir/Hello/There")); 115 assertFalse(element1.isInSsDir("$/somedir2/Another/Directory/page.htm")); 116 117 element1.setSsDir("/"); 118 assertTrue(element1.isInSsDir("$/anythingCouldBeHere/Blah/blah")); 119 assertTrue(element1.isInSsDir("$/")); 120 121 element1.setSsDir("$/"); 122 assertTrue(element1.isInSsDir("$/anythingCouldBeHere/Blah/blah")); 123 assertTrue(element1.isInSsDir("$/")); 124 125 element1.setSsDir("$/somedir/"); 126 assertTrue(element1.isInSsDir("$/somedir")); 127 assertTrue(element1.isInSsDir("$/somedir/Hello/There")); 128 assertFalse(element1.isInSsDir("$/somedir2/Another/Directory/page.htm")); 129 } 130 131 public void testIsBeforeLastBuild() { 132 VssJournal element1 = new VssJournal(); 133 long beforeTime = System.currentTimeMillis(); 134 long afterTime = beforeTime + 50000; 135 136 element1.setLastBuildDate(new Date (beforeTime)); 137 assertTrue(!element1.isBeforeLastBuild(new Date (afterTime))); 138 } 139 140 public void testHandleEntryCheckin() { 141 List entry = new ArrayList (); 142 entry.add("$/AutoBuild/conf/cruisecontrol.properties"); 143 entry.add("Version: 5"); 144 entry.add("User: Etucker Date: 7/06/01 Time: 2:11p"); 145 entry.add("Checked in"); 146 entry.add("Comment: Making cc email users when build failed"); 147 148 Modification mod = element.handleEntry(entry); 149 assertEquals(mod.getFileName(), "cruisecontrol.properties"); 150 assertEquals(mod.getFolderName(), "$/AutoBuild/conf"); 151 assertEquals(mod.comment, "Comment: Making cc email users when build failed"); 152 assertEquals(mod.userName, "Etucker"); 153 assertEquals(mod.type, "vss"); 154 155 Modification.ModifiedFile modfile = (Modification.ModifiedFile) mod.files.get(0); 156 assertEquals(modfile.action, "checkin"); 157 assertNull(element.getProperties().get(PROPERTY_ON_DELETE)); 158 } 159 160 public void testHandleEntryRename() { 161 List entry = new ArrayList (); 162 entry.add("$/WILD/Client/English"); 163 entry.add("Version: 15"); 164 entry.add("User: Ddavis Date: 7/10/01 Time: 10:41a"); 165 entry.add("body3.htm renamed to step3.htm "); 166 167 Modification mod = element.handleEntry(entry); 168 assertEquals(mod.getFileName(), "body3.htm"); 169 assertEquals(mod.getFolderName(), "$/WILD/Client/English"); 170 assertEquals(mod.comment, ""); 171 assertEquals(mod.userName, "Ddavis"); 172 assertEquals(mod.type, "vss"); 173 174 Modification.ModifiedFile modfile = (Modification.ModifiedFile) mod.files.get(0); 175 assertEquals(modfile.action, "delete"); 176 assertNotNull(element.getProperties().get(PROPERTY_ON_DELETE)); 177 } 178 179 public void testHandleEntryLabel() { 180 List entry = new ArrayList (); 181 entry.add("$/ThirdPartyComponents/jakarta-ant-1.3/lib"); 182 entry.add("Version: 7"); 183 entry.add("User: Etucker Date: 7/06/01 Time: 10:28a"); 184 entry.add("Labeled test_label"); 185 entry.add("Comment: Just testing to see what all gets put in the log file"); 186 187 Modification mod = element.handleEntry(entry); 188 189 assertEquals("Label entry added. Labels shouldn't be added.", 190 null, mod); 191 assertNull(element.getProperties().get(PROPERTY_ON_DELETE)); 192 } 193 194 public void testParseDate() throws ParseException { 195 Date date = element.parseDate("User: Etucker Date: 7/25/01 Time: 2:11p"); 196 SimpleDateFormat sdf = new SimpleDateFormat ("MM/dd/yy hh:mm", Locale.US); 197 assertEquals(sdf.parse("07/25/01 14:11"), date); 198 199 element.setDateFormat("d.MM.yy"); 200 element.setTimeFormat("hh:mm"); 201 date = element.parseDate("User: Brandhof Date: 15.11.05 Time: 16:54"); 202 assertEquals(sdf.parse("11/15/05 16:54"), date); 203 } 204 205 } 206 207 | Popular Tags |