KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > bootstrappers > VssBootstrapperTest


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.bootstrappers;
38
39 import junit.framework.TestCase;
40 import net.sourceforge.cruisecontrol.CruiseControlException;
41
42 public class VssBootstrapperTest extends TestCase {
43
44   public VssBootstrapperTest(String JavaDoc name) { super(name); }
45
46   public void testValidate() {
47     VssBootstrapper bootstrapper = new VssBootstrapper();
48     try {
49         bootstrapper.validate();
50         fail("VssBootstrapper should throw exception if required attributes not set");
51     } catch (CruiseControlException ex) {
52         String JavaDoc message = ex.getMessage();
53         assertEquals(
54             "exception message when required attributes not set",
55             "VssBootstrapper has required attributes vssPath and localDirectory",
56             message);
57     }
58
59     bootstrapper.setVssPath("$test/vss/path/file.ext");
60     try {
61         bootstrapper.validate();
62         fail("VssBootstrapper should throw exception if required attributes not set");
63     } catch (CruiseControlException ex) {
64         String JavaDoc message = ex.getMessage();
65         assertEquals(
66             "exception message when required attributes not set",
67             "VssBootstrapper has required attributes vssPath and localDirectory",
68             message);
69     }
70
71     bootstrapper.setLocalDirectory(".");
72     try {
73         bootstrapper.validate();
74     } catch (CruiseControlException ex) {
75         fail("validate() shouldn't fail when required attributes have been set");
76     }
77
78     bootstrapper.setLocalDirectory("c:/not/an/existing/directory");
79     try {
80         bootstrapper.validate();
81         fail("validate() should fail when given a file path that doesn't exist");
82     } catch (CruiseControlException ex) {
83     }
84   }
85
86   public void testCommandLine() {
87     VssBootstrapper bootstrapper = new VssBootstrapper();
88     String JavaDoc commandLine = bootstrapper.generateCommandLine();
89     assertNotNull("command line should never be null", commandLine);
90
91     final String JavaDoc vssPath = "$Project/subproject/file.ext";
92     bootstrapper.setVssPath(vssPath);
93     final String JavaDoc localDirectory = "c:/foo";
94     bootstrapper.setLocalDirectory(localDirectory);
95
96     commandLine = bootstrapper.generateCommandLine();
97     String JavaDoc expectedCommandLine = "ss.exe get \"" + vssPath + "\" -GL\"" + localDirectory + "\" -I-N";
98     assertEquals(expectedCommandLine, commandLine);
99
100     bootstrapper.setLogin("bob,password");
101     commandLine = bootstrapper.generateCommandLine();
102     expectedCommandLine = expectedCommandLine + " -Ybob,password";
103     assertEquals(expectedCommandLine, commandLine);
104
105     final String JavaDoc ssDir = "c:\\buildtools\\vss";
106     bootstrapper.setSsDir(ssDir);
107     final String JavaDoc serverPath = "t:\\vss\\foo";
108     bootstrapper.setServerPath(serverPath);
109     expectedCommandLine = ssDir + "\\" + expectedCommandLine;
110     commandLine = bootstrapper.generateCommandLine();
111     assertEquals(expectedCommandLine, commandLine);
112   }
113 }
Popular Tags