KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > CronExpressionTest


1 /*
2  * Copyright 2004-2006 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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;
17
18 import java.text.ParseException JavaDoc;
19 import java.util.Calendar JavaDoc;
20 import java.util.TimeZone JavaDoc;
21
22 public class CronExpressionTest extends SerializationTestSupport {
23     private static final String JavaDoc[] VERSIONS = new String JavaDoc[] {"1.5.2"};
24
25     private static final TimeZone JavaDoc EST_TIME_ZONE = TimeZone.getTimeZone("US/Eastern");
26
27     /**
28      * Get the object to serialize when generating serialized file for future
29      * tests, and against which to validate deserialized object.
30      */

31     protected Object JavaDoc getTargetObject() throws ParseException JavaDoc {
32         CronExpression cronExpression = new CronExpression("0 15 10 * * ? 2005");
33         cronExpression.setTimeZone(EST_TIME_ZONE);
34         
35         return cronExpression;
36     }
37     
38     /**
39      * Get the Quartz versions for which we should verify
40      * serialization backwards compatibility.
41      */

42     protected String JavaDoc[] getVersions() {
43         return VERSIONS;
44     }
45     
46     /**
47      * Verify that the target object and the object we just deserialized
48      * match.
49      */

50     protected void verifyMatch(Object JavaDoc target, Object JavaDoc deserialized) {
51         CronExpression targetCronExpression = (CronExpression)target;
52         CronExpression deserializedCronExpression = (CronExpression)deserialized;
53         
54         assertNotNull(deserializedCronExpression);
55         assertEquals(targetCronExpression.getCronExpression(), deserializedCronExpression.getCronExpression());
56         assertEquals(targetCronExpression.getTimeZone(), deserializedCronExpression.getTimeZone());
57     }
58     
59     /*
60      * Test method for 'org.quartz.CronExpression.isSatisfiedBy(Date)'.
61      */

62     public void testIsSatisfiedBy() throws Exception JavaDoc {
63         CronExpression cronExpression = new CronExpression("0 15 10 * * ? 2005");
64         
65         Calendar cal = Calendar.getInstance();
66         
67         cal.set(2005, Calendar.JUNE, 1, 10, 15, 0);
68         assertTrue(cronExpression.isSatisfiedBy(cal.getTime()));
69         
70         cal.set(Calendar.YEAR, 2006);
71         assertFalse(cronExpression.isSatisfiedBy(cal.getTime()));
72
73         cal = Calendar.getInstance();
74         cal.set(2005, Calendar.JUNE, 1, 10, 16, 0);
75         assertFalse(cronExpression.isSatisfiedBy(cal.getTime()));
76
77         cal = Calendar.getInstance();
78         cal.set(2005, Calendar.JUNE, 1, 10, 14, 0);
79         assertFalse(cronExpression.isSatisfiedBy(cal.getTime()));
80     }
81 }
82
Popular Tags