1 | /*
|
---|
2 | * Copyright 2002-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.optional.sos;
|
---|
18 |
|
---|
19 | import java.io.File;
|
---|
20 |
|
---|
21 | import org.apache.tools.ant.BuildFileTest;
|
---|
22 | import org.apache.tools.ant.Project;
|
---|
23 | import org.apache.tools.ant.types.Commandline;
|
---|
24 | import org.apache.tools.ant.types.Path;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Testcase to ensure that command line generation and required attributes are
|
---|
28 | * correct.
|
---|
29 | *
|
---|
30 | */
|
---|
31 | public class SOSTest extends BuildFileTest {
|
---|
32 |
|
---|
33 | private Project project;
|
---|
34 | private Commandline commandline;
|
---|
35 |
|
---|
36 | private static final String VSS_SERVER_PATH = "\\\\server\\vss\\srcsafe.ini";
|
---|
37 | private static final String VSS_PROJECT_PATH = "/SourceRoot/Project";
|
---|
38 | private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project";
|
---|
39 | private static final String SOS_SERVER_PATH = "192.168.0.1:8888";
|
---|
40 | private static final String SOS_USERNAME = "ant";
|
---|
41 | private static final String SOS_PASSWORD = "rocks";
|
---|
42 | private static final String LOCAL_PATH = "testdir";
|
---|
43 | private static final String SRC_FILE = "Class1.java";
|
---|
44 | private static final String SRC_LABEL = "label1";
|
---|
45 | private static final String SRC_COMMENT = "I fixed a bug";
|
---|
46 | private static final String SOS_HOME = "/home/user/.sos";
|
---|
47 | private static final String VERSION = "007";
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Constructor for the SOSTest object
|
---|
51 | *
|
---|
52 | * @param s Test name
|
---|
53 | */
|
---|
54 | public SOSTest(String s) {
|
---|
55 | super(s);
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * The JUnit setup method
|
---|
60 | *
|
---|
61 | * @throws Exception
|
---|
62 | */
|
---|
63 | protected void setUp()
|
---|
64 | throws Exception {
|
---|
65 | project = new Project();
|
---|
66 | project.setBasedir(".");
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * The teardown method for JUnit
|
---|
71 | *
|
---|
72 | * @throws Exception
|
---|
73 | */
|
---|
74 | protected void tearDown()
|
---|
75 | throws Exception {
|
---|
76 | File file = new File(project.getBaseDir(), LOCAL_PATH);
|
---|
77 | if (file.exists()) {
|
---|
78 | file.delete();
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | /** Test SOSGetFile flags & commandline generation */
|
---|
83 | public void testGetFileFlags() {
|
---|
84 | String[] sTestCmdLine = {"soscmd", "-command", "GetFile", "-file",
|
---|
85 | SRC_FILE, "-revision", "007", "-server", SOS_SERVER_PATH, "-name",
|
---|
86 | SOS_USERNAME, "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH,
|
---|
87 | "-project", DS_VSS_PROJECT_PATH, "-verbose", "-nocompress",
|
---|
88 | "-nocache", "-workdir", project.getBaseDir().getAbsolutePath()
|
---|
89 | + File.separator + LOCAL_PATH};
|
---|
90 |
|
---|
91 | // Set up a SOSGet task
|
---|
92 | SOSGet sosGet = new SOSGet();
|
---|
93 | sosGet.setProject(project);
|
---|
94 | sosGet.setVssServerPath(VSS_SERVER_PATH);
|
---|
95 | sosGet.setSosServerPath(SOS_SERVER_PATH);
|
---|
96 | sosGet.setProjectPath(VSS_PROJECT_PATH);
|
---|
97 | sosGet.setFile(SRC_FILE);
|
---|
98 | sosGet.setUsername(SOS_USERNAME);
|
---|
99 | sosGet.setPassword(SOS_PASSWORD);
|
---|
100 | sosGet.setVersion(VERSION);
|
---|
101 | sosGet.setLocalPath(new Path(project, LOCAL_PATH));
|
---|
102 | sosGet.setNoCache(true);
|
---|
103 | sosGet.setNoCompress(true);
|
---|
104 | sosGet.setVerbose(true);
|
---|
105 | sosGet.setRecursive(true);
|
---|
106 |
|
---|
107 | commandline = sosGet.buildCmdLine();
|
---|
108 |
|
---|
109 | checkCommandLines(sTestCmdLine, commandline.getCommandline());
|
---|
110 | }
|
---|
111 |
|
---|
112 | /** Test SOSGetProject flags & commandline generation */
|
---|
113 | public void testGetProjectFlags() {
|
---|
114 | String[] sTestCmdLine = {"soscmd", "-command", "GetProject", "-recursive",
|
---|
115 | "-label", SRC_LABEL, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
|
---|
116 | "-password", "", "-database", VSS_SERVER_PATH, "-project",
|
---|
117 | DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir",
|
---|
118 | project.getBaseDir().getAbsolutePath()};
|
---|
119 |
|
---|
120 | // Set up a SOSGet task
|
---|
121 | SOSGet sosGet = new SOSGet();
|
---|
122 | sosGet.setProject(project);
|
---|
123 | sosGet.setVssServerPath(VSS_SERVER_PATH);
|
---|
124 | sosGet.setSosServerPath(SOS_SERVER_PATH);
|
---|
125 | sosGet.setProjectPath(DS_VSS_PROJECT_PATH);
|
---|
126 | sosGet.setLabel(SRC_LABEL);
|
---|
127 | sosGet.setUsername(SOS_USERNAME);
|
---|
128 | sosGet.setSosHome(SOS_HOME);
|
---|
129 | sosGet.setNoCache(true);
|
---|
130 | sosGet.setNoCompress(false);
|
---|
131 | sosGet.setVerbose(false);
|
---|
132 | sosGet.setRecursive(true);
|
---|
133 |
|
---|
134 | commandline = sosGet.buildCmdLine();
|
---|
135 |
|
---|
136 | checkCommandLines(sTestCmdLine, commandline.getCommandline());
|
---|
137 | }
|
---|
138 |
|
---|
139 | /** Tests SOSGet required attributes. */
|
---|
140 | public void testGetExceptions() {
|
---|
141 | configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
|
---|
142 | expectSpecificBuildException("sosget.1", "some cause", "sosserverpath attribute must be set!");
|
---|
143 | expectSpecificBuildException("sosget.2", "some cause", "username attribute must be set!");
|
---|
144 | expectSpecificBuildException("sosget.3", "some cause", "vssserverpath attribute must be set!");
|
---|
145 | expectSpecificBuildException("sosget.4", "some cause", "projectpath attribute must be set!");
|
---|
146 | }
|
---|
147 |
|
---|
148 | /** Test CheckInFile option flags */
|
---|
149 | public void testCheckinFileFlags() {
|
---|
150 | String[] sTestCmdLine = {"soscmd", "-command", "CheckInFile", "-file",
|
---|
151 | SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
|
---|
152 | "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project",
|
---|
153 | DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache",
|
---|
154 | "-workdir", project.getBaseDir().getAbsolutePath() + File.separator
|
---|
155 | + LOCAL_PATH, "-log", SRC_COMMENT};
|
---|
156 |
|
---|
157 | // Set up a SOSCheckin task
|
---|
158 | SOSCheckin sosCheckin = new SOSCheckin();
|
---|
159 | sosCheckin.setProject(project);
|
---|
160 | sosCheckin.setVssServerPath(VSS_SERVER_PATH);
|
---|
161 | sosCheckin.setSosServerPath(SOS_SERVER_PATH);
|
---|
162 | sosCheckin.setProjectPath(VSS_PROJECT_PATH);
|
---|
163 | sosCheckin.setFile(SRC_FILE);
|
---|
164 | sosCheckin.setComment(SRC_COMMENT);
|
---|
165 | sosCheckin.setUsername(SOS_USERNAME);
|
---|
166 | sosCheckin.setPassword(SOS_PASSWORD);
|
---|
167 | sosCheckin.setLocalPath(new Path(project, LOCAL_PATH));
|
---|
168 | sosCheckin.setNoCache(true);
|
---|
169 | sosCheckin.setNoCompress(true);
|
---|
170 | sosCheckin.setVerbose(true);
|
---|
171 | sosCheckin.setRecursive(true);
|
---|
172 |
|
---|
173 | commandline = sosCheckin.buildCmdLine();
|
---|
174 |
|
---|
175 | checkCommandLines(sTestCmdLine, commandline.getCommandline());
|
---|
176 | }
|
---|
177 |
|
---|
178 | /** Test CheckInProject option flags */
|
---|
179 | public void testCheckinProjectFlags() {
|
---|
180 | String[] sTestCmdLine = {"soscmd", "-command", "CheckInProject",
|
---|
181 | "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
|
---|
182 | "-password", "", "-database", VSS_SERVER_PATH, "-project",
|
---|
183 | DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir",
|
---|
184 | project.getBaseDir().getAbsolutePath(), "-log", SRC_COMMENT,};
|
---|
185 |
|
---|
186 | // Set up a SOSCheckin task
|
---|
187 | SOSCheckin sosCheckin = new SOSCheckin();
|
---|
188 | sosCheckin.setProject(project);
|
---|
189 | sosCheckin.setVssServerPath(VSS_SERVER_PATH);
|
---|
190 | sosCheckin.setSosServerPath(SOS_SERVER_PATH);
|
---|
191 | sosCheckin.setProjectPath(DS_VSS_PROJECT_PATH);
|
---|
192 | sosCheckin.setComment(SRC_COMMENT);
|
---|
193 | sosCheckin.setUsername(SOS_USERNAME);
|
---|
194 | sosCheckin.setSosHome(SOS_HOME);
|
---|
195 | sosCheckin.setNoCache(true);
|
---|
196 | sosCheckin.setNoCompress(false);
|
---|
197 | sosCheckin.setVerbose(false);
|
---|
198 | sosCheckin.setRecursive(true);
|
---|
199 |
|
---|
200 | commandline = sosCheckin.buildCmdLine();
|
---|
201 |
|
---|
202 | checkCommandLines(sTestCmdLine, commandline.getCommandline());
|
---|
203 | }
|
---|
204 |
|
---|
205 | /** Test SOSCheckIn required attributes. */
|
---|
206 | public void testCheckinExceptions() {
|
---|
207 | configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
|
---|
208 | expectSpecificBuildException("soscheckin.1", "some cause", "sosserverpath attribute must be set!");
|
---|
209 | expectSpecificBuildException("soscheckin.2", "some cause", "username attribute must be set!");
|
---|
210 | expectSpecificBuildException("soscheckin.3", "some cause", "vssserverpath attribute must be set!");
|
---|
211 | expectSpecificBuildException("soscheckin.4", "some cause", "projectpath attribute must be set!");
|
---|
212 | }
|
---|
213 |
|
---|
214 | /** Test CheckOutFile option flags */
|
---|
215 | public void testCheckoutFileFlags() {
|
---|
216 | String[] sTestCmdLine = {"soscmd", "-command", "CheckOutFile", "-file",
|
---|
217 | SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
|
---|
218 | "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project",
|
---|
219 | DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache",
|
---|
220 | "-workdir", project.getBaseDir().getAbsolutePath()
|
---|
221 | + File.separator + LOCAL_PATH};
|
---|
222 |
|
---|
223 | // Set up a SOSCheckout task
|
---|
224 | SOSCheckout sosCheckout = new SOSCheckout();
|
---|
225 | sosCheckout.setProject(project);
|
---|
226 | sosCheckout.setVssServerPath(VSS_SERVER_PATH);
|
---|
227 | sosCheckout.setSosServerPath(SOS_SERVER_PATH);
|
---|
228 | sosCheckout.setProjectPath(DS_VSS_PROJECT_PATH);
|
---|
229 | sosCheckout.setFile(SRC_FILE);
|
---|
230 | sosCheckout.setUsername(SOS_USERNAME);
|
---|
231 | sosCheckout.setPassword(SOS_PASSWORD);
|
---|
232 | sosCheckout.setLocalPath(new Path(project, LOCAL_PATH));
|
---|
233 | sosCheckout.setNoCache(true);
|
---|
234 | sosCheckout.setNoCompress(true);
|
---|
235 | sosCheckout.setVerbose(true);
|
---|
236 | sosCheckout.setRecursive(true);
|
---|
237 |
|
---|
238 | commandline = sosCheckout.buildCmdLine();
|
---|
239 |
|
---|
240 | checkCommandLines(sTestCmdLine, commandline.getCommandline());
|
---|
241 | }
|
---|
242 |
|
---|
243 | /** Test CheckOutProject option flags */
|
---|
244 | public void testCheckoutProjectFlags() {
|
---|
245 | String[] sTestCmdLine = {"soscmd", "-command", "CheckOutProject",
|
---|
246 | "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
|
---|
247 | "-password", "", "-database", VSS_SERVER_PATH, "-project",
|
---|
248 | DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir",
|
---|
249 | project.getBaseDir().getAbsolutePath()};
|
---|
250 |
|
---|
251 | // Set up a sosCheckout task
|
---|
252 | SOSCheckout sosCheckout = new SOSCheckout();
|
---|
253 | sosCheckout.setProject(project);
|
---|
254 | sosCheckout.setVssServerPath(VSS_SERVER_PATH);
|
---|
255 | sosCheckout.setSosServerPath(SOS_SERVER_PATH);
|
---|
256 | sosCheckout.setProjectPath(VSS_PROJECT_PATH);
|
---|
257 | sosCheckout.setUsername(SOS_USERNAME);
|
---|
258 | sosCheckout.setSosHome(SOS_HOME);
|
---|
259 | sosCheckout.setNoCache(true);
|
---|
260 | sosCheckout.setNoCompress(false);
|
---|
261 | sosCheckout.setVerbose(false);
|
---|
262 | sosCheckout.setRecursive(true);
|
---|
263 |
|
---|
264 | commandline = sosCheckout.buildCmdLine();
|
---|
265 |
|
---|
266 | checkCommandLines(sTestCmdLine, commandline.getCommandline());
|
---|
267 | }
|
---|
268 |
|
---|
269 | /** Test SOSCheckout required attributes. */
|
---|
270 | public void testCheckoutExceptions() {
|
---|
271 | configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
|
---|
272 | expectSpecificBuildException("soscheckout.1", "some cause", "sosserverpath attribute must be set!");
|
---|
273 | expectSpecificBuildException("soscheckout.2", "some cause", "username attribute must be set!");
|
---|
274 | expectSpecificBuildException("soscheckout.3", "some cause", "vssserverpath attribute must be set!");
|
---|
275 | expectSpecificBuildException("soscheckout.4", "some cause", "projectpath attribute must be set!");
|
---|
276 | }
|
---|
277 |
|
---|
278 | /** Test Label option flags */
|
---|
279 | public void testLabelFlags() {
|
---|
280 | String[] sTestCmdLine = {"soscmd", "-command", "AddLabel", "-server",
|
---|
281 | SOS_SERVER_PATH, "-name", SOS_USERNAME, "-password", "", "-database",
|
---|
282 | VSS_SERVER_PATH, "-project", DS_VSS_PROJECT_PATH, "-label",
|
---|
283 | SRC_LABEL, "-verbose", "-log", SRC_COMMENT};
|
---|
284 |
|
---|
285 | // Set up a sosCheckout task
|
---|
286 | SOSLabel sosLabel = new SOSLabel();
|
---|
287 | sosLabel.setVssServerPath(VSS_SERVER_PATH);
|
---|
288 | sosLabel.setSosServerPath(SOS_SERVER_PATH);
|
---|
289 | sosLabel.setProjectPath(DS_VSS_PROJECT_PATH);
|
---|
290 | sosLabel.setUsername(SOS_USERNAME);
|
---|
291 | sosLabel.setSosHome(SOS_HOME);
|
---|
292 | sosLabel.setComment(SRC_COMMENT);
|
---|
293 | sosLabel.setLabel(SRC_LABEL);
|
---|
294 | sosLabel.setNoCache(true);
|
---|
295 | sosLabel.setNoCompress(false);
|
---|
296 | sosLabel.setVerbose(true);
|
---|
297 |
|
---|
298 | commandline = sosLabel.buildCmdLine();
|
---|
299 |
|
---|
300 | checkCommandLines(sTestCmdLine, commandline.getCommandline());
|
---|
301 | }
|
---|
302 |
|
---|
303 | /** Test SOSLabel required attributes. */
|
---|
304 | public void testLabelExceptions() {
|
---|
305 | configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
|
---|
306 | expectSpecificBuildException("soslabel.1", "some cause", "sosserverpath attribute must be set!");
|
---|
307 | expectSpecificBuildException("soslabel.2", "some cause", "username attribute must be set!");
|
---|
308 | expectSpecificBuildException("soslabel.3", "some cause", "vssserverpath attribute must be set!");
|
---|
309 | expectSpecificBuildException("soslabel.4", "some cause", "projectpath attribute must be set!");
|
---|
310 | expectSpecificBuildException("soslabel.5", "some cause", "label attribute must be set!");
|
---|
311 | }
|
---|
312 |
|
---|
313 | /**
|
---|
314 | * Iterate through the generated command line comparing it to reference
|
---|
315 | * one.
|
---|
316 | *
|
---|
317 | * @param sTestCmdLine The reference command line;
|
---|
318 | * @param sGeneratedCmdLine The generated command line;
|
---|
319 | */
|
---|
320 | private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) {
|
---|
321 | int length = sTestCmdLine.length;
|
---|
322 | for (int i = 0; i < length; i++) {
|
---|
323 | try {
|
---|
324 | assertEquals("arg # " + String.valueOf(i),
|
---|
325 | sTestCmdLine[i],
|
---|
326 | sGeneratedCmdLine[i]);
|
---|
327 | } catch (ArrayIndexOutOfBoundsException aioob) {
|
---|
328 | fail("missing arg " + sTestCmdLine[i]);
|
---|
329 | }
|
---|
330 | }
|
---|
331 | if (sGeneratedCmdLine.length > sTestCmdLine.length) {
|
---|
332 | // We have extra elements
|
---|
333 | fail("extra args");
|
---|
334 | }
|
---|
335 | }
|
---|
336 | }
|
---|