KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
40 import java.util.Calendar JavaDoc;
41 import java.util.Date JavaDoc;
42
43 import junit.framework.TestCase;
44 import net.sourceforge.cruisecontrol.CruiseControlException;
45
46 public class PVCSTest extends TestCase {
47
48     private PVCS pvcs;
49
50     public void setUp() {
51         pvcs = new PVCS();
52     }
53
54     public void tearDown() {
55         pvcs = null;
56     }
57
58     public void testValidate() {
59         try {
60             pvcs.validate();
61             fail("PVCS should throw exceptions when required attributes are not set.");
62         } catch (CruiseControlException e) {
63             assertTrue(true);
64         }
65
66         pvcs.setPvcsproject("project");
67         pvcs.setPvcssubproject("subproject");
68
69         try {
70             pvcs.validate();
71             assertTrue(true);
72         } catch (CruiseControlException e) {
73             fail("PVCS should not throw exceptions when required attributes are set.");
74         }
75     }
76
77     public void testGetExecutable() {
78         String JavaDoc testExe = "testexe";
79         assertEquals(
80             "Wrong pvcs bin setting w/out bin set.",
81             testExe,
82             pvcs.getExecutable(testExe));
83
84         pvcs.setPvcsbin("mybindir");
85         assertEquals(
86             "Wrong pvcs bin setting w/ bin set.",
87             "mybindir" + File.separator + testExe,
88             pvcs.getExecutable(testExe));
89     }
90
91     public void testBuildExecCommandWithVersionLabel() {
92         pvcs.setPvcsproject("C:/PVCS-Repos/TestProject/pvcs");
93         pvcs.setPvcssubproject("/TestProject");
94         pvcs.setPvcsversionlabel("Test Version Label");
95
96         String JavaDoc ccCommand = pvcs.getExecutable("pcli") + " "
97                 + pvcs.buildExecCommand("11/23/2004 8:00AM", "11/23/2004 1:00PM");
98         String JavaDoc expectedCommand = pvcs.getExecutable("pcli")
99                 + " "
100                 + "run -ns -q -xo\"vlog.txt\" -xe\"vlog.txt\" vlog "
101                 + "-ds\"11/23/2004 8:00AM\" -de\"11/23/2004 1:00PM\" "
102                 + "-pr\"C:/PVCS-Repos/TestProject/pvcs\" -v\"Test Version Label\" "
103                 + "-z /TestProject";
104
105         assertEquals("Wrong PVCS command generated!", expectedCommand, ccCommand);
106     }
107
108     public void testBuildExecCommandWithNullVersionLabel() {
109         pvcs.setPvcsproject("C:/PVCS-Repos/TestProject/pvcs");
110         pvcs.setPvcssubproject("/TestProject");
111         pvcs.setPvcsversionlabel("");
112
113         String JavaDoc ccCommand = pvcs.getExecutable("pcli") + " "
114                 + pvcs.buildExecCommand("11/23/2004 8:00AM", "11/23/2004 1:00PM");
115         String JavaDoc expectedCommand = pvcs.getExecutable("pcli") + " "
116                 + "run -ns -q -xo\"vlog.txt\" -xe\"vlog.txt\" vlog "
117                 + "-ds\"11/23/2004 8:00AM\" -de\"11/23/2004 1:00PM\" "
118                 + "-pr\"C:/PVCS-Repos/TestProject/pvcs\" " + "-z /TestProject";
119         assertEquals("Wrong PVCS command generated!", expectedCommand, ccCommand);
120     }
121
122     public void testBuildExecCommandWithoutVersionLabel() {
123         pvcs.setPvcsproject("C:/PVCS-Repos/TestProject/pvcs");
124         pvcs.setPvcssubproject("/TestProject");
125
126         String JavaDoc ccCommand = pvcs.getExecutable("pcli") + " "
127                 + pvcs.buildExecCommand("11/23/2004 8:00AM", "11/23/2004 1:00PM");
128         String JavaDoc expectedCommand = pvcs.getExecutable("pcli") + " "
129                 + "run -ns -q -xo\"vlog.txt\" -xe\"vlog.txt\" vlog "
130                 + "-ds\"11/23/2004 8:00AM\" -de\"11/23/2004 1:00PM\" "
131                 + "-pr\"C:/PVCS-Repos/TestProject/pvcs\" " + "-z /TestProject";
132
133         assertEquals("Wrong PVCS command generated!", expectedCommand, ccCommand);
134   }
135     
136     public void testBuildExecCommandWithoutLoginId() {
137         pvcs.setPvcsproject("C:/PVCS-Repos/TestProject/pvcs");
138         pvcs.setPvcssubproject("/TestProject");
139
140         String JavaDoc ccCommand = pvcs.getExecutable("pcli") + " "
141                 + pvcs.buildExecCommand("11/23/2004 8:00AM", "11/23/2004 1:00PM");
142         String JavaDoc expectedCommand = pvcs.getExecutable("pcli") + " "
143                 + "run -ns -q -xo\"vlog.txt\" -xe\"vlog.txt\" vlog "
144                 + "-ds\"11/23/2004 8:00AM\" -de\"11/23/2004 1:00PM\" "
145                 + "-pr\"C:/PVCS-Repos/TestProject/pvcs\" " + "-z /TestProject";
146
147         assertEquals("Wrong PVCS command generated!", expectedCommand, ccCommand);
148     }
149     
150     public void testBuildExecCommandWithEmptyLoginId() {
151         pvcs.setPvcsproject("C:/PVCS-Repos/TestProject/pvcs");
152         pvcs.setPvcssubproject("/TestProject");
153         pvcs.setLoginid("");
154
155         String JavaDoc ccCommand = pvcs.getExecutable("pcli") + " "
156                 + pvcs.buildExecCommand("11/23/2004 8:00AM", "11/23/2004 1:00PM");
157         String JavaDoc expectedCommand = pvcs.getExecutable("pcli") + " "
158                 + "run -ns -q -xo\"vlog.txt\" -xe\"vlog.txt\" vlog "
159                 + "-ds\"11/23/2004 8:00AM\" -de\"11/23/2004 1:00PM\" "
160                 + "-pr\"C:/PVCS-Repos/TestProject/pvcs\" " + "-z /TestProject";
161
162         assertEquals("Wrong PVCS command generated!", expectedCommand, ccCommand);
163     }
164     
165     public void testBuildExecCommandWithLoginId() {
166         pvcs.setPvcsproject("C:/PVCS-Repos/TestProject/pvcs");
167         pvcs.setPvcssubproject("/TestProject");
168         pvcs.setLoginid("TestUser");
169
170         String JavaDoc ccCommand = pvcs.getExecutable("pcli") + " "
171                 + pvcs.buildExecCommand("11/23/2004 8:00AM", "11/23/2004 1:00PM");
172         String JavaDoc expectedCommand = pvcs.getExecutable("pcli") + " "
173                 + "run -ns -q -xo\"vlog.txt\" -xe\"vlog.txt\" vlog "
174                 + "-id\"TestUser\" -ds\"11/23/2004 8:00AM\" "
175                 + "-de\"11/23/2004 1:00PM\" -pr\"C:/PVCS-Repos/TestProject/pvcs\" "
176                 + "-z /TestProject";
177
178         assertEquals("Wrong PVCS command generated!", expectedCommand, ccCommand);
179     }
180     
181     public void testMakeModifications() {
182         Calendar JavaDoc cal = Calendar.getInstance();
183         cal.set(2004, 11, 23);
184         Date JavaDoc date = cal.getTime();
185         pvcs.setLastBuild(date);
186         pvcs.setPvcsproject("Services");
187         pvcs.makeModificationsList(new File JavaDoc("test/net/sourceforge/cruisecontrol/sourcecontrols/vlog.txt"));
188     }
189 }
190
Popular Tags