KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
43  * Should also test bootstrap() but to do that we need to mock calling the command line
44  *
45  * @author <a HREF="mailto:mroberts@thoughtworks.com">Mike Roberts</a>
46  * @author <a HREF="mailto:cstevenson@thoughtworks.com">Chris Stevenson</a>
47  */

48 public class P4BootstrapperTest extends TestCase {
49     private P4Bootstrapper p4Bootstrapper;
50
51     public void setUp() throws Exception JavaDoc {
52         p4Bootstrapper = new P4Bootstrapper();
53     }
54
55     public void testViewNotSet() {
56         try {
57             p4Bootstrapper.validate();
58             fail("Should be Exception if view is not set.");
59         } catch (CruiseControlException expected) {
60         }
61     }
62
63     public void testInvalidView() {
64         p4Bootstrapper.setView("");
65         try {
66             p4Bootstrapper.validate();
67             fail("Empty path not allowed");
68         } catch (CruiseControlException expected) {
69         }
70     }
71
72     public void testInvalidPort() {
73         p4Bootstrapper.setView("foo");
74         p4Bootstrapper.setPort("");
75         try {
76             p4Bootstrapper.validate();
77             fail("Empty port not allowed");
78         } catch (CruiseControlException expected) {
79         }
80     }
81
82     public void testInvalidClient() {
83         p4Bootstrapper.setView("foo");
84         p4Bootstrapper.setClient("");
85         try {
86             p4Bootstrapper.validate();
87             fail("Empty client not allowed");
88         } catch (CruiseControlException expected) {
89         }
90     }
91
92     public void testInvalidUser() {
93         p4Bootstrapper.setView("foo");
94         p4Bootstrapper.setUser("");
95         try {
96             p4Bootstrapper.validate();
97             fail("Empty user not allowed");
98         } catch (CruiseControlException expected) {
99         }
100     }
101
102     public void testCreateCommandlineWithViewSet() throws CruiseControlException {
103         p4Bootstrapper.setView("foo");
104         assertEquals("p4 -s sync foo", p4Bootstrapper.createCommandline().toString());
105
106         p4Bootstrapper.setView("foo bar");
107         assertEquals("p4 -s sync \"foo bar\"", p4Bootstrapper.createCommandline().toString());
108     }
109
110     public void testCreateCommandlineWithP4PortSet() throws CruiseControlException {
111         p4Bootstrapper.setView("foo");
112         p4Bootstrapper.setPort("testhost:1666");
113         checkEnvironmentSpecification(" -p testhost:1666 ");
114     }
115
116     public void testCreateCommandlineWithP4ClientSet() throws CruiseControlException {
117         p4Bootstrapper.setView("foo");
118         p4Bootstrapper.setClient("testclient");
119         checkEnvironmentSpecification(" -c testclient ");
120     }
121
122     public void testCreateCommandlineWithP4UserSet() throws CruiseControlException {
123         p4Bootstrapper.setView("foo");
124         p4Bootstrapper.setUser("testuser");
125         p4Bootstrapper.setPasswd("password");
126         checkEnvironmentSpecification(" -u testuser -P password ");
127     }
128
129     /**
130      * Checks that a P4 environment command line option is created correctly in a P4 command line specification
131      */

132     private void checkEnvironmentSpecification(String JavaDoc expectedSetting)
133             throws CruiseControlException {
134         String JavaDoc commandline = p4Bootstrapper.createCommandline().toString();
135         int specicationPosition = commandline.indexOf(expectedSetting);
136         int syncPosition = commandline.indexOf(" sync ");
137         assertTrue(specicationPosition != -1);
138         assertTrue(syncPosition != -1);
139         assertTrue(specicationPosition < syncPosition);
140     }
141 }
142
Popular Tags