KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.TestCase;
40 import net.sourceforge.cruisecontrol.CruiseControlException;
41 import net.sourceforge.cruisecontrol.Modification;
42
43 import java.io.BufferedInputStream JavaDoc;
44 import java.io.IOException JavaDoc;
45 import java.io.InputStream JavaDoc;
46 import java.text.ParseException JavaDoc;
47 import java.text.SimpleDateFormat JavaDoc;
48 import java.util.Collections JavaDoc;
49 import java.util.Date JavaDoc;
50 import java.util.List JavaDoc;
51
52
53 /**
54  * Things that could/should be improved:
55  * <ul>
56  * <li> test using a server lying in a different timezone. Right now it's not handled.
57  * </ul>
58  * @author <a HREF="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a>
59  */

60 public class SnapshotCMTest extends TestCase {
61
62     private Date JavaDoc parseSnaphotOutDateFormat(String JavaDoc dateString) throws ParseException JavaDoc {
63         return new SimpleDateFormat JavaDoc(SnapshotCM.OUT_DATE_FORMAT).parse(dateString);
64     }
65
66     public void testValidate() throws CruiseControlException, IOException JavaDoc {
67         SnapshotCM snaphotCM = new SnapshotCM();
68
69         try {
70             snaphotCM.validate();
71             fail("SnapshotCM should throw exceptions when required fields are not set.");
72         } catch (CruiseControlException e) {
73         }
74
75         snaphotCM.setSourcePath("thePath");
76
77         try {
78             snaphotCM.validate();
79         } catch (CruiseControlException e) {
80             fail("SnapshotCM should not throw exceptions when required fields are set.");
81         }
82
83         // test validity of the path format?
84
}
85
86     private InputStream JavaDoc loadTestLog(String JavaDoc name) {
87         InputStream JavaDoc testStream = getClass().getResourceAsStream(name);
88         assertNotNull("failed to load resource " + name + " in class " + getClass().getName(), testStream);
89         return testStream;
90     }
91
92     public void testParseStream() throws IOException JavaDoc, ParseException JavaDoc {
93         SnapshotCM snaphotCM = new SnapshotCM();
94
95         BufferedInputStream JavaDoc input =
96                 new BufferedInputStream JavaDoc(loadTestLog("snapshotcm-history.txt"));
97         List JavaDoc modifications = snaphotCM.parseStream(input);
98         input.close();
99         Collections.sort(modifications);
100
101         assertEquals("Should have returned 3 modifications.",
102                 3,
103                 modifications.size());
104
105         Modification mod1 = new Modification("Content");
106         Modification.ModifiedFile mod1file = mod1.createModifiedFile("build.xml", "/xxx/yyy/cccc/dddd");
107         mod1file.action = "modified";
108         mod1.revision = "18";
109         mod1.modifiedTime = parseSnaphotOutDateFormat("2004/01/06 15:49:38");
110         mod1.userName = "pacon";
111         mod1.comment =
112                 "Corrected capitalization for all parameters";
113
114         Modification mod2 = new Modification("Content");
115         Modification.ModifiedFile mod2file = mod2.createModifiedFile("build.xml", "/xxx/yyy/cccc/dddd");
116         mod2file.action = "modified";
117         mod2.revision = "19";
118         mod2.modifiedTime = parseSnaphotOutDateFormat("2004/01/06 17:00:40");
119         mod2.userName = "pacon";
120         mod2.comment = "Removed -D param from SnapshotCM wco and wci commands.";
121
122         Modification mod3 = new Modification("Content");
123         Modification.ModifiedFile mod3file =
124             mod3.createModifiedFile("wallawalla", "/xxx/yyy/zzzz/scripts/sbin/init.d/");
125         mod3file.action = "modified";
126         mod3.revision = "8";
127         mod3.modifiedTime = parseSnaphotOutDateFormat("2004/01/07 09:51:34");
128         mod3.userName = "pacon";
129         mod3.comment = "remove obsolete comment";
130
131         assertEquals(mod1, modifications.get(0));
132         assertEquals(mod2, modifications.get(1));
133         assertEquals(mod3, modifications.get(2));
134     }
135 }
136
Popular Tags