001: /* ====================================================================
002: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003: *
004: * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by Jcorporate Ltd.
021: * (http://www.jcorporate.com/)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. "Jcorporate" and product names such as "Expresso" must
026: * not be used to endorse or promote products derived from this
027: * software without prior written permission. For written permission,
028: * please contact info@jcorporate.com.
029: *
030: * 5. Products derived from this software may not be called "Expresso",
031: * or other Jcorporate product names; nor may "Expresso" or other
032: * Jcorporate product names appear in their name, without prior
033: * written permission of Jcorporate Ltd.
034: *
035: * 6. No product derived from this software may compete in the same
036: * market space, i.e. framework, without prior written permission
037: * of Jcorporate Ltd. For written permission, please contact
038: * partners@jcorporate.com.
039: *
040: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051: * SUCH DAMAGE.
052: * ====================================================================
053: *
054: * This software consists of voluntary contributions made by many
055: * individuals on behalf of the Jcorporate Ltd. Contributions back
056: * to the project(s) are encouraged when you make modifications.
057: * Please send them to support@jcorporate.com. For more information
058: * on Jcorporate Ltd. and its products, please see
059: * <http://www.jcorporate.com/>.
060: *
061: * Portions of this software are based upon other open source
062: * products and are subject to their respective licenses.
063: */
064:
065: package com.jcorporate.expresso.core.misc.tests;
066:
067: import com.jcorporate.expresso.core.misc.DateTime;
068: import com.jcorporate.expresso.services.test.ExpressoTestCase;
069: import com.jcorporate.expresso.services.test.TestSystemInitializer;
070: import junit.framework.Test;
071: import junit.framework.TestSuite;
072: import junit.textui.TestRunner;
073:
074: import java.util.Calendar;
075: import java.util.Date;
076:
077: /**
078: * <p>Test case to verify DateTime utility class</p>
079: * <p>Copyright: Copyright (c) 2001-2002</p>
080: * <p>Company: JCorporate Ltd.</p>
081: *
082: * @author Tommy Grovnes
083: * @version $Revision: 1.2 $ on $Date: 2004/11/17 20:48:23 $
084: */
085: public class TestDateTime extends ExpressoTestCase {
086:
087: String myContext = TestSystemInitializer.getTestContext();
088:
089: public TestDateTime(String testName) throws Exception {
090: super (testName);
091: }
092:
093: public static Test suite() {
094: return new TestSuite(TestDateTime.class);
095: }
096:
097: public static void checkOKDate(String testName, String result) {
098: assertTrue("Not null Return ", (result != null));
099: assertTrue("Greater Than Zero Length Return ",
100: (result.length() > 0));
101: System.out.println(testName + " : result " + result);
102: }
103:
104: public static void checkNullDate(String testName, String result) {
105: assertTrue("Is Null Return ", (result == null));
106: System.out.println(testName + " : result " + result);
107: }
108:
109: public void testGoodDate() throws Exception {
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 date = new Date();
118: Calendar 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)", DateTime
135: .getDateTimeForDB(myContext));
136: checkOKDate(
137: "getDateTimeForDB(year, month, day, hour, min, sec, myContext)",
138: DateTime.getDateTimeForDB(year, month, day, hour, min,
139: sec, myContext));
140: checkOKDate("getDateTimeForDB(date, myContext)", DateTime
141: .getDateTimeForDB(date, myContext));
142: // checkOKDate("getDateString(aCalendar)",
143: // DateTime.getDateString(aCalendar));
144: checkOKDate(
145: "getDateTimeForDB(year, month, day, hour, min, sec)",
146: DateTime.getDateTimeForDB(year, month, day, hour, min,
147: sec));
148: checkOKDate("getDateTimeForDB(date)", DateTime
149: .getDateTimeForDB(date));
150: checkOKDate("getDateTimeString()", DateTime.getDateTimeString());
151: checkOKDate("getDateTimeString(date)", DateTime
152: .getDateTimeString(date));
153: checkOKDate("getTimeForDB()", DateTime.getTimeForDB());
154: checkOKDate("getTimeForDB(hour, min, sec)", DateTime
155: .getTimeForDB(hour, min, sec));
156: checkOKDate("getTimeForDB(date)", DateTime.getTimeForDB(date));
157: checkOKDate("getTimeForDB(date, myContext)", DateTime
158: .getTimeForDB(date, myContext));
159: checkOKDate("getDateForDB()", DateTime.getDateForDB());
160: checkOKDate("getDateForDB(year, month, day)", DateTime
161: .getDateForDB(year, month, day));
162: checkOKDate("getDateForDB(date)", DateTime.getDateForDB(date));
163: checkOKDate("getDateForDB(date, myContext)", DateTime
164: .getDateForDB(date, myContext));
165: }
166:
167: public void testNullDate() throws Exception {
168:
169: Date date = null;
170:
171: System.out.println("=======================================");
172: System.out.println("testNullDate\n");
173:
174: checkNullDate("getDateTimeForDB(date, myContext)", DateTime
175: .getDateTimeForDB(date, myContext));
176: checkNullDate("getDateTimeForDB(date)", DateTime
177: .getDateTimeForDB(date));
178: checkNullDate("getDateTimeString(date)", DateTime
179: .getDateTimeString(date));
180: checkNullDate("getTimeForDB(date)", DateTime.getTimeForDB(date));
181: checkNullDate("getTimeForDB(date, myContext)", DateTime
182: .getTimeForDB(date, myContext));
183: checkNullDate("getDateForDB(date)", DateTime.getDateForDB(date));
184: checkNullDate("getDateForDB(date, myContext)", DateTime
185: .getDateForDB(date, myContext));
186:
187: }
188:
189: public void testBadDate1() throws Exception {
190:
191: int year = -1;
192: int month = -1;
193: int day = -1;
194: int hour = -1;
195: int min = -1;
196: int sec = -1;
197: Calendar aCalendar = Calendar.getInstance();
198: aCalendar.set(year, month, day, hour, min, sec);
199:
200: System.out.println("=======================================");
201: System.out.println("testBadDate\n");
202: System.out.println("year = " + year);
203: System.out.println("month = " + month);
204: System.out.println("day = " + day);
205: System.out.println("hour = " + hour);
206: System.out.println("min = " + min);
207: System.out.println("sec = " + sec);
208: System.out.println("");
209:
210: System.out
211: .println("getDateTimeForDB(year, month, day, hour, min, sec, myContext) : result "
212: + DateTime.getDateTimeForDB(year, month, day,
213: hour, min, sec, myContext));
214: // System.out.println("getDateString(aCalendar) : result "
215: // + DateTime.getDateString(aCalendar));
216: System.out
217: .println("getDateTimeForDB(year, month, day, hour, min, sec) : result "
218: + DateTime.getDateTimeForDB(year, month, day,
219: hour, min, sec));
220: System.out.println("getTimeForDB(hour, min, sec) : result "
221: + DateTime.getTimeForDB(hour, min, sec));
222: System.out.println("getDateForDB(year, month, day) : result "
223: + DateTime.getDateForDB(year, month, day));
224:
225: }
226:
227: public void testBadDate2() throws Exception {
228:
229: int year = 99999;
230: int month = 99;
231: int day = 99;
232: int hour = 99;
233: int min = 99;
234: int sec = 99;
235: Calendar aCalendar = Calendar.getInstance();
236: aCalendar.set(year, month, day, hour, min, sec);
237:
238: System.out.println("=======================================");
239: System.out.println("testBadDate2\n");
240: System.out.println("year = " + year);
241: System.out.println("month = " + month);
242: System.out.println("day = " + day);
243: System.out.println("hour = " + hour);
244: System.out.println("min = " + min);
245: System.out.println("sec = " + sec);
246: System.out.println("");
247:
248: System.out
249: .println("getDateTimeForDB(year, month, day, hour, min, sec,"
250: + " myContext) : result "
251: + DateTime.getDateTimeForDB(year, month, day,
252: hour, min, sec, myContext));
253: // System.out.println("getDateString(aCalendar) : result " +
254: // DateTime.getDateString(aCalendar));
255: System.out
256: .println("getDateTimeForDB(year, month, day, hour, min, sec) : result "
257: + DateTime.getDateTimeForDB(year, month, day,
258: hour, min, sec));
259: System.out.println("getTimeForDB(hour, min, sec) : result "
260: + DateTime.getTimeForDB(hour, min, sec));
261: System.out.println("getDateForDB(year, month, day) : result "
262: + DateTime.getDateForDB(year, month, day));
263: }
264:
265: public static void main(String args[]) throws Exception {
266: TestRunner.run(suite());
267: }
268:
269: }
|