KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > sourcecontrols > MockSourceControl


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2001, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.sourcecontrols;
38
39 import net.sourceforge.cruisecontrol.Modification;
40 import net.sourceforge.cruisecontrol.SourceControl;
41 import net.sourceforge.cruisecontrol.CruiseControlException;
42
43 import java.util.ArrayList JavaDoc;
44 import java.util.Date JavaDoc;
45 import java.util.List JavaDoc;
46 import java.util.Hashtable JavaDoc;
47 import java.util.Map JavaDoc;
48
49 public class MockSourceControl implements SourceControl {
50
51     private int version;
52     private Hashtable JavaDoc properties = new Hashtable JavaDoc();
53     private String JavaDoc property = null;
54     private String JavaDoc propertyOnDelete = null;
55
56     // added this because otherwise the unit-tests doesn't work
57
// if the machine is slow. I promise, this was hard to catch :-)
58
private Date JavaDoc modifiedDate = new Date JavaDoc();
59
60     
61     public void setProperty(String JavaDoc property) {
62         this.property = property;
63     }
64
65     public void setPropertyOnDelete(String JavaDoc propertyOnDelete) {
66         this.propertyOnDelete = propertyOnDelete;
67     }
68
69     public Map JavaDoc getProperties() {
70         return properties;
71     }
72
73     public void setType(int version) {
74         this.version = version;
75     }
76
77     public void validate() throws CruiseControlException {
78     }
79
80     public List JavaDoc getModifications(Date JavaDoc lastBuild, Date JavaDoc now) {
81         ArrayList JavaDoc result = new ArrayList JavaDoc();
82
83         if (version == 1) {
84             //build up a couple Modification objects
85
Modification mod1 = new Modification();
86             Modification.ModifiedFile mod1file = mod1.createModifiedFile("file1", "dir1");
87             mod1file.action = "Checkin";
88             mod1.userName = "user1";
89             mod1.modifiedTime = modifiedDate;
90             mod1.comment = "comment1";
91             result.add(mod1);
92
93             Modification mod2 = new Modification();
94             Modification.ModifiedFile mod2file = mod1.createModifiedFile("file2", "dir2");
95             mod2file.action = "Checkin";
96             mod2.userName = "user2";
97             mod2.modifiedTime = modifiedDate;
98             mod2.comment = "comment2";
99             result.add(mod2);
100
101             if (property != null) {
102                 properties.put(property, "true");
103             }
104         }
105
106         if (version == 2) {
107             Modification mod3 = new Modification();
108             Modification.ModifiedFile mod3file = mod3.createModifiedFile("file3", "dir3");
109             mod3file.action = "Checkin";
110             mod3.userName = "user3";
111             mod3.modifiedTime = modifiedDate;
112             mod3.comment = "comment3";
113             result.add(mod3);
114
115             Modification mod4 = new Modification();
116             Modification.ModifiedFile mod4file = mod4.createModifiedFile("file4", "dir4");
117             mod4file.action = "Checkin";
118             mod4.userName = "user4";
119             mod4.modifiedTime = modifiedDate;
120             mod4.comment = "comment4";
121             result.add(mod4);
122
123             if (propertyOnDelete != null) {
124                 properties.put(propertyOnDelete, "true");
125             }
126         }
127
128
129         return result;
130     }
131
132 }
Popular Tags