01: /*
02: * Copyright 2004-2006 OpenSymphony
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy
06: * of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations
14: * under the License.
15: */
16: package org.quartz.impl.calendar;
17:
18: import org.quartz.SerializationTestSupport;
19:
20: /**
21: * Unit test for DailyCalendar.
22: */
23: public class DailyCalendarTest extends SerializationTestSupport {
24: private static final String[] VERSIONS = new String[] { "1.5.2" };
25:
26: public void testStringStartEndTimes() {
27: DailyCalendar dailyCalendar = new DailyCalendar("TestCal",
28: "1:20", "14:50");
29: assertTrue(dailyCalendar.toString().indexOf(
30: "01:20:00:000 - 14:50:00:000") > 0);
31:
32: dailyCalendar = new DailyCalendar("TestCal", "1:20:1:456",
33: "14:50:15:2");
34: assertTrue(dailyCalendar.toString().indexOf(
35: "01:20:01:456 - 14:50:15:002") > 0);
36: }
37:
38: public void testStringInvertTimeRange() {
39: DailyCalendar dailyCalendar = new DailyCalendar("TestCal",
40: "1:20", "14:50");
41: dailyCalendar.setInvertTimeRange(true);
42: assertTrue(dailyCalendar.toString().indexOf("inverted: true") > 0);
43:
44: dailyCalendar.setInvertTimeRange(false);
45: assertTrue(dailyCalendar.toString().indexOf("inverted: false") > 0);
46: }
47:
48: /**
49: * Get the object to serialize when generating serialized file for future
50: * tests, and against which to validate deserialized object.
51: */
52: protected Object getTargetObject() {
53: DailyCalendar c = new DailyCalendar("TestCal", "01:20:01:456",
54: "14:50:15:002");
55: c.setDescription("description");
56: c.setInvertTimeRange(true);
57:
58: return c;
59: }
60:
61: /**
62: * Get the Quartz versions for which we should verify
63: * serialization backwards compatibility.
64: */
65: protected String[] getVersions() {
66: return VERSIONS;
67: }
68:
69: /**
70: * Verify that the target object and the object we just deserialized
71: * match.
72: */
73: protected void verifyMatch(Object target, Object deserialized) {
74: DailyCalendar targetCalendar = (DailyCalendar) target;
75: DailyCalendar deserializedCalendar = (DailyCalendar) deserialized;
76:
77: assertNotNull(deserializedCalendar);
78: assertEquals(targetCalendar.getDescription(),
79: deserializedCalendar.getDescription());
80: assertTrue(deserializedCalendar.getInvertTimeRange());
81: assertNull(deserializedCalendar.getTimeZone());
82: assertTrue(deserializedCalendar.toString().indexOf(
83: "01:20:01:456 - 14:50:15:002") > 0);
84: }
85: }
|