KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.text.ParseException JavaDoc;
40 import java.text.SimpleDateFormat JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.Date JavaDoc;
43 import java.util.List JavaDoc;
44 import java.util.Locale JavaDoc;
45
46 import junit.framework.TestCase;
47 import net.sourceforge.cruisecontrol.CruiseControlException;
48 import net.sourceforge.cruisecontrol.Modification;
49
50 /**
51  * @author Eli Tucker
52  * @author Simon Brandhof
53  */

54 public class VssJournalTest extends TestCase {
55     private static final String JavaDoc SS_DIR = "/";
56     private static final String JavaDoc PROPERTY_ON_DELETE = "deletedfiles";
57     
58     private VssJournal element;
59     
60     public VssJournalTest(String JavaDoc name) {
61         super(name);
62     }
63
64     protected void setUp() {
65         // Set up so that this element will match all tests.
66
element = new VssJournal();
67         element.setSsDir(SS_DIR);
68         element.setLastBuildDate(new Date JavaDoc(0));
69         element.setPropertyOnDelete(PROPERTY_ON_DELETE);
70     }
71
72     public void testValidate() {
73         VssJournal vj = new VssJournal();
74
75         try {
76             vj.validate();
77             fail("VssJournal should throw exceptions when required attributes are not set.");
78         } catch (CruiseControlException e) {
79             assertTrue(true);
80         }
81
82         vj.setJournalFile("journalfile");
83         vj.setSsDir("ssdir");
84
85         try {
86             vj.validate();
87             assertTrue(true);
88         } catch (CruiseControlException e) {
89             fail("VssJournal should not throw exceptions when required attributes are set.");
90         }
91     }
92
93     public void testSubstringToLastSlash() {
94         assertTrue("$/Eclipse/src/main/com/itxc".equals(
95          element.substringToLastSlash("$/Eclipse/src/main/com/itxc/eclipse")));
96     }
97     
98     public void testSubstringFromLastSlash() {
99         assertTrue("eclipse".equals(
100          element.substringFromLastSlash("$/Eclipse/src/main/com/itxc/eclipse")));
101     }
102
103     public void testIsInSsDir() {
104         VssJournal element1 = new VssJournal();
105         element1.setSsDir("/somedir");
106         assertTrue(element1.isInSsDir("$/somedir"));
107         assertTrue(element1.isInSsDir("$/somedir/Hello/There"));
108         assertFalse(element1.isInSsDir("$/somedir2/Another/Directory/page.htm"));
109         // Should be case insensitive
110
assertTrue(element1.isInSsDir("$/SomeDir/Another/Directory/page.htm"));
111         
112         element1.setSsDir("/somedir/");
113         assertTrue(element1.isInSsDir("$/somedir"));
114         assertTrue(element1.isInSsDir("$/somedir/Hello/There"));
115         assertFalse(element1.isInSsDir("$/somedir2/Another/Directory/page.htm"));
116         
117         element1.setSsDir("/");
118         assertTrue(element1.isInSsDir("$/anythingCouldBeHere/Blah/blah"));
119         assertTrue(element1.isInSsDir("$/"));
120         
121         element1.setSsDir("$/");
122         assertTrue(element1.isInSsDir("$/anythingCouldBeHere/Blah/blah"));
123         assertTrue(element1.isInSsDir("$/"));
124         
125         element1.setSsDir("$/somedir/");
126         assertTrue(element1.isInSsDir("$/somedir"));
127         assertTrue(element1.isInSsDir("$/somedir/Hello/There"));
128         assertFalse(element1.isInSsDir("$/somedir2/Another/Directory/page.htm"));
129     }
130     
131     public void testIsBeforeLastBuild() {
132         VssJournal element1 = new VssJournal();
133         long beforeTime = System.currentTimeMillis();
134         long afterTime = beforeTime + 50000;
135
136         element1.setLastBuildDate(new Date JavaDoc(beforeTime));
137         assertTrue(!element1.isBeforeLastBuild(new Date JavaDoc(afterTime)));
138     }
139     
140     public void testHandleEntryCheckin() {
141         List JavaDoc entry = new ArrayList JavaDoc();
142         entry.add("$/AutoBuild/conf/cruisecontrol.properties");
143         entry.add("Version: 5");
144         entry.add("User: Etucker Date: 7/06/01 Time: 2:11p");
145         entry.add("Checked in");
146         entry.add("Comment: Making cc email users when build failed");
147         
148         Modification mod = element.handleEntry(entry);
149         assertEquals(mod.getFileName(), "cruisecontrol.properties");
150         assertEquals(mod.getFolderName(), "$/AutoBuild/conf");
151         assertEquals(mod.comment, "Comment: Making cc email users when build failed");
152         assertEquals(mod.userName, "Etucker");
153         assertEquals(mod.type, "vss");
154
155         Modification.ModifiedFile modfile = (Modification.ModifiedFile) mod.files.get(0);
156         assertEquals(modfile.action, "checkin");
157         assertNull(element.getProperties().get(PROPERTY_ON_DELETE));
158     }
159     
160     public void testHandleEntryRename() {
161         List JavaDoc entry = new ArrayList JavaDoc();
162         entry.add("$/WILD/Client/English");
163         entry.add("Version: 15");
164         entry.add("User: Ddavis Date: 7/10/01 Time: 10:41a");
165         entry.add("body3.htm renamed to step3.htm ");
166         
167         Modification mod = element.handleEntry(entry);
168         assertEquals(mod.getFileName(), "body3.htm");
169         assertEquals(mod.getFolderName(), "$/WILD/Client/English");
170         assertEquals(mod.comment, "");
171         assertEquals(mod.userName, "Ddavis");
172         assertEquals(mod.type, "vss");
173         
174         Modification.ModifiedFile modfile = (Modification.ModifiedFile) mod.files.get(0);
175         assertEquals(modfile.action, "delete");
176         assertNotNull(element.getProperties().get(PROPERTY_ON_DELETE));
177     }
178     
179     public void testHandleEntryLabel() {
180         List JavaDoc entry = new ArrayList JavaDoc();
181         entry.add("$/ThirdPartyComponents/jakarta-ant-1.3/lib");
182         entry.add("Version: 7");
183         entry.add("User: Etucker Date: 7/06/01 Time: 10:28a");
184         entry.add("Labeled test_label");
185         entry.add("Comment: Just testing to see what all gets put in the log file");
186         
187         Modification mod = element.handleEntry(entry);
188         
189         assertEquals("Label entry added. Labels shouldn't be added.",
190                      null, mod);
191         assertNull(element.getProperties().get(PROPERTY_ON_DELETE));
192     }
193     
194     public void testParseDate() throws ParseException JavaDoc {
195         Date JavaDoc date = element.parseDate("User: Etucker Date: 7/25/01 Time: 2:11p");
196         SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc("MM/dd/yy hh:mm", Locale.US);
197         assertEquals(sdf.parse("07/25/01 14:11"), date);
198         
199         element.setDateFormat("d.MM.yy");
200         element.setTimeFormat("hh:mm");
201         date = element.parseDate("User: Brandhof Date: 15.11.05 Time: 16:54");
202         assertEquals(sdf.parse("11/15/05 16:54"), date);
203     }
204
205 }
206     
207
Popular Tags