source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 17.7 KB
Line 
1/*
2 * Copyright 2003-2005 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 */
17package org.apache.tools.ant.taskdefs.optional.vss;
18
19import java.io.File;
20import java.text.SimpleDateFormat;
21import java.util.Calendar;
22import java.util.Date;
23import java.util.TimeZone;
24
25import org.apache.tools.ant.BuildFileTest;
26import org.apache.tools.ant.Location;
27import org.apache.tools.ant.Project;
28import org.apache.tools.ant.taskdefs.Tstamp;
29import org.apache.tools.ant.types.Commandline;
30import org.apache.tools.ant.types.Path;
31
32/**
33 * Testcase to ensure that command line generation and required attributes are correct.
34 *
35 */
36public class MSVSSTest extends BuildFileTest implements MSVSSConstants {
37
38 private Commandline commandline;
39
40 private static final String VSS_SERVER_PATH = "\\\\server\\vss\\srcsafe.ini";
41 private static final String VSS_PROJECT_PATH = "/SourceRoot/Project";
42 private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project";
43 private static final String VSS_USERNAME = "ant";
44 private static final String VSS_PASSWORD = "rocks";
45 private static final String LOCAL_PATH = "testdir";
46 private static final String SRC_FILE = "Class1.java";
47 private static final String SRC_LABEL = "label1";
48 private static final String LONG_LABEL = "123456789012345678901234567890";
49 private static final String SRC_COMMENT = "I fixed a bug";
50 private static final String VERSION = "007";
51 private static final String DATE = "00-00-00";
52 private static final String DATE2 = "01-01-01";
53 private static final String OUTPUT = "output.log";
54 private static final String SS_DIR = "c:/winnt".replace('/', File.separatorChar);
55
56 /**
57 * Constructor for the MSVSSTest object
58 *
59 * @param s Test name
60 */
61 public MSVSSTest(String s) {
62 super(s);
63 }
64
65 /**
66 * The JUnit setup method
67 *
68 * @throws Exception
69 */
70 protected void setUp()
71 throws Exception {
72 project = new Project();
73 project.setBasedir(".");
74 }
75
76 /**
77 * The teardown method for JUnit
78 *
79 * @throws Exception
80 */
81 protected void tearDown()
82 throws Exception {
83 File file = new File(project.getBaseDir(), LOCAL_PATH);
84 if (file.exists()) {
85 file.delete();
86 }
87 }
88
89 /** Tests VSSGet commandline generation. */
90 public void testGetCommandLine() {
91 String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_GET, DS_VSS_PROJECT_PATH,
92 MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir().getAbsolutePath()
93 + File.separator + LOCAL_PATH, MSVSS.FLAG_AUTORESPONSE_DEF,
94 MSVSS.FLAG_RECURSION, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN
95 + VSS_USERNAME + "," + VSS_PASSWORD, FLAG_FILETIME_UPDATED, FLAG_SKIP_WRITABLE};
96
97 // Set up a VSSGet task
98 MSVSSGET vssGet = new MSVSSGET();
99 vssGet.setProject(project);
100 vssGet.setRecursive(true);
101 vssGet.setLocalpath(new Path(project, LOCAL_PATH));
102 vssGet.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
103 vssGet.setVersion(VERSION);
104 vssGet.setQuiet(false);
105 vssGet.setDate(DATE);
106 vssGet.setLabel(SRC_LABEL);
107 vssGet.setVsspath(VSS_PROJECT_PATH);
108 MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated();
109 cmu.setValue(TIME_UPDATED);
110 vssGet.setFileTimeStamp(cmu);
111 MSVSS.WritableFiles wf = new MSVSS.WritableFiles();
112 wf.setValue(WRITABLE_SKIP);
113 vssGet.setWritableFiles(wf);
114
115 commandline = vssGet.buildCmdLine();
116
117 checkCommandLines(sTestCmdLine, commandline.getCommandline());
118 }
119
120 /** Tests VSSGet required attributes. */
121 public void testGetExceptions() {
122 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
123 expectSpecificBuildException("vssget.1", "some cause", "vsspath attribute must be set!");
124 }
125
126 /** Tests Label commandline generation. */
127 public void testLabelCommandLine1() {
128 String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH,
129 MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_YES,
130 MSVSS.FLAG_LABEL + SRC_LABEL, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN
131 + VSS_USERNAME + "," + VSS_PASSWORD};
132
133 // Set up a VSSLabel task
134 MSVSSLABEL vssLabel = new MSVSSLABEL();
135 vssLabel.setProject(project);
136 vssLabel.setComment(SRC_COMMENT);
137 vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
138 vssLabel.setVersion(VERSION);
139 vssLabel.setAutoresponse("Y");
140 vssLabel.setLabel(SRC_LABEL);
141 vssLabel.setVsspath(VSS_PROJECT_PATH);
142
143 commandline = vssLabel.buildCmdLine();
144
145 checkCommandLines(sTestCmdLine, commandline.getCommandline());
146 }
147
148 /** Tests Label commandline generation with a label of more than 31 chars. */
149 public void testLabelCommandLine2() {
150 String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH,
151 MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_DEF,
152 MSVSS.FLAG_LABEL + LONG_LABEL,
153 MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD};
154
155 // Set up a VSSLabel task
156 MSVSSLABEL vssLabel = new MSVSSLABEL();
157 vssLabel.setProject(project);
158 vssLabel.setComment(SRC_COMMENT);
159 vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
160 vssLabel.setLabel(LONG_LABEL + "blahblah");
161 vssLabel.setVsspath(VSS_PROJECT_PATH);
162
163 commandline = vssLabel.buildCmdLine();
164
165 checkCommandLines(sTestCmdLine, commandline.getCommandline());
166 }
167
168 /**
169 * Test VSSLabel required attributes.
170 */
171 public void testLabelExceptions() {
172 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
173 expectSpecificBuildException("vsslabel.1", "some cause", "vsspath attribute must be set!");
174 expectSpecificBuildException("vsslabel.2", "some cause", "label attribute must be set!");
175 }
176
177 /** Tests VSSHistory commandline generation with from label. */
178 public void testHistoryCommandLine1() {
179 String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
180 MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_LABEL + LONG_LABEL
181 + MSVSS.VALUE_FROMLABEL + SRC_LABEL, MSVSS.FLAG_LOGIN + VSS_USERNAME
182 + "," + VSS_PASSWORD, MSVSS.FLAG_OUTPUT + project.getBaseDir().getAbsolutePath()
183 + File.separator + OUTPUT};
184
185 // Set up a VSSHistory task
186 MSVSSHISTORY vssHistory = new MSVSSHISTORY();
187 vssHistory.setProject(project);
188
189 vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
190
191 vssHistory.setFromLabel(SRC_LABEL);
192 vssHistory.setToLabel(LONG_LABEL + "blahblah");
193 vssHistory.setVsspath(VSS_PROJECT_PATH);
194 vssHistory.setRecursive(false);
195 vssHistory.setOutput(new File(project.getBaseDir().getAbsolutePath(), OUTPUT));
196
197 commandline = vssHistory.buildCmdLine();
198
199 checkCommandLines(sTestCmdLine, commandline.getCommandline());
200 }
201
202 /** Tests VSSHistory commandline generation with from date. */
203 public void testHistoryCommandLine2() {
204 String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
205 MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + DATE + MSVSS.VALUE_FROMDATE
206 + DATE2, MSVSS.FLAG_RECURSION, MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD};
207
208 // Set up a VSSHistory task
209 MSVSSHISTORY vssHistory = new MSVSSHISTORY();
210 vssHistory.setProject(project);
211 vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
212 vssHistory.setFromDate(DATE2);
213 vssHistory.setToDate(DATE);
214 vssHistory.setVsspath(VSS_PROJECT_PATH);
215 vssHistory.setRecursive(true);
216
217 commandline = vssHistory.buildCmdLine();
218
219 checkCommandLines(sTestCmdLine, commandline.getCommandline());
220 }
221
222 /** Tests VSSHistory commandline generation with date calculation. */
223 public void testHistoryCommandLine3() {
224 // Set up a Timestamp
225 Tstamp tstamp = new Tstamp();
226 Location location = new Location("src/etc/testcases/taskdefs/optional/vss/vss.xml");
227 tstamp.setLocation(location);
228 tstamp.setProject(project);
229 Tstamp.CustomFormat format = tstamp.createFormat();
230 format.setProperty("today");
231 format.setPattern("HH:mm:ss z");
232 format.setTimezone("GMT");
233 Date date = Calendar.getInstance().getTime();
234 format.execute(project, date, location);
235 String today = project.getProperty("today");
236
237 // Get today's date
238 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z");
239 sdf.setTimeZone( TimeZone.getTimeZone("GMT") );
240 String expected = sdf.format(date);
241
242 // Set up a VSSHistory task
243 MSVSSHISTORY vssHistory = new MSVSSHISTORY();
244 vssHistory.setProject(project);
245 vssHistory.setLogin(VSS_USERNAME);
246 vssHistory.setToDate(today);
247 vssHistory.setVsspath(VSS_PROJECT_PATH);
248
249 String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
250 MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + expected, MSVSS.FLAG_LOGIN + VSS_USERNAME};
251
252 commandline = vssHistory.buildCmdLine();
253
254 checkCommandLines(sTestCmdLine, commandline.getCommandline());
255 }
256
257 /**
258 * Tests VSSHistory required attributes.
259 */
260 public void testHistoryExceptions() {
261 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
262 expectSpecificBuildException("vsshistory.1", "some cause", "vsspath attribute must be set!");
263 }
264
265 /** Tests CheckIn commandline generation. */
266 public void testCheckinCommandLine() {
267 String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CHECKIN, DS_VSS_PROJECT_PATH,
268 MSVSS.FLAG_AUTORESPONSE_NO, MSVSS.FLAG_WRITABLE, MSVSS.FLAG_LOGIN + VSS_USERNAME,
269 MSVSS.FLAG_COMMENT + SRC_COMMENT};
270
271 // Set up a VSSCheckIn task
272 MSVSSCHECKIN vssCheckin = new MSVSSCHECKIN();
273 vssCheckin.setProject(project);
274 vssCheckin.setComment(SRC_COMMENT);
275 vssCheckin.setLogin(VSS_USERNAME);
276 vssCheckin.setAutoresponse("N");
277 vssCheckin.setVsspath(VSS_PROJECT_PATH);
278 vssCheckin.setWritable(true);
279
280 commandline = vssCheckin.buildCmdLine();
281
282 checkCommandLines(sTestCmdLine, commandline.getCommandline());
283 }
284
285 /**
286 * Test VSSCheckIn required attributes.
287 */
288 public void testCheckinExceptions() {
289 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
290 expectSpecificBuildException("vsscheckin.1", "some cause", "vsspath attribute must be set!");
291 }
292
293 /** Tests CheckOut commandline generation. */
294 public void testCheckoutCommandLine() {
295 String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_CHECKOUT,
296 DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION,
297 MSVSS.FLAG_VERSION_DATE + DATE, MSVSS.FLAG_LOGIN + VSS_USERNAME,
298 FLAG_FILETIME_MODIFIED, FLAG_NO_GET};
299
300 // Set up a VSSCheckOut task
301 MSVSSCHECKOUT vssCheckout = new MSVSSCHECKOUT();
302 vssCheckout.setProject(project);
303 vssCheckout.setLogin(VSS_USERNAME);
304 vssCheckout.setVsspath(DS_VSS_PROJECT_PATH);
305 vssCheckout.setRecursive(true);
306 vssCheckout.setDate(DATE);
307 vssCheckout.setLabel(SRC_LABEL);
308 vssCheckout.setSsdir(SS_DIR);
309 MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated();
310 cmu.setValue(TIME_MODIFIED);
311 vssCheckout.setFileTimeStamp(cmu);
312 vssCheckout.setGetLocalCopy(false);
313
314 commandline = vssCheckout.buildCmdLine();
315
316 checkCommandLines(sTestCmdLine, commandline.getCommandline());
317 }
318
319 /**
320 * Test VSSCheckout required attributes.
321 */
322 public void testCheckoutExceptions() {
323 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
324 expectSpecificBuildException("vsscheckout.1", "some cause", "vsspath attribute must be set!");
325 expectSpecificBuildException("vsscheckout.2", "some cause", "blah is not a legal value for this attribute");
326 }
327
328 /** Tests Add commandline generation. */
329 public void testAddCommandLine() {
330 String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_ADD,
331 project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH,
332 MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION,
333 MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD, MSVSS.FLAG_COMMENT + "-"};
334
335 // Set up a VSSAdd task
336 MSVSSADD vssAdd = new MSVSSADD();
337 vssAdd.setProject(project);
338 vssAdd.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
339 vssAdd.setVsspath(DS_VSS_PROJECT_PATH);
340 vssAdd.setRecursive(true);
341 vssAdd.setSsdir(SS_DIR);
342 vssAdd.setWritable(false);
343 vssAdd.setLocalpath(new Path(project, LOCAL_PATH));
344
345 commandline = vssAdd.buildCmdLine();
346
347 checkCommandLines(sTestCmdLine, commandline.getCommandline());
348 }
349
350 /**
351 * Test VSSAdd required attributes.
352 */
353 public void testAddExceptions() {
354 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
355 expectSpecificBuildException("vssadd.1", "some cause", "localPath attribute must be set!");
356 }
357
358 /** Tests CP commandline generation. */
359 public void testCpCommandLine() {
360 String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CP,
361 DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_LOGIN +
362 VSS_USERNAME};
363
364 // Set up a VSSCp task
365 MSVSSCP vssCp = new MSVSSCP();
366 vssCp.setProject(project);
367 vssCp.setLogin(VSS_USERNAME);
368 vssCp.setVsspath(DS_VSS_PROJECT_PATH);
369
370 commandline = vssCp.buildCmdLine();
371
372 checkCommandLines(sTestCmdLine, commandline.getCommandline());
373 }
374
375 /**
376 * Test VSSCP required attributes.
377 */
378 public void testCpExceptions() {
379 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
380 expectSpecificBuildException("vsscp.1", "some cause", "vsspath attribute must be set!");
381 }
382
383 /** Tests Create commandline generation. */
384 public void testCreateCommandLine() {
385 String[] sTestCmdLine = { MSVSS.SS_EXE, MSVSS.COMMAND_CREATE,
386 DS_VSS_PROJECT_PATH, MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_NO,
387 MSVSS.FLAG_QUIET, MSVSS.FLAG_LOGIN + VSS_USERNAME};
388
389 // Set up a VSSCreate task
390 MSVSSCREATE vssCreate = new MSVSSCREATE();
391 vssCreate.setProject(project);
392 vssCreate.setComment(SRC_COMMENT);
393 vssCreate.setLogin(VSS_USERNAME);
394 vssCreate.setVsspath(DS_VSS_PROJECT_PATH);
395 vssCreate.setFailOnError(true);
396 vssCreate.setAutoresponse("N");
397 vssCreate.setQuiet(true);
398
399 commandline = vssCreate.buildCmdLine();
400
401 checkCommandLines(sTestCmdLine, commandline.getCommandline());
402 }
403
404 /**
405 * Test VSSCreate required attributes.
406 */
407 public void testCreateExceptions() {
408 configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
409 expectSpecificBuildException("vsscreate.1", "some cause", "vsspath attribute must be set!");
410 }
411
412 /**
413 * Iterate through the generated command line comparing it to reference one.
414 * @param sTestCmdLine The reference command line;
415 * @param sGeneratedCmdLine The generated command line;
416 */
417 private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) {
418 int testLength = sTestCmdLine.length;
419 int genLength = sGeneratedCmdLine.length;
420
421 int genIndex = 0;
422 int testIndex = 0;
423
424 while (testIndex < testLength) {
425 try {
426 if (sGeneratedCmdLine[genIndex] == "") {
427 genIndex++;
428 continue;
429 }
430 assertEquals("arg # " + testIndex,
431 sTestCmdLine[testIndex],
432 sGeneratedCmdLine[genIndex]);
433 testIndex++;
434 genIndex++;
435 } catch (ArrayIndexOutOfBoundsException aioob) {
436 fail("missing arg " + sTestCmdLine[testIndex]);
437 }
438 }
439
440 // Count the number of empty strings
441 int cnt = 0;
442 for (int i = 0; i < genLength; i++) {
443 if (sGeneratedCmdLine[i] == "") {
444 cnt++;
445 }
446 }
447 if (genLength - cnt > sTestCmdLine.length) {
448 // We have extra elements
449 fail("extra args");
450 }
451 }
452}
Note: See TracBrowser for help on using the repository browser.