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 net.sourceforge.cruisecontrol.Modification;
039: import net.sourceforge.cruisecontrol.SourceControl;
040: import net.sourceforge.cruisecontrol.CruiseControlException;
041:
042: import java.util.ArrayList;
043: import java.util.Date;
044: import java.util.List;
045: import java.util.Hashtable;
046: import java.util.Map;
047:
048: public class MockSourceControl implements SourceControl {
049:
050: private int version;
051: private final Hashtable properties = new Hashtable();
052: private String property = null;
053: private String propertyOnDelete = null;
054:
055: // added this because otherwise the unit-tests doesn't work
056: // if the machine is slow. I promise, this was hard to catch :-)
057: private Date modifiedDate = new Date();
058:
059: public void setModifiedDate(final Date modifiedDate) {
060: this .modifiedDate = modifiedDate;
061: }
062:
063: public void setProperty(String property) {
064: this .property = property;
065: }
066:
067: public void setPropertyOnDelete(String propertyOnDelete) {
068: this .propertyOnDelete = propertyOnDelete;
069: }
070:
071: public Map getProperties() {
072: return properties;
073: }
074:
075: public void setType(int version) {
076: this .version = version;
077: }
078:
079: public void validate() throws CruiseControlException {
080: }
081:
082: public List getModifications(Date lastBuild, Date now) {
083: ArrayList result = new ArrayList();
084:
085: if (version == 1) {
086: //build up a couple Modification objects
087: Modification mod1 = new Modification();
088: Modification.ModifiedFile mod1file = mod1
089: .createModifiedFile("file1", "dir1");
090: mod1file.action = "Checkin";
091: mod1.userName = "user1";
092: mod1.modifiedTime = modifiedDate;
093: mod1.comment = "comment1";
094: result.add(mod1);
095:
096: Modification mod2 = new Modification();
097: Modification.ModifiedFile mod2file = mod1
098: .createModifiedFile("file2", "dir2");
099: mod2file.action = "Checkin";
100: mod2.userName = "user2";
101: mod2.modifiedTime = modifiedDate;
102: mod2.comment = "comment2";
103: result.add(mod2);
104:
105: if (property != null) {
106: properties.put(property, "true");
107: }
108: }
109:
110: if (version == 2) {
111: Modification mod3 = new Modification();
112: Modification.ModifiedFile mod3file = mod3
113: .createModifiedFile("file3", "dir3");
114: mod3file.action = "Checkin";
115: mod3.userName = "user3";
116: mod3.modifiedTime = modifiedDate;
117: mod3.comment = "comment3";
118: result.add(mod3);
119:
120: Modification mod4 = new Modification();
121: Modification.ModifiedFile mod4file = mod4
122: .createModifiedFile("file4", "dir4");
123: mod4file.action = "Checkin";
124: mod4.userName = "user4";
125: mod4.modifiedTime = modifiedDate;
126: mod4.comment = "comment4";
127: result.add(mod4);
128:
129: if (propertyOnDelete != null) {
130: properties.put(propertyOnDelete, "true");
131: }
132: }
133:
134: return result;
135: }
136:
137: }
|