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 java.util.ArrayList;
039: import java.util.Date;
040: import java.util.List;
041:
042: import junit.framework.TestCase;
043: import net.sourceforge.cruisecontrol.CruiseControlException;
044: import net.sourceforge.cruisecontrol.Modification;
045: import net.sourceforge.cruisecontrol.util.Commandline;
046:
047: public class MKSTest extends TestCase {
048:
049: public void testShouldReturnPreviousModificationOnlyWhenPassedSameLastBuildDate() {
050: final List expected = new ArrayList();
051:
052: MKS mks = new MKS() {
053:
054: Commandline createResyncCommandLine(String projectFilePath) {
055: return null;
056: }
057:
058: void executeResyncAndParseModifications(
059: Commandline cmdLine, List modifications) {
060: Modification mod = new Modification();
061: mod.modifiedTime = new Date();
062: mod.userName = "";
063:
064: expected.add(mod);
065: modifications.add(mod);
066: }
067:
068: String getProjectFilePath() {
069: return null;
070: }
071:
072: };
073:
074: Date lastBuild = new Date(10000);
075:
076: List actual = mks.getModifications(lastBuild, null);
077: assertEquals(1, actual.size());
078: assertEquals(expected.get(0), actual.get(0));
079:
080: actual = mks.getModifications(lastBuild, null);
081: assertEquals(2, actual.size());
082: assertEquals(expected.get(0), actual.get(0));
083: assertEquals(expected.get(1), actual.get(1));
084:
085: Date newLastBuild = new Date(20000);
086: actual = mks.getModifications(newLastBuild, null);
087: assertEquals(1, actual.size());
088: assertEquals(expected.get(2), actual.get(0));
089: }
090:
091: public void testValidate() {
092:
093: MKS mks = new MKS();
094:
095: try {
096: mks.validate();
097: fail("MKS should throw exceptions when required attributes are not set.");
098: } catch (CruiseControlException e) {
099: assertTrue(true);
100: }
101:
102: mks.setLocalWorkingDir("empty");
103:
104: try {
105: mks.validate();
106: fail("MKS should throw exceptions when required attributes are not set.");
107: } catch (CruiseControlException e) {
108: assertTrue(true);
109: }
110:
111: mks.setProject("empty");
112:
113: try {
114: mks.validate();
115: assertTrue(true);
116: } catch (CruiseControlException e) {
117: fail("MKS should not throw exceptions when required attributes are set.");
118: }
119: }
120: }
|