KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > misc > tests > TestDateTime


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.core.misc.tests;
66
67 import com.jcorporate.expresso.core.misc.DateTime;
68 import com.jcorporate.expresso.services.test.ExpressoTestCase;
69 import com.jcorporate.expresso.services.test.TestSystemInitializer;
70 import junit.framework.Test;
71 import junit.framework.TestSuite;
72 import junit.textui.TestRunner;
73
74 import java.util.Calendar JavaDoc;
75 import java.util.Date JavaDoc;
76
77 /**
78  * <p>Test case to verify DateTime utility class</p>
79  * <p>Copyright: Copyright (c) 2001-2002</p>
80  * <p>Company: JCorporate Ltd.</p>
81  *
82  * @author Tommy Grovnes
83  * @version $Revision: 1.2 $ on $Date: 2004/11/17 20:48:23 $
84  */

85 public class TestDateTime extends ExpressoTestCase {
86
87     String JavaDoc myContext = TestSystemInitializer.getTestContext();
88
89     public TestDateTime(String JavaDoc testName)
90             throws Exception JavaDoc {
91         super(testName);
92     }
93
94     public static Test suite() {
95         return new TestSuite(TestDateTime.class);
96     }
97
98     public static void checkOKDate(String JavaDoc testName, String JavaDoc result) {
99         assertTrue("Not null Return ", (result != null));
100         assertTrue("Greater Than Zero Length Return ", (result.length() > 0));
101         System.out.println(testName + " : result " + result);
102     }
103
104     public static void checkNullDate(String JavaDoc testName, String JavaDoc result) {
105         assertTrue("Is Null Return ", (result == null));
106         System.out.println(testName + " : result " + result);
107     }
108
109     public void testGoodDate() throws Exception JavaDoc {
110
111         int year = 1969;
112         int month = 4;
113         int day = 22;
114         int hour = 13;
115         int min = 14;
116         int sec = 15;
117         Date JavaDoc date = new Date JavaDoc();
118         Calendar JavaDoc aCalendar = Calendar.getInstance();
119         aCalendar.set(year, month, day, hour, min, sec);
120
121         System.out.println("=======================================");
122         System.out.println("testGoodDate\n");
123         System.out.println("year = " + year);
124         System.out.println("month = " + month);
125         System.out.println("day = " + day);
126         System.out.println("hour = " + hour);
127         System.out.println("min = " + min);
128         System.out.println("sec = " + sec);
129         System.out.println("date = " + date);
130         System.out.println("");
131
132         checkOKDate("getDateString()", DateTime.getDateString());
133         checkOKDate("getDateTimeForDB()", DateTime.getDateTimeForDB());
134         checkOKDate("getDateTimeForDB(myContext)",
135                 DateTime.getDateTimeForDB(myContext));
136         checkOKDate("getDateTimeForDB(year, month, day, hour, min, sec, myContext)",
137                 DateTime.getDateTimeForDB(year, month, day, hour, min, sec, myContext));
138         checkOKDate("getDateTimeForDB(date, myContext)",
139                 DateTime.getDateTimeForDB(date, myContext));
140 // checkOKDate("getDateString(aCalendar)",
141
// DateTime.getDateString(aCalendar));
142
checkOKDate("getDateTimeForDB(year, month, day, hour, min, sec)",
143                 DateTime.getDateTimeForDB(year, month, day, hour, min, sec));
144         checkOKDate("getDateTimeForDB(date)",
145                 DateTime.getDateTimeForDB(date));
146         checkOKDate("getDateTimeString()",
147                 DateTime.getDateTimeString());
148         checkOKDate("getDateTimeString(date)",
149                 DateTime.getDateTimeString(date));
150         checkOKDate("getTimeForDB()", DateTime.getTimeForDB());
151         checkOKDate("getTimeForDB(hour, min, sec)",
152                 DateTime.getTimeForDB(hour, min, sec));
153         checkOKDate("getTimeForDB(date)", DateTime.getTimeForDB(date));
154         checkOKDate("getTimeForDB(date, myContext)",
155                 DateTime.getTimeForDB(date, myContext));
156         checkOKDate("getDateForDB()", DateTime.getDateForDB());
157         checkOKDate("getDateForDB(year, month, day)",
158                 DateTime.getDateForDB(year, month, day));
159         checkOKDate("getDateForDB(date)", DateTime.getDateForDB(date));
160         checkOKDate("getDateForDB(date, myContext)",
161                 DateTime.getDateForDB(date, myContext));
162     }
163
164     public void testNullDate() throws Exception JavaDoc {
165
166         Date JavaDoc date = null;
167
168         System.out.println("=======================================");
169         System.out.println("testNullDate\n");
170
171         checkNullDate("getDateTimeForDB(date, myContext)",
172                 DateTime.getDateTimeForDB(date, myContext));
173         checkNullDate("getDateTimeForDB(date)",
174                 DateTime.getDateTimeForDB(date));
175         checkNullDate("getDateTimeString(date)",
176                 DateTime.getDateTimeString(date));
177         checkNullDate("getTimeForDB(date)",
178                 DateTime.getTimeForDB(date));
179         checkNullDate("getTimeForDB(date, myContext)",
180                 DateTime.getTimeForDB(date, myContext));
181         checkNullDate("getDateForDB(date)",
182                 DateTime.getDateForDB(date));
183         checkNullDate("getDateForDB(date, myContext)",
184                 DateTime.getDateForDB(date, myContext));
185
186     }
187
188     public void testBadDate1() throws Exception JavaDoc {
189
190         int year = -1;
191         int month = -1;
192         int day = -1;
193         int hour = -1;
194         int min = -1;
195         int sec = -1;
196         Calendar JavaDoc aCalendar = Calendar.getInstance();
197         aCalendar.set(year, month, day, hour, min, sec);
198
199         System.out.println("=======================================");
200         System.out.println("testBadDate\n");
201         System.out.println("year = " + year);
202         System.out.println("month = " + month);
203         System.out.println("day = " + day);
204         System.out.println("hour = " + hour);
205         System.out.println("min = " + min);
206         System.out.println("sec = " + sec);
207         System.out.println("");
208
209         System.out.println("getDateTimeForDB(year, month, day, hour, min, sec, myContext) : result "
210                 + DateTime.getDateTimeForDB(year, month, day, hour, min, sec, myContext));
211 // System.out.println("getDateString(aCalendar) : result "
212
// + DateTime.getDateString(aCalendar));
213
System.out.println("getDateTimeForDB(year, month, day, hour, min, sec) : result "
214                 + DateTime.getDateTimeForDB(year, month, day, hour, min, sec));
215         System.out.println("getTimeForDB(hour, min, sec) : result "
216                 + DateTime.getTimeForDB(hour, min, sec));
217         System.out.println("getDateForDB(year, month, day) : result "
218                 + DateTime.getDateForDB(year, month, day));
219
220     }
221
222     public void testBadDate2() throws Exception JavaDoc {
223
224         int year = 99999;
225         int month = 99;
226         int day = 99;
227         int hour = 99;
228         int min = 99;
229         int sec = 99;
230         Calendar JavaDoc aCalendar = Calendar.getInstance();
231         aCalendar.set(year, month, day, hour, min, sec);
232
233         System.out.println("=======================================");
234         System.out.println("testBadDate2\n");
235         System.out.println("year = " + year);
236         System.out.println("month = " + month);
237         System.out.println("day = " + day);
238         System.out.println("hour = " + hour);
239         System.out.println("min = " + min);
240         System.out.println("sec = " + sec);
241         System.out.println("");
242
243         System.out.println("getDateTimeForDB(year, month, day, hour, min, sec," +
244                 " myContext) : result "
245                 + DateTime.getDateTimeForDB(year, month,
246                         day, hour, min, sec, myContext));
247 // System.out.println("getDateString(aCalendar) : result " +
248
// DateTime.getDateString(aCalendar));
249
System.out.println("getDateTimeForDB(year, month, day, hour, min, sec) : result " +
250                 DateTime.getDateTimeForDB(year, month, day,
251                         hour, min, sec));
252         System.out.println("getTimeForDB(hour, min, sec) : result " +
253                 DateTime.getTimeForDB(hour, min, sec));
254         System.out.println("getDateForDB(year, month, day) : result " +
255                 DateTime.getDateForDB(year, month, day));
256     }
257
258
259     public static void main(String JavaDoc args[])
260             throws Exception JavaDoc {
261         TestRunner.run(suite());
262     }
263
264 }
265
266
Popular Tags