KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.File JavaDoc;
40 import java.io.IOException JavaDoc;
41
42 import junit.framework.TestCase;
43 import net.sourceforge.cruisecontrol.CruiseControlException;
44
45 public class CVSBootstrapperTest extends TestCase {
46
47     private CVSBootstrapper bootStrapper;
48
49     protected void setUp() {
50         bootStrapper = new CVSBootstrapper();
51     }
52     
53     public void testValidate() throws IOException JavaDoc {
54         try {
55             bootStrapper.validate();
56             fail("CVSBootstrapper should throw an exception when no attributes are set.");
57         } catch (CruiseControlException e) {
58         }
59         
60         bootStrapper.setCvsroot("someroot");
61         try {
62             bootStrapper.validate();
63         } catch (CruiseControlException e) {
64             fail("CVSBootstrapper should not throw an exception when a valid attribute is set.");
65         }
66         
67         bootStrapper = new CVSBootstrapper();
68         bootStrapper.setFile("somefile");
69         try {
70             bootStrapper.validate();
71         } catch (CruiseControlException e) {
72             fail("CVSBootstrapper should not throw an exception when a valid attribute is set.");
73         }
74
75         File JavaDoc tempFile = File.createTempFile("temp", "txt");
76         tempFile.deleteOnExit();
77
78         bootStrapper.setLocalWorkingCopy(tempFile.getParent());
79         try {
80             bootStrapper.validate();
81         } catch (CruiseControlException e) {
82             fail("CVSBootstrapper should not throw an exception when a valid attribute is set.");
83         }
84
85         bootStrapper.setLocalWorkingCopy(tempFile.getAbsolutePath());
86         try {
87             bootStrapper.validate();
88             fail("validate() should fail when 'localWorkingCopy' is file instead of directory.");
89         } catch (CruiseControlException e) {
90         }
91         
92         String JavaDoc badDirName = "z:/foo/foo/foo/bar";
93         bootStrapper.setLocalWorkingCopy(badDirName);
94         try {
95             bootStrapper.validate();
96             fail("validate() should throw exception on non-existant directory.");
97         } catch (CruiseControlException e) {
98         }
99     }
100
101     public void testBuildUpdateCommand() throws CruiseControlException {
102         String JavaDoc tempDir = System.getProperty("java.io.tmpdir");
103
104         bootStrapper.setLocalWorkingCopy(tempDir);
105         assertEquals(
106             "cvs update -dP",
107             bootStrapper.buildUpdateCommand().toString());
108
109         bootStrapper.setFile("somefile");
110         assertEquals(
111             "cvs update -dP somefile",
112             bootStrapper.buildUpdateCommand().toString());
113
114         bootStrapper.setCvsroot("somecvsroot");
115         assertEquals(
116             "cvs -d somecvsroot update -dP somefile",
117             bootStrapper.buildUpdateCommand().toString());
118         
119         bootStrapper.setResetStickyTags(true);
120         assertEquals("cvs -d somecvsroot update -dPA somefile",
121                 bootStrapper.buildUpdateCommand().toString());
122         
123         bootStrapper.setOverwriteChanges(true);
124         assertEquals("cvs -d somecvsroot update -dPAC somefile",
125                 bootStrapper.buildUpdateCommand().toString());
126     }
127     
128 }
129
Popular Tags