001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol.sourcecontrols;
037:
038: import junit.framework.TestCase;
039: import net.sourceforge.cruisecontrol.CruiseControlException;
040: import net.sourceforge.cruisecontrol.Modification;
041:
042: import java.io.BufferedInputStream;
043: import java.io.IOException;
044: import java.io.InputStream;
045: import java.text.ParseException;
046: import java.text.SimpleDateFormat;
047: import java.util.Collections;
048: import java.util.Date;
049: import java.util.List;
050:
051: /**
052: * Things that could/should be improved:
053: * <ul>
054: * <li> test using a server lying in a different timezone. Right now it's not handled.
055: * </ul>
056: * @author <a href="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a>
057: */
058: public class SnapshotCMTest extends TestCase {
059:
060: private Date parseSnaphotOutDateFormat(String dateString)
061: throws ParseException {
062: return new SimpleDateFormat(SnapshotCM.OUT_DATE_FORMAT)
063: .parse(dateString);
064: }
065:
066: public void testValidate() {
067: SnapshotCM snaphotCM = new SnapshotCM();
068:
069: try {
070: snaphotCM.validate();
071: fail("SnapshotCM should throw exceptions when required fields are not set.");
072: } catch (CruiseControlException e) {
073: }
074:
075: snaphotCM.setSourcePath("thePath");
076:
077: try {
078: snaphotCM.validate();
079: } catch (CruiseControlException e) {
080: fail("SnapshotCM should not throw exceptions when required fields are set.");
081: }
082:
083: // test validity of the path format?
084: }
085:
086: private InputStream loadTestLog(String name) {
087: InputStream testStream = getClass().getResourceAsStream(name);
088: assertNotNull("failed to load resource " + name + " in class "
089: + getClass().getName(), testStream);
090: return testStream;
091: }
092:
093: public void testParseStream() throws IOException, ParseException {
094: SnapshotCM snaphotCM = new SnapshotCM();
095:
096: BufferedInputStream input = new BufferedInputStream(
097: loadTestLog("snapshotcm-history.txt"));
098: List modifications = snaphotCM.parseStream(input);
099: input.close();
100: Collections.sort(modifications);
101:
102: assertEquals("Should have returned 3 modifications.", 3,
103: modifications.size());
104:
105: Modification mod1 = new Modification("Content");
106: Modification.ModifiedFile mod1file = mod1.createModifiedFile(
107: "build.xml", "/xxx/yyy/cccc/dddd");
108: mod1file.action = "modified";
109: mod1.revision = "18";
110: mod1.modifiedTime = parseSnaphotOutDateFormat("2004/01/06 15:49:38");
111: mod1.userName = "pacon";
112: mod1.comment = "Corrected capitalization for all parameters";
113:
114: Modification mod2 = new Modification("Content");
115: Modification.ModifiedFile mod2file = mod2.createModifiedFile(
116: "build.xml", "/xxx/yyy/cccc/dddd");
117: mod2file.action = "modified";
118: mod2.revision = "19";
119: mod2.modifiedTime = parseSnaphotOutDateFormat("2004/01/06 17:00:40");
120: mod2.userName = "pacon";
121: mod2.comment = "Removed -D param from SnapshotCM wco and wci commands.";
122:
123: Modification mod3 = new Modification("Content");
124: Modification.ModifiedFile mod3file = mod3.createModifiedFile(
125: "wallawalla", "/xxx/yyy/zzzz/scripts/sbin/init.d/");
126: mod3file.action = "modified";
127: mod3.revision = "8";
128: mod3.modifiedTime = parseSnaphotOutDateFormat("2004/01/07 09:51:34");
129: mod3.userName = "pacon";
130: mod3.comment = "remove obsolete comment";
131:
132: assertEquals(mod1, modifications.get(0));
133: assertEquals(mod2, modifications.get(1));
134: assertEquals(mod3, modifications.get(2));
135: }
136: }
|