KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > ProjectConfigTest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2005, 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;
38
39 import junit.framework.TestCase;
40
41 public class ProjectConfigTest extends TestCase {
42
43     private ProjectConfig config;
44
45     protected void setUp() {
46         config = new ProjectConfig();
47     }
48
49     protected void tearDown() {
50         config = null;
51     }
52     
53     public void testBuildAfterFailedShouldDefaultToTrue() {
54         assertTrue(config.shouldBuildAfterFailed());
55         config.setBuildAfterFailed(false);
56         assertFalse(config.shouldBuildAfterFailed());
57     }
58
59     public void testValidate_ScheduleRequired() throws CruiseControlException {
60         try {
61             config.validate();
62             fail("a schedule should have been required by ProjectConfig");
63         } catch (CruiseControlException expected) {
64             assertEquals("project requires a schedule", expected.getMessage());
65         }
66
67         config.add(new MockSchedule());
68         config.validate();
69     }
70
71     public void testValidateCallsSubelementValidates() throws CruiseControlException {
72         MockSchedule schedule = new MockSchedule();
73         config.add(schedule);
74         MockBootstrappers bootstrappers = new MockBootstrappers();
75         config.add(bootstrappers);
76         MockModificationSet modificationSet = new MockModificationSet();
77         config.add(modificationSet);
78         MockListeners listeners = new MockListeners();
79         config.add(listeners);
80         MockPublishers publishers = new MockPublishers();
81         config.add(publishers);
82         MockLog log = new MockLog();
83         config.add(log);
84
85         config.validate();
86
87         assertTrue(schedule.validateWasCalled());
88         assertTrue(bootstrappers.validateWasCalled());
89         assertTrue(modificationSet.validateWasCalled());
90         assertTrue(listeners.validateWasCalled());
91         assertTrue(publishers.validateWasCalled());
92         assertTrue(log.validateWasCalled());
93     }
94
95     private static class MockBootstrappers extends ProjectConfig.Bootstrappers {
96         private boolean validateWasCalled = false;
97
98         public void validate() throws CruiseControlException {
99             validateWasCalled = true;
100         }
101
102         public boolean validateWasCalled() {
103             return validateWasCalled;
104         }
105     }
106
107     private static class MockModificationSet extends ModificationSet {
108         private boolean validateWasCalled = false;
109
110         public void validate() throws CruiseControlException {
111             validateWasCalled = true;
112         }
113
114         public boolean validateWasCalled() {
115             return validateWasCalled;
116         }
117     }
118
119     private static class MockListeners extends ProjectConfig.Listeners {
120         private boolean validateWasCalled = false;
121
122         public void validate() throws CruiseControlException {
123             validateWasCalled = true;
124         }
125
126         public boolean validateWasCalled() {
127             return validateWasCalled;
128         }
129     }
130
131     private static class MockPublishers extends ProjectConfig.Publishers {
132         private boolean validateWasCalled = false;
133
134         public void validate() throws CruiseControlException {
135             validateWasCalled = true;
136         }
137
138         public boolean validateWasCalled() {
139             return validateWasCalled;
140         }
141     }
142
143     private static class MockLog extends Log {
144         private boolean validateWasCalled = false;
145
146         public void validate() throws CruiseControlException {
147             validateWasCalled = true;
148         }
149
150         public boolean validateWasCalled() {
151             return validateWasCalled;
152         }
153     }
154 }
155
Popular Tags