KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.io.File JavaDoc;
43 import java.io.IOException JavaDoc;
44
45 /**
46  * @see <a HREF="http://subversion.tigris.org/">subversion.tigris.org</a>
47  * @author <a HREF="etienne.studer@canoo.com">Etienne Studer</a>
48  */

49 public class SVNBootstrapperTest extends TestCase {
50
51     private SVNBootstrapper bootStrapper;
52
53     protected void setUp() {
54         bootStrapper = new SVNBootstrapper();
55     }
56
57     public void testValidate() throws IOException JavaDoc {
58         try {
59             bootStrapper.validate();
60             fail("should throw an exception when no attributes are set");
61         } catch (CruiseControlException e) {
62         }
63
64         bootStrapper = new SVNBootstrapper();
65         bootStrapper.setFile("some filename");
66         try {
67             bootStrapper.validate();
68         } catch (CruiseControlException e) {
69             fail("should not throw an exception when at least the 'filename' attribute is set");
70         }
71
72         bootStrapper = new SVNBootstrapper();
73         bootStrapper.setLocalWorkingCopy("invalid directory");
74         try {
75             bootStrapper.validate();
76             fail("should throw an exception when an invalid 'localWorkingCopy' attribute is set");
77         } catch (CruiseControlException e) {
78             // expected
79
}
80
81         File JavaDoc tempFile = File.createTempFile("temp", "txt");
82         tempFile.deleteOnExit();
83
84         bootStrapper = new SVNBootstrapper();
85         bootStrapper.setLocalWorkingCopy(tempFile.getParent());
86         try {
87             bootStrapper.validate();
88         } catch (CruiseControlException e) {
89             fail(
90                 "should not throw an exception when at least a valid 'localWorkingCopy' "
91                     + "attribute is set");
92         }
93
94         bootStrapper = new SVNBootstrapper();
95         bootStrapper.setLocalWorkingCopy(tempFile.getAbsolutePath());
96         try {
97             bootStrapper.validate();
98             fail(
99                 "should throw an exception when 'localWorkingCopy' is a file instead of a "
100                     + "directory.");
101         } catch (CruiseControlException e) {
102             // expected
103
}
104     }
105
106     public void testBuildUpdateCommand() throws CruiseControlException {
107         String JavaDoc tempDir = System.getProperty("java.io.tmpdir");
108
109         bootStrapper.setLocalWorkingCopy(tempDir);
110         String JavaDoc command = bootStrapper.buildUpdateCommand().toString();
111         assertEquals("svn update --non-interactive", command);
112
113         bootStrapper.setFile("foo.txt");
114         command = bootStrapper.buildUpdateCommand().toString();
115         assertEquals("svn update --non-interactive foo.txt", command);
116
117         bootStrapper.setUsername("lee");
118         command = bootStrapper.buildUpdateCommand().toString();
119         assertEquals("svn update --non-interactive --username lee foo.txt", command);
120
121         bootStrapper.setPassword("secret");
122         command = bootStrapper.buildUpdateCommand().toString();
123         assertEquals(
124             "svn update --non-interactive --username lee --password secret foo.txt",
125             command);
126     }
127 }
128
Popular Tags