001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol;
037:
038: import junit.framework.TestCase;
039:
040: import java.util.Calendar;
041:
042: public class PauseBuilderTest extends TestCase {
043:
044: private Calendar cal, cal2;
045:
046: public PauseBuilderTest(String name) {
047: super (name);
048: }
049:
050: public void setUp() {
051: cal = Calendar.getInstance();
052: cal.clear();
053: cal.set(2001, Calendar.NOVEMBER, 22); //Thursday, November 22, 2001
054: cal2 = Calendar.getInstance();
055: cal2.clear();
056: cal2.set(2001, Calendar.NOVEMBER, 23); //Friday, November 23, 2001
057: }
058:
059: public void testValidate() {
060: PauseBuilder pb = new PauseBuilder();
061:
062: try {
063: pb.validate();
064: fail("PauseBuilder should throw exceptions when required fields are not set.");
065: } catch (CruiseControlException e) {
066: }
067:
068: pb.setStartTime(1400);
069: try {
070: pb.validate();
071: fail("PauseBuilder should throw exceptions when required fields are not set.");
072: } catch (CruiseControlException e) {
073: }
074:
075: pb.setEndTime(1500);
076:
077: try {
078: pb.validate();
079: } catch (CruiseControlException e) {
080: fail("PauseBuilder should not throw exceptions when required fields are set.");
081: }
082:
083: try {
084: pb.setDay("sUnDaY");
085: pb.validate();
086: pb.setDay("monday");
087: pb.validate();
088: pb.setDay("TuesdaY");
089: pb.validate();
090: pb.setDay("wedNESday");
091: pb.validate();
092: pb.setDay("Thursday");
093: pb.validate();
094: pb.setDay("friday");
095: pb.validate();
096: pb.setDay("SATURDAY");
097: pb.validate();
098: } catch (CruiseControlException e) {
099: fail("PauseBuilder shouldn't throw exception with english names for day of week (case insensitive)");
100: }
101: try {
102: pb.setDay("1");
103: pb.validate();
104: fail("PauseBuilder requires english names for day of week (case insensitive)");
105: } catch (CruiseControlException e) {
106: }
107: }
108:
109: public void testIsPaused() {
110: Calendar calendar = Calendar.getInstance();
111: calendar.set(2002, Calendar.DECEMBER, 23, 18, 00, 00);
112:
113: Calendar calendar2 = Calendar.getInstance();
114: calendar2.set(2002, Calendar.DECEMBER, 23, 20, 00, 00);
115:
116: Calendar calendar3 = Calendar.getInstance();
117: calendar3.set(2002, Calendar.DECEMBER, 23, 22, 00, 00);
118:
119: Calendar calendar4 = Calendar.getInstance();
120: calendar4.set(2002, Calendar.DECEMBER, 24, 3, 00, 00);
121:
122: Calendar calendar5 = Calendar.getInstance();
123: calendar5.set(2002, Calendar.DECEMBER, 24, 7, 00, 00);
124:
125: PauseBuilder pb = new PauseBuilder();
126: pb.setStartTime(1900);
127: pb.setEndTime(2100);
128:
129: assertEquals(false, pb.isPaused(calendar.getTime()));
130: assertEquals(true, pb.isPaused(calendar2.getTime()));
131: assertEquals(false, pb.isPaused(calendar3.getTime()));
132:
133: pb.setDay("monday");
134: assertEquals(false, pb.isPaused(calendar.getTime()));
135: assertEquals(true, pb.isPaused(calendar2.getTime()));
136: assertEquals(false, pb.isPaused(calendar3.getTime()));
137:
138: pb.setDay("tuesday");
139: assertEquals(false, pb.isPaused(calendar.getTime()));
140: assertEquals(false, pb.isPaused(calendar2.getTime()));
141: assertEquals(false, pb.isPaused(calendar3.getTime()));
142:
143: pb = new PauseBuilder();
144: pb.setStartTime(2100);
145: pb.setEndTime(500);
146:
147: assertEquals(false, pb.isPaused(calendar.getTime()));
148: assertEquals(true, pb.isPaused(calendar3.getTime()));
149: assertEquals(true, pb.isPaused(calendar4.getTime()));
150: assertEquals(false, pb.isPaused(calendar5.getTime()));
151:
152: pb.setDay("monday");
153:
154: assertEquals(false, pb.isPaused(calendar.getTime()));
155: assertEquals(true, pb.isPaused(calendar3.getTime()));
156: assertEquals(true, pb.isPaused(calendar4.getTime()));
157: assertEquals(false, pb.isPaused(calendar5.getTime()));
158:
159: pb.setDay("tuesday");
160:
161: assertEquals(false, pb.isPaused(calendar.getTime()));
162: assertEquals(false, pb.isPaused(calendar3.getTime()));
163: assertEquals(false, pb.isPaused(calendar4.getTime()));
164: assertEquals(false, pb.isPaused(calendar5.getTime()));
165: }
166:
167: }
|