1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
33
* PartialTimestampFormatTest.java
36
* Created on November 14, 2004, 12:49 AM
39
package org.ggf.drmaa;
43
import junit.framework.*;
47
* @author dan.templeton@sun.com
49
public class PartialTimestampFormatTest extends TestCase {
50
public PartialTimestampFormatTest(java.lang.String testName) {
54
public static Test suite() {
55
TestSuite suite = new TestSuite(PartialTimestampFormatTest.class);
59
/** Test of format method, of class org.ggf.drmaa.PartialTimestampFormat. */
60
public void testFormat() {
61
System.out.println("testFormat");
63
PartialTimestamp pt = new PartialTimestamp();
64
PartialTimestampFormat ptf = new PartialTimestampFormat();
66
pt.set(pt.HOUR_OF_DAY, 1);
67
pt.set(pt.MINUTE, 31);
68
assertEquals("01:31", ptf.format(pt));
70
pt.set(pt.DAY_OF_MONTH, 24);
71
assertEquals("24 01:31", ptf.format(pt));
73
pt.set(pt.MONTH, pt.NOVEMBER);
74
assertEquals("11/24 01:31", ptf.format(pt));
77
assertEquals("04/11/24 01:31", ptf.format(pt));
79
pt.set(pt.CENTURY, 20);
80
assertEquals("2004/11/24 01:31", ptf.format(pt));
82
pt.set(pt.SECOND, 17);
83
assertEquals("2004/11/24 01:31:17", ptf.format(pt));
85
pt.set(pt.ZONE_OFFSET, -2 * 60 * 60 * 1000);
86
assertEquals("2004/11/24 01:31:17 -02:00", ptf.format(pt));
88
pt = new PartialTimestamp();
90
pt.set(pt.HOUR_OF_DAY, 1);
91
pt.set(pt.MINUTE, 31);
92
assertEquals("01:31", ptf.format(pt));
94
pt.set(pt.SECOND, 17);
95
assertEquals("01:31:17", ptf.format(pt));
97
pt.set(pt.DAY_OF_MONTH, 24);
98
assertEquals("24 01:31:17", ptf.format(pt));
100
pt.set(pt.MONTH, pt.NOVEMBER);
101
assertEquals("11/24 01:31:17", ptf.format(pt));
104
assertEquals("04/11/24 01:31:17", ptf.format(pt));
106
pt.set(pt.CENTURY, 20);
107
assertEquals("2004/11/24 01:31:17", ptf.format(pt));
109
pt.set(pt.ZONE_OFFSET, -2 * 60 * 60 * 1000);
110
assertEquals("2004/11/24 01:31:17 -02:00", ptf.format(pt));
112
pt = new PartialTimestamp();
114
pt.set(pt.HOUR_OF_DAY, 1);
115
pt.set(pt.MINUTE, 31);
116
assertEquals("01:31", ptf.format(pt));
118
pt.set(pt.ZONE_OFFSET, -2 * 60 * 60 * 1000);
119
assertEquals("01:31 -02:00", ptf.format(pt));
121
pt.set(pt.DAY_OF_MONTH, 24);
122
assertEquals("24 01:31 -02:00", ptf.format(pt));
124
pt.set(pt.MONTH, pt.NOVEMBER);
125
assertEquals("11/24 01:31 -02:00", ptf.format(pt));
128
assertEquals("04/11/24 01:31 -02:00", ptf.format(pt));
130
pt.set(pt.CENTURY, 20);
131
assertEquals("2004/11/24 01:31 -02:00", ptf.format(pt));
133
pt.set(pt.SECOND, 17);
134
assertEquals("2004/11/24 01:31:17 -02:00", ptf.format(pt));
137
/** Test of parse method, of class org.ggf.drmaa.PartialTimestampFormat. */
138
public void testParse() throws ParseException {
139
System.out.println("testParse");
141
PartialTimestampFormat f = new PartialTimestampFormat();
143
/* These should succeed. */
144
PartialTimestamp pt = f.parse("2004/11/13 21:39:22 +01:00");
145
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, 22, 60 * 60 * 1000);
146
pt = f.parse("04/11/13 21:39:21 +01:00");
147
this.checkPT(pt, pt.UNSET, 04, pt.NOVEMBER, 13, 21, 39, 21, 60 * 60 * 1000);
148
pt = f.parse("11/13 21:39:21 +01:00");
149
this.checkPT(pt, pt.UNSET, pt.UNSET, pt.NOVEMBER, 13, 21, 39, 21, 60 * 60 * 1000);
150
pt = f.parse("13 21:39:21 +01:00");
151
this.checkPT(pt, pt.UNSET, pt.UNSET, pt.UNSET, 13, 21, 39, 21, 60 * 60 * 1000);
152
pt = f.parse("21:39:21 +01:00");
153
this.checkPT(pt, pt.UNSET, pt.UNSET, pt.UNSET, pt.UNSET, 21, 39, 21, 60 * 60 * 1000);
154
pt = f.parse("2004/11/13 21:39:21");
155
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, 21, pt.UNSET);
156
pt = f.parse("2004/11/13 21:39 +01:00");
157
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, pt.UNSET, 60 * 60 * 1000);
158
pt = f.parse("2004/11/13 21:39:21");
159
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, 21, pt.UNSET);
160
pt = f.parse("21:39:21");
161
this.checkPT(pt, pt.UNSET, pt.UNSET, pt.UNSET, pt.UNSET, 21, 39, 21, pt.UNSET);
162
pt = f.parse("21:39 +01:00");
163
this.checkPT(pt, pt.UNSET, pt.UNSET, pt.UNSET, pt.UNSET, 21, 39, pt.UNSET, 60 * 60 * 1000);
164
pt = f.parse("21:39");
165
this.checkPT(pt, pt.UNSET, pt.UNSET, pt.UNSET, pt.UNSET, 21, 39, pt.UNSET, pt.UNSET);
166
pt = f.parse(" 2004/11/13 21:39:21 +01:00");
167
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, 21, 60 * 60 * 1000);
168
pt = f.parse("2004/11/13 21:039:21 +01:00");
169
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 03, pt.UNSET, pt.UNSET);
170
pt = f.parse("2004/11/13 21:39:201 +01:00");
171
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, 20, pt.UNSET);
172
pt = f.parse("2004/11/13 21:39:21 01:00");
173
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, 21, pt.UNSET);
174
pt = f.parse("2004/11/13 21:39:21 :00");
175
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, 21, pt.UNSET);
176
pt = f.parse("2004/11/13 21:39:21 00");
177
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, 21, pt.UNSET);
178
pt = f.parse("2004/11/13 21:39: +01:00");
179
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, pt.UNSET, pt.UNSET);
180
pt = f.parse("2004/11/13 21:39:21 *01:00");
181
this.checkPT(pt, 20, 04, pt.NOVEMBER, 13, 21, 39, 21, pt.UNSET);
183
/* These should fail. */
185
f.parse("12004/11/13 21:39:21 +01:00");
186
fail("Allowed 12004/11/13 21:39:21 +01:00");
187
} catch (ParseException e) {
191
f.parse("2004/110/13 21:39:21 +01:00");
192
fail("Allowed 2004/110/13 21:39:21 +01:00");
193
} catch (ParseException e) {
197
f.parse("2004/11/103 21:39:21 +01:00");
198
fail("Allowed 2004/11/103 21:39:21 +01:00");
199
} catch (ParseException e) {
203
f.parse("2004/11/13 210:39:21 +01:00");
204
fail("Allowed 2004/11/13 210:39:21 +01:00");
205
} catch (ParseException e) {
209
f.parse("2004/11/13 21:39:21 +001:00");
210
fail("Allowed 2004/11/13 21:39:21 +001:00");
211
} catch (ParseException e) {
215
f.parse("204/11/13 21:39:21 +01:00");
216
fail("Allowed 204/11/13 21:39:21 +01:00");
217
} catch (ParseException e) {
221
f.parse("2004/1/13 21:39:21 +01:00");
222
fail("Allowed 2004/1/13 21:39:21 +01:00");
223
} catch (ParseException e) {
227
f.parse("2004/11/3 21:39:21 +01:00");
228
fail("Allowed 2004/11/3 21:39:21 +01:00");
229
} catch (ParseException e) {
233
f.parse("2004/11/13 1:39:21 +01:00");
234
fail("Allowed 2004/11/13 1:39:21 +01:00");
235
} catch (ParseException e) {
239
f.parse("2004/11/13 21:9:21 +01:00");
240
fail("Allowed 2004/11/13 21:9:21 +01:00");
241
} catch (ParseException e) {
245
f.parse("2004/11/13 21:39:2 +01:00");
246
fail("Allowed 2004/11/13 21:39:2 +01:00");
247
} catch (ParseException e) {
251
f.parse("2004/11/13 21:39:21 +1:00");
252
fail("Allowed 2004/11/13 21:39:21 +1:00");
253
} catch (ParseException e) {
257
f.parse("2004/11/13 21:39:21 +01:0");
258
fail("Allowed 2004/11/13 21:39:21 +01:0");
259
} catch (ParseException e) {
263
f.parse("2004/11/13 21:39:21 +01:");
264
fail("Allowed 2004/11/13 21:39:21 +01:");
265
} catch (ParseException e) {
269
f.parse("2004/11/13 21:39:21 +01");
270
fail("Allowed 2004/11/13 21:39:21 +01");
271
} catch (ParseException e) {
275
f.parse("2004/11/13 21:39:21 +0");
276
fail("Allowed 2004/11/13 21:39:21 +0");
277
} catch (ParseException e) {
281
f.parse("2004/11/13 21:39:21 +");
282
fail("Allowed 2004/11/13 21:39:21 +");
283
} catch (ParseException e) {
287
f.parse("2004/11/13 21: +01:00");
288
fail("Allowed 2004/11/13 21: +01:00");
289
} catch (ParseException e) {
293
f.parse("2004/11/13 :21 +01:00");
294
fail("Allowed 2004/11/13 :21 +01:00");
295
} catch (ParseException e) {
299
f.parse("2004/11/13 21 +01:00");
300
fail("Allowed 2004/11/13 21 +01:00");
301
} catch (ParseException e) {
305
f.parse("2004/11/ 21:39:21 +01:00");
306
fail("Allowed 2004/11/ 21:39:21 +01:00");
307
} catch (ParseException e) {
311
f.parse("2004// 21:39:21 +01:00");
312
fail("Allowed 2004// 21:39:21 +01:00");
313
} catch (ParseException e) {
317
f.parse("/11/13 21:39:21 +01:00");
318
fail("Allowed /11/13 21:39:21 +01:00");
319
} catch (ParseException e) {
323
f.parse("2004//13 21:39:21 +01:00");
324
fail("Allowed 2004//13 21:39:21 +01:00");
325
} catch (ParseException e) {
329
f.parse("//13 21:39:21 +01:00");
330
fail("Allowed //13 21:39:21 +01:00");
331
} catch (ParseException e) {
335
f.parse("2004/11/13/21:39:21 +01:00");
336
fail("Allowed 2004/11/13/21:39:21 +01:00");
337
} catch (ParseException e) {
341
f.parse("2004/11:13 21:39:21 +01:00");
342
fail("Allowed 2004/11:13 21:39:21 +01:00");
343
} catch (ParseException e) {
347
f.parse("2004:11/13 21:39:21 +01:00");
348
fail("Allowed 2004:11/13 21:39:21 +01:00");
349
} catch (ParseException e) {
353
f.parse("2004 11/13 21:39:21 +01:00");
354
fail("Allowed 2004 11/13 21:39:21 +01:00");
355
} catch (ParseException e) {
359
f.parse("2004/11 13 21:39:21 +01:00");
360
fail("Allowed 2004/11 13 21:39:21 +01:00");
361
} catch (ParseException e) {
365
f.parse("2004|11/13 21:39:21 +01:00");
366
fail("Allowed 2004|11/13 21:39:21 +01:00");
367
} catch (ParseException e) {
371
f.parse("2004/11/13 21;39:21 +01:00");
372
fail("Allowed 2004/11/13 21;39:21 +01:00");
373
} catch (ParseException e) {
377
f.parse("/2004/11/13 21:39:21 +01:00");
378
fail("Allowed /2004/11/13 21:39:21 +01:00");
379
} catch (ParseException e) {
383
f.parse("2004/11/13 21:3f:21 +01:00");
384
fail("Allowed 2004/11/13 21:3f:21 +01:00");
385
} catch (ParseException e) {
390
private void checkPT(PartialTimestamp pt, int century, int year, int month,
391
int date, int hour, int minute, int second,
393
assertEquals(century, pt.get(pt.CENTURY));
394
assertEquals(year, pt.get(pt.YEAR));
395
assertEquals(month, pt.get(pt.MONTH));
396
assertEquals(date, pt.get(pt.DAY_OF_MONTH));
397
assertEquals(hour, pt.get(pt.HOUR_OF_DAY));
398
assertEquals(minute, pt.get(pt.MINUTE));
399
assertEquals(second, pt.get(pt.SECOND));
400
assertEquals(offset, pt.get(pt.ZONE_OFFSET));