001: /*
002: * $Id: TestDateTimeUtils.java,v 1.7 2005/06/18 01:03:44 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2004 Axion Development Team. 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
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040: package org.axiondb.util;
041:
042: import org.axiondb.AxionException;
043:
044: import junit.framework.Test;
045: import junit.framework.TestCase;
046: import junit.framework.TestSuite;
047:
048: /**
049: * Unit tests for DateTimeUtils function.
050: *
051: * @version $Revision: 1.7 $ $Date: 2005/06/18 01:03:44 $
052: * @author Jonathan Giron
053: */
054: public class TestDateTimeUtils extends TestCase {
055: public TestDateTimeUtils(String testName) {
056: super (testName);
057: }
058:
059: public static Test suite() {
060: return new TestSuite(TestDateTimeUtils.class);
061: }
062:
063: public void testProcessFormatStringWithValidInputs()
064: throws Exception {
065: assertEquals("hh", DateTimeUtils.processFormatString("HH"));
066: assertEquals("hh", DateTimeUtils.processFormatString("HH12"));
067: assertEquals("hh", DateTimeUtils.processFormatString("hh12"));
068: assertEquals("HH", DateTimeUtils.processFormatString("HH24"));
069: assertEquals("HH", DateTimeUtils.processFormatString("hh24"));
070: assertEquals("mmMM", DateTimeUtils.processFormatString("mimm"));
071: assertEquals("mmMM", DateTimeUtils.processFormatString("MIMM"));
072: assertEquals("mmMM", DateTimeUtils.processFormatString("MImm"));
073: assertEquals("mmMM", DateTimeUtils.processFormatString("miMM"));
074: assertEquals("yyyy", DateTimeUtils.processFormatString("YYYY"));
075: assertEquals("hhMMMM", DateTimeUtils
076: .processFormatString("hhMONTH"));
077: assertEquals("DDDyy", DateTimeUtils
078: .processFormatString("DDDYY"));
079: }
080:
081: public void testLabelToCode() throws Exception {
082: assertEquals(DateTimeUtils.DAY, DateTimeUtils
083: .labelToCode("day"));
084: assertEquals(DateTimeUtils.DAY, DateTimeUtils
085: .labelToCode("Day"));
086: assertEquals(DateTimeUtils.DAY, DateTimeUtils
087: .labelToCode("DAY"));
088:
089: assertEquals(DateTimeUtils.MONTH, DateTimeUtils
090: .labelToCode("month"));
091: assertEquals(DateTimeUtils.MONTH, DateTimeUtils
092: .labelToCode("Month"));
093: assertEquals(DateTimeUtils.MONTH, DateTimeUtils
094: .labelToCode("MONTH"));
095:
096: assertEquals(DateTimeUtils.YEAR, DateTimeUtils
097: .labelToCode("year"));
098: assertEquals(DateTimeUtils.YEAR, DateTimeUtils
099: .labelToCode("Year"));
100: assertEquals(DateTimeUtils.YEAR, DateTimeUtils
101: .labelToCode("YEAR"));
102:
103: assertEquals(DateTimeUtils.MINUTE, DateTimeUtils
104: .labelToCode("minute"));
105: assertEquals(DateTimeUtils.MINUTE, DateTimeUtils
106: .labelToCode("Minute"));
107: assertEquals(DateTimeUtils.MINUTE, DateTimeUtils
108: .labelToCode("MINUTE"));
109:
110: assertEquals(DateTimeUtils.SECOND, DateTimeUtils
111: .labelToCode("second"));
112: assertEquals(DateTimeUtils.SECOND, DateTimeUtils
113: .labelToCode("Second"));
114: assertEquals(DateTimeUtils.SECOND, DateTimeUtils
115: .labelToCode("SECOND"));
116:
117: assertEquals(DateTimeUtils.WEEK, DateTimeUtils
118: .labelToCode("week"));
119: assertEquals(DateTimeUtils.WEEK, DateTimeUtils
120: .labelToCode("Week"));
121: assertEquals(DateTimeUtils.WEEK, DateTimeUtils
122: .labelToCode("WEEK"));
123:
124: assertEquals(DateTimeUtils.QUARTER, DateTimeUtils
125: .labelToCode("quarter"));
126: assertEquals(DateTimeUtils.QUARTER, DateTimeUtils
127: .labelToCode("Quarter"));
128: assertEquals(DateTimeUtils.QUARTER, DateTimeUtils
129: .labelToCode("QUARTER"));
130:
131: assertEquals(DateTimeUtils.MILLISECOND, DateTimeUtils
132: .labelToCode("millisecond"));
133: assertEquals(DateTimeUtils.MILLISECOND, DateTimeUtils
134: .labelToCode("Millisecond"));
135: assertEquals(DateTimeUtils.MILLISECOND, DateTimeUtils
136: .labelToCode("MILLISECOND"));
137:
138: final String msg = "Expected AxionException (22006) - invalid interval format";
139: try {
140: DateTimeUtils.labelToCode("blah");
141: fail(msg);
142: } catch (AxionException expected) {
143: assertEquals(msg, "22006", expected.getSQLState());
144: }
145:
146: try {
147: DateTimeUtils.labelToCode(null);
148: fail(msg);
149: } catch (AxionException expected) {
150: assertEquals(msg, "22006", expected.getSQLState());
151: }
152: }
153:
154: public void testGetPartMnemonicFor() throws Exception {
155: String[][] partMnemonicPair = new String[][] {
156: new String[] { "WEEKDAY", "dow" },
157: new String[] { "WEEKDAY3", "dy" },
158: new String[] { "WEEKDAYFULL", "day" },
159: new String[] { "DAY", "dd" },
160: new String[] { "MONTH", "mm" },
161: new String[] { "MONTH3", "mon" },
162: new String[] { "MONTHFULL", "month" },
163: new String[] { "YEAR", "yyyy" },
164: new String[] { "YEAR2", "yy" },
165: new String[] { "HOUR", "h" },
166: new String[] { "HOUR12", "hh12" },
167: new String[] { "HOUR24", "hh24" },
168: new String[] { "MINUTE", "mi" },
169: new String[] { "SECOND", "ss" },
170: new String[] { "WEEK", "w" },
171: new String[] { "QUARTER", "q" },
172: new String[] { "MILLISECOND", "ff" },
173: new String[] { "AMPM", "am" } };
174:
175: for (int i = 0; i < partMnemonicPair.length; i++) {
176: assertEquals(partMnemonicPair[i][1], DateTimeUtils
177: .getPartMnemonicFor(partMnemonicPair[i][0]));
178: }
179:
180: final String msg = "Expected AxionException (22006) - invalid interval format";
181: try {
182: DateTimeUtils.getPartMnemonicFor(null);
183: fail(msg);
184: } catch (AxionException expected) {
185: assertEquals(msg, "22006", expected.getSQLState());
186: }
187:
188: try {
189: DateTimeUtils.getPartMnemonicFor("unknown");
190: fail(msg);
191: } catch (AxionException expected) {
192: assertEquals(msg, "22006", expected.getSQLState());
193: }
194: }
195: }
|