KickJava   Java API By Example, From Geeks To Geeks.

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


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
38 package net.sourceforge.cruisecontrol;
39
40 import junit.framework.TestCase;
41
42 import java.util.Calendar JavaDoc;
43
44 public class PauseBuilderTest extends TestCase {
45
46     private Calendar JavaDoc cal, cal2;
47
48     public PauseBuilderTest(String JavaDoc name) {
49         super(name);
50     }
51
52     public void setUp() {
53         cal = Calendar.getInstance();
54         cal.clear();
55         cal.set(2001, Calendar.NOVEMBER, 22); //Thursday, November 22, 2001
56
cal2 = Calendar.getInstance();
57         cal2.clear();
58         cal2.set(2001, Calendar.NOVEMBER, 23); //Friday, November 23, 2001
59
}
60
61     public void testValidate() {
62         PauseBuilder pb = new PauseBuilder();
63
64         try {
65             pb.validate();
66             fail("PauseBuilder should throw exceptions when required fields are not set.");
67         } catch (CruiseControlException e) {
68         }
69
70         pb.setStartTime(1400);
71         try {
72             pb.validate();
73             fail("PauseBuilder should throw exceptions when required fields are not set.");
74         } catch (CruiseControlException e) {
75         }
76
77         pb.setEndTime(1500);
78
79         try {
80             pb.validate();
81         } catch (CruiseControlException e) {
82             fail("PauseBuilder should not throw exceptions when required fields are set.");
83         }
84
85         try {
86             pb.setDay("sUnDaY");
87             pb.validate();
88             pb.setDay("monday");
89             pb.validate();
90             pb.setDay("TuesdaY");
91             pb.validate();
92             pb.setDay("wedNESday");
93             pb.validate();
94             pb.setDay("Thursday");
95             pb.validate();
96             pb.setDay("friday");
97             pb.validate();
98             pb.setDay("SATURDAY");
99             pb.validate();
100         } catch (CruiseControlException e) {
101             fail("PauseBuilder shouldn't throw exception with english names for day of week (case insensitive)");
102         }
103         try {
104             pb.setDay("1");
105             pb.validate();
106             fail("PauseBuilder requires english names for day of week (case insensitive)");
107         } catch (CruiseControlException e) {
108         }
109     }
110
111     public void testIsPaused() {
112         Calendar JavaDoc calendar = Calendar.getInstance();
113         calendar.set(2002, Calendar.DECEMBER, 23, 18, 00, 00);
114
115         Calendar JavaDoc calendar2 = Calendar.getInstance();
116         calendar2.set(2002, Calendar.DECEMBER, 23, 20, 00, 00);
117
118         Calendar JavaDoc calendar3 = Calendar.getInstance();
119         calendar3.set(2002, Calendar.DECEMBER, 23, 22, 00, 00);
120
121         Calendar JavaDoc calendar4 = Calendar.getInstance();
122         calendar4.set(2002, Calendar.DECEMBER, 24, 3, 00, 00);
123
124         Calendar JavaDoc calendar5 = Calendar.getInstance();
125         calendar5.set(2002, Calendar.DECEMBER, 24, 7, 00, 00);
126
127         PauseBuilder pb = new PauseBuilder();
128         pb.setStartTime(1900);
129         pb.setEndTime(2100);
130
131         assertEquals(false, pb.isPaused(calendar.getTime()));
132         assertEquals(true, pb.isPaused(calendar2.getTime()));
133         assertEquals(false, pb.isPaused(calendar3.getTime()));
134
135         pb.setDay("monday");
136         assertEquals(false, pb.isPaused(calendar.getTime()));
137         assertEquals(true, pb.isPaused(calendar2.getTime()));
138         assertEquals(false, pb.isPaused(calendar3.getTime()));
139
140         pb.setDay("tuesday");
141         assertEquals(false, pb.isPaused(calendar.getTime()));
142         assertEquals(false, pb.isPaused(calendar2.getTime()));
143         assertEquals(false, pb.isPaused(calendar3.getTime()));
144
145         pb = new PauseBuilder();
146         pb.setStartTime(2100);
147         pb.setEndTime(500);
148
149         assertEquals(false, pb.isPaused(calendar.getTime()));
150         assertEquals(true, pb.isPaused(calendar3.getTime()));
151         assertEquals(true, pb.isPaused(calendar4.getTime()));
152         assertEquals(false, pb.isPaused(calendar5.getTime()));
153
154         pb.setDay("monday");
155
156         assertEquals(false, pb.isPaused(calendar.getTime()));
157         assertEquals(true, pb.isPaused(calendar3.getTime()));
158         assertEquals(true, pb.isPaused(calendar4.getTime()));
159         assertEquals(false, pb.isPaused(calendar5.getTime()));
160
161         pb.setDay("tuesday");
162
163         assertEquals(false, pb.isPaused(calendar.getTime()));
164         assertEquals(false, pb.isPaused(calendar3.getTime()));
165         assertEquals(false, pb.isPaused(calendar4.getTime()));
166         assertEquals(false, pb.isPaused(calendar5.getTime()));
167     }
168
169 }
170
Popular Tags