Source Code Cross Referenced for TestCharToDateFunction.java in  » Database-DBMS » axion » org » axiondb » functions » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » axion » org.axiondb.functions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: TestCharToDateFunction.java,v 1.9 2005/03/19 03:57:12 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:
041:        package org.axiondb.functions;
042:
043:        import java.sql.Timestamp;
044:        import java.util.HashMap;
045:
046:        import junit.framework.Test;
047:        import junit.framework.TestSuite;
048:
049:        import org.axiondb.AxionException;
050:        import org.axiondb.ColumnIdentifier;
051:        import org.axiondb.Literal;
052:        import org.axiondb.RowDecorator;
053:        import org.axiondb.engine.rows.SimpleRow;
054:        import org.axiondb.types.TimestampType;
055:
056:        /**
057:         * Unit tests for CharToDate function.
058:         * 
059:         * @version $Revision: 1.9 $ $Date: 2005/03/19 03:57:12 $ 
060:         * @author Jonathan Giron
061:         */
062:        public class TestCharToDateFunction extends BaseFunctionTest {
063:
064:            public TestCharToDateFunction(String testName) {
065:                super (testName);
066:            }
067:
068:            public static final void main(String[] args) {
069:                junit.textui.TestRunner.run(suite());
070:            }
071:
072:            public static Test suite() {
073:                return new TestSuite(TestCharToDateFunction.class);
074:            }
075:
076:            public void setUp() throws Exception {
077:                super .setUp();
078:                TimestampType.setTimeZone("GMT");
079:            }
080:
081:            /*
082:             * @see org.axiondb.functions.BaseFunctionTest#makeFunction()
083:             */
084:            protected ConcreteFunction makeFunction() {
085:                return new CharToDateFunction();
086:            }
087:
088:            public void testIsValid() {
089:                ConcreteFunction function = makeFunction();
090:                assertFalse(function.isValid());
091:                function.addArgument(new ColumnIdentifier("column"));
092:                assertFalse(function.isValid());
093:                function.addArgument(new ColumnIdentifier("column2"));
094:                assertTrue(function.isValid());
095:                function.addArgument(new ColumnIdentifier("column3"));
096:                assertTrue(function.isValid());
097:            }
098:
099:            public void testValidFormats() throws Exception {
100:                CharToDateFunction function = new CharToDateFunction();
101:                ColumnIdentifier dateStr = new ColumnIdentifier("dateStr");
102:                ColumnIdentifier formatLbl = new ColumnIdentifier("format");
103:
104:                function.addArgument(dateStr);
105:                function.addArgument(formatLbl);
106:
107:                HashMap map = new HashMap();
108:                map.put(dateStr, new Integer(0));
109:                map.put(formatLbl, new Integer(1));
110:
111:                RowDecorator dec = new RowDecorator(map);
112:
113:                // Sample time: 2004-04-01 12:00:00Z
114:                TimestampType.setTimeZone("GMT");
115:                final Timestamp target = new Timestamp(34 * 365 * 24 * 60 * 60
116:                        * 1000L + //year
117:                        9 * 24 * 60 * 60 * 1000L + // leap years
118:                        // '72,'76,'80,'84,'88,'92,'96, 2000,
119:                        // 2004
120:                        (31 + 28 + 31) * 24 * 60 * 60 * 1000L // April 01
121:                );
122:
123:                // Test YYYY-MM-DD date only format, with dash separators
124:                Literal format = new Literal("yyyy-mm-dd");
125:                dec
126:                        .setRow(new SimpleRow(new Object[] { "2004-04-01",
127:                                format }));
128:
129:                Object returnVal = function.evaluate(dec);
130:                assertEquals("Expected valid return for format "
131:                        + format.toString() + "; ", target, returnVal);
132:
133:                // Test US civilian time only format, with colon separators
134:                format = new Literal("hh:mi:ss am");
135:                dec
136:                        .setRow(new SimpleRow(new Object[] { "00:00:00 AM",
137:                                format }));
138:                returnVal = function.evaluate(dec);
139:                assertEquals("Expected valid return for format "
140:                        + format.toString() + "; ", new Timestamp(0), returnVal);
141:
142:                // Test NATO/military time only format, with colon separators and
143:                // milliseconds
144:                format = new Literal("hh24:mi:ss.ff");
145:                dec
146:                        .setRow(new SimpleRow(new Object[] { "16:30:00.00",
147:                                format }));
148:                returnVal = function.evaluate(dec);
149:                assertEquals("Expected valid return for format "
150:                        + format.toString() + "; ", new Timestamp(
151:                        ((16 * 60) + 30) * 60L * 1000L), returnVal);
152:
153:                // Test compact ISO 8601 format
154:                format = new Literal("yyyymmddThh24miss");
155:                dec.setRow(new SimpleRow(new Object[] { "20040401T000000",
156:                        format }));
157:                returnVal = function.evaluate(dec);
158:                assertEquals("Expected valid return for format "
159:                        + format.toString() + "; ", target, returnVal);
160:
161:                // Test three-letter month abbreviation
162:                format = new Literal("dd mon yyyy hh24:mi:ss.ff");
163:                dec.setRow(new SimpleRow(new Object[] {
164:                        "01 APR 2004 00:00:00.00", format }));
165:                returnVal = function.evaluate(dec);
166:                assertEquals("Expected valid return for format "
167:                        + format.toString() + "; ", target, returnVal);
168:
169:                // Test German-style date format, with dot separators
170:                format = new Literal("dd.mm.yyyy");
171:                dec
172:                        .setRow(new SimpleRow(new Object[] { "01.04.2004",
173:                                format }));
174:                returnVal = function.evaluate(dec);
175:                assertEquals("Expected valid return for format "
176:                        + format.toString() + "; ", target, returnVal);
177:
178:                // Test US-style date format with slash separators
179:                format = new Literal("mm/dd/yyyy");
180:                dec
181:                        .setRow(new SimpleRow(new Object[] { "04/01/2004",
182:                                format }));
183:                returnVal = function.evaluate(dec);
184:                assertEquals("Expected valid return for format "
185:                        + format.toString() + "; ", target, returnVal);
186:
187:                // Test pattern with all capital letters
188:                format = new Literal("YYYYMMDDTHH24MISS");
189:                dec.setRow(new SimpleRow(new Object[] { "20040401T000000",
190:                        format }));
191:                returnVal = function.evaluate(dec);
192:                assertEquals("Expected valid return for format "
193:                        + format.toString() + "; ", target, returnVal);
194:
195:                // Test day in year + 2 digit year (upper case form)
196:                format = new Literal("DDDYY");
197:                dec.setRow(new SimpleRow(new Object[] { "09204", format }));
198:                returnVal = function.evaluate(dec);
199:                assertEquals("Expected valid return for format "
200:                        + format.toString() + "; ", target, returnVal);
201:
202:                // Test day in year + 2 digit year (lower case form)
203:                format = new Literal("dddyy");
204:                dec.setRow(new SimpleRow(new Object[] { "09204", format }));
205:                returnVal = function.evaluate(dec);
206:                assertEquals("Expected valid return for format "
207:                        + format.toString() + "; ", target, returnVal);
208:            }
209:
210:            public void testValidFormatWithNonZeroSeconds() throws Exception {
211:                CharToDateFunction function = new CharToDateFunction();
212:                ColumnIdentifier dateStr = new ColumnIdentifier("dateStr");
213:                ColumnIdentifier formatLbl = new ColumnIdentifier("format");
214:
215:                function.addArgument(dateStr);
216:                function.addArgument(formatLbl);
217:
218:                HashMap map = new HashMap();
219:                map.put(dateStr, new Integer(0));
220:                map.put(formatLbl, new Integer(1));
221:
222:                RowDecorator dec = new RowDecorator(map);
223:
224:                // Sample time: 2004-04-01 12:00:45Z
225:                TimestampType.setTimeZone("GMT");
226:                final Timestamp target = new Timestamp(34 * 365 * 24 * 60 * 60
227:                        * 1000L + //year
228:                        9 * 24 * 60 * 60 * 1000L // leap years
229:                        // '72,'76,'80,'84,'88,'92,'96, 2000,
230:                        // 2004
231:                        + (31 + 28 + 31) * 24 * 60 * 60 * 1000L // April 01
232:                        + 45 * 1000L // 00:00:45
233:                );
234:
235:                // Test pattern with all capital letters and fractional seconds
236:                Literal format = new Literal("YYYYMMDDTHH24MISS");
237:                dec.setRow(new SimpleRow(new Object[] { "20040401T000045",
238:                        format }));
239:                Object returnVal = function.evaluate(dec);
240:                assertEquals("Expected valid return for format "
241:                        + format.toString() + "; ", target, returnVal);
242:
243:                final Timestamp target2 = new Timestamp(34 * 365 * 24 * 60 * 60
244:                        * 1000L + //year
245:                        9 * 24 * 60 * 60 * 1000L // leap years
246:                        // '72,'76,'80,'84,'88,'92,'96, 2000,
247:                        // 2004
248:                        + (31 + 28 + 31) * 24 * 60 * 60 * 1000L // April 01
249:                        + 45 * 1000L // 00:00:45
250:                        + 678L // 0.678
251:                );
252:                format = new Literal("YYYY-MM-DD HH24:MI:SS.FF");
253:                dec.setRow(new SimpleRow(new Object[] {
254:                        "2004-04-01 00:00:45.678", format }));
255:                returnVal = function.evaluate(dec);
256:                assertEquals("Expected valid return for format "
257:                        + format.toString() + "; ", target2, returnVal);
258:
259:                final Timestamp target3 = new Timestamp(34 * 365 * 24 * 60 * 60
260:                        * 1000L + //year
261:                        9 * 24 * 60 * 60 * 1000L // leap years
262:                        // '72,'76,'80,'84,'88,'92,'96, 2000,
263:                        // 2004
264:                        + (31 + 28 + 31) * 24 * 60 * 60 * 1000L // April 01
265:                        + 0 * 1000L // 00:00:00
266:                        + 678L // 0.678
267:                );
268:                format = new Literal("YYYY-MM-DD HH24:MI:SS.FF");
269:                dec.setRow(new SimpleRow(new Object[] {
270:                        "2004-04-01 00:00:00.678", format }));
271:                returnVal = function.evaluate(dec);
272:                assertEquals("Expected valid return for format "
273:                        + format.toString() + "; ", target3, returnVal);
274:            }
275:
276:            public void testNullDateStrYieldsNull() throws Exception {
277:                DateToCharFunction function = new DateToCharFunction();
278:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
279:                ColumnIdentifier formatLbl = new ColumnIdentifier("format");
280:
281:                function.addArgument(timestampLbl);
282:                function.addArgument(formatLbl);
283:
284:                HashMap map = new HashMap();
285:                map.put(timestampLbl, new Integer(0));
286:                map.put(formatLbl, new Integer(1));
287:
288:                RowDecorator dec = new RowDecorator(map);
289:                Literal format = new Literal("yyyy.mm.dd");
290:                dec.setRow(new SimpleRow(new Object[] { null, format }));
291:
292:                Object returnVal = function.evaluate(dec);
293:                assertNull(
294:                        "Null value for date-str input should have returned null",
295:                        returnVal);
296:            }
297:
298:            public void testInvalidDateStrThrowsException() throws Exception {
299:                CharToDateFunction function = new CharToDateFunction();
300:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
301:                ColumnIdentifier formatLbl = new ColumnIdentifier(
302:                        "formatLiteral");
303:
304:                function.addArgument(timestampLbl);
305:                function.addArgument(formatLbl);
306:
307:                HashMap map = new HashMap();
308:                map.put(timestampLbl, new Integer(0));
309:                map.put(formatLbl, new Integer(1));
310:
311:                RowDecorator dec = new RowDecorator(map);
312:                Literal format = new Literal("yyyy-mm-dd");
313:                dec.setRow(new SimpleRow(new Object[] { "abcdef", format }));
314:                try {
315:                    function.evaluate(dec);
316:                    fail("Unparseable value for date-str input should have thrown an Exception");
317:                } catch (AxionException e) {
318:                    // Desired effect - ignore.
319:                }
320:
321:                dec.setRow(new SimpleRow(new Object[] { null, format }));
322:                assertNull(function.evaluate(dec));
323:            }
324:
325:            public void testOutOfRangeYearInDateStrThrowsException()
326:                    throws Exception {
327:                CharToDateFunction function = new CharToDateFunction();
328:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
329:                ColumnIdentifier formatLbl = new ColumnIdentifier(
330:                        "formatLiteral");
331:
332:                function.addArgument(timestampLbl);
333:                function.addArgument(formatLbl);
334:
335:                HashMap map = new HashMap();
336:                map.put(timestampLbl, new Integer(0));
337:                map.put(formatLbl, new Integer(1));
338:
339:                RowDecorator dec = new RowDecorator(map);
340:
341:                Literal format = new Literal("yyyy-mm-dd");
342:                dec
343:                        .setRow(new SimpleRow(new Object[] { "-434-13-02",
344:                                format }));
345:                try {
346:                    function.evaluate(dec);
347:                    fail("Out-of-range month value for date-str input should have thrown an Exception");
348:                } catch (AxionException e) {
349:                    // Desired effect - ignore.
350:                }
351:            }
352:
353:            public void testOutOfRangeMonthInDateStrThrowsException()
354:                    throws Exception {
355:                CharToDateFunction function = new CharToDateFunction();
356:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
357:                ColumnIdentifier formatLbl = new ColumnIdentifier(
358:                        "formatLiteral");
359:
360:                function.addArgument(timestampLbl);
361:                function.addArgument(formatLbl);
362:
363:                HashMap map = new HashMap();
364:                map.put(timestampLbl, new Integer(0));
365:                map.put(formatLbl, new Integer(1));
366:
367:                RowDecorator dec = new RowDecorator(map);
368:
369:                Literal format = new Literal("yyyy-mm-dd");
370:                dec
371:                        .setRow(new SimpleRow(new Object[] { "2004-13-02",
372:                                format }));
373:                try {
374:                    function.evaluate(dec);
375:                    fail("Out-of-range month value for date-str input should have thrown an Exception");
376:                } catch (AxionException e) {
377:                    // Desired effect - ignore.
378:                }
379:
380:                dec
381:                        .setRow(new SimpleRow(new Object[] { "2004-00-01",
382:                                format }));
383:                try {
384:                    function.evaluate(dec);
385:                    fail("Out-of-range month value for date-str input should have thrown an Exception");
386:                } catch (AxionException e) {
387:                    // Desired effect - ignore.
388:                }
389:            }
390:
391:            public void testOutOfRangeDayInDateStrThrowsException()
392:                    throws Exception {
393:                CharToDateFunction function = new CharToDateFunction();
394:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
395:                ColumnIdentifier formatLbl = new ColumnIdentifier(
396:                        "formatLiteral");
397:
398:                function.addArgument(timestampLbl);
399:                function.addArgument(formatLbl);
400:
401:                HashMap map = new HashMap();
402:                map.put(timestampLbl, new Integer(0));
403:                map.put(formatLbl, new Integer(1));
404:
405:                RowDecorator dec = new RowDecorator(map);
406:
407:                Literal format = new Literal("yyyymmdd");
408:                dec.setRow(new SimpleRow(new Object[] { "20050229", format }));
409:                try {
410:                    function.evaluate(dec);
411:                    fail("Out-of-range day value for date-str input should have thrown an Exception");
412:                } catch (AxionException e) {
413:                    // Desired effect - ignore.
414:                }
415:
416:                format = new Literal("yyyymmdd");
417:                dec.setRow(new SimpleRow(new Object[] { "200502-1", format }));
418:                try {
419:                    function.evaluate(dec);
420:                    fail("Out-of-range day value for date-str input should have thrown an Exception");
421:                } catch (AxionException e) {
422:                    // Desired effect - ignore.
423:                }
424:
425:                format = new Literal("dddyy");
426:                dec.setRow(new SimpleRow(new Object[] { "36603", format }));
427:                try {
428:                    function.evaluate(dec);
429:                    fail("Out-of-range leap year day value for non-leap year date-str input should have thrown an Exception");
430:                } catch (AxionException e) {
431:                    // Desired effect - ignore.
432:                }
433:            }
434:
435:            public void testOutOfRangeHourInTimeStrThrowsException()
436:                    throws Exception {
437:                CharToDateFunction function = new CharToDateFunction();
438:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
439:                ColumnIdentifier formatLbl = new ColumnIdentifier(
440:                        "formatLiteral");
441:
442:                function.addArgument(timestampLbl);
443:                function.addArgument(formatLbl);
444:
445:                HashMap map = new HashMap();
446:                map.put(timestampLbl, new Integer(0));
447:                map.put(formatLbl, new Integer(1));
448:
449:                RowDecorator dec = new RowDecorator(map);
450:
451:                // Test 24-hour format range
452:                Literal format = new Literal("hh24:mi:ss");
453:                dec.setRow(new SimpleRow(new Object[] { "24:00:00", format }));
454:                try {
455:                    function.evaluate(dec);
456:                    fail("Out-of-range hour value (24) for hh24 date-str input should have thrown an Exception");
457:                } catch (AxionException e) {
458:                    // Desired effect - ignore.
459:                }
460:
461:                dec.setRow(new SimpleRow(new Object[] { "-1:00:00", format }));
462:                try {
463:                    function.evaluate(dec);
464:                    fail("Out-of-range hour value (-1) for hh24 date-str input should have thrown an Exception");
465:                } catch (AxionException e) {
466:                    // Desired effect - ignore.
467:                }
468:
469:                // Test 12-hour format range (1-12) [hh12]
470:                format = new Literal("hh12:mi:ss");
471:                dec.setRow(new SimpleRow(new Object[] { "13:00:00", format }));
472:                try {
473:                    function.evaluate(dec);
474:                    fail("Out-of-range hour value (13) for hh12 date-str input should have thrown an Exception");
475:                } catch (AxionException e) {
476:                    // Desired effect - ignore.
477:                }
478:
479:                dec.setRow(new SimpleRow(new Object[] { "-1:00:00", format }));
480:                try {
481:                    function.evaluate(dec);
482:                    fail("Out-of-range hour value (-1) for hh12 date-str input should have thrown an Exception");
483:                } catch (AxionException e) {
484:                    // Desired effect - ignore.
485:                }
486:
487:                // Test 12-hour format range (1-12) [hh - identical to hh12]
488:                format = new Literal("hh:mi:ss");
489:                dec.setRow(new SimpleRow(new Object[] { "13:00:00", format }));
490:                try {
491:                    function.evaluate(dec);
492:                    fail("Out-of-range hour value (13) for hh date-str input should have thrown an Exception");
493:                } catch (AxionException e) {
494:                    // Desired effect - ignore.
495:                }
496:
497:                dec.setRow(new SimpleRow(new Object[] { "-1:00:00", format }));
498:                try {
499:                    function.evaluate(dec);
500:                    fail("Out-of-range hour value (-1) for hh date-str input should have thrown an Exception");
501:                } catch (AxionException e) {
502:                    // Desired effect - ignore.
503:                }
504:            }
505:
506:            public void testOutOfRangeMinuteInTimeStrThrowsException()
507:                    throws Exception {
508:                CharToDateFunction function = new CharToDateFunction();
509:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
510:                ColumnIdentifier formatLbl = new ColumnIdentifier(
511:                        "formatLiteral");
512:
513:                function.addArgument(timestampLbl);
514:                function.addArgument(formatLbl);
515:
516:                HashMap map = new HashMap();
517:                map.put(timestampLbl, new Integer(0));
518:                map.put(formatLbl, new Integer(1));
519:
520:                RowDecorator dec = new RowDecorator(map);
521:
522:                // Test minute range (00-59)
523:                Literal format = new Literal("hh24:mi:ss");
524:                dec.setRow(new SimpleRow(new Object[] { "10:61:00", format }));
525:                try {
526:                    function.evaluate(dec);
527:                    fail("Out-of-range minute value (61) for hh date-str input should have thrown an Exception");
528:                } catch (AxionException e) {
529:                    // Desired effect - ignore.
530:                }
531:
532:                dec.setRow(new SimpleRow(new Object[] { "10:-1:00", format }));
533:                try {
534:                    function.evaluate(dec);
535:                    fail("Out-of-range minute value (-1) for hh date-str input should have thrown an Exception");
536:                } catch (AxionException e) {
537:                    // Desired effect - ignore.
538:                }
539:            }
540:
541:            public void testOutOfRangeSecondInTimeStrThrowsException()
542:                    throws Exception {
543:                CharToDateFunction function = new CharToDateFunction();
544:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
545:                ColumnIdentifier formatLbl = new ColumnIdentifier(
546:                        "formatLiteral");
547:
548:                function.addArgument(timestampLbl);
549:                function.addArgument(formatLbl);
550:
551:                HashMap map = new HashMap();
552:                map.put(timestampLbl, new Integer(0));
553:                map.put(formatLbl, new Integer(1));
554:
555:                RowDecorator dec = new RowDecorator(map);
556:
557:                // Test second range (00-59)
558:                Literal format = new Literal("hh24:mi:ss");
559:                dec.setRow(new SimpleRow(new Object[] { "10:00:61", format }));
560:                try {
561:                    function.evaluate(dec);
562:                    fail("Out-of-range second value (61) for hh date-str input should have thrown an Exception");
563:                } catch (AxionException e) {
564:                    // Desired effect - ignore.
565:                }
566:
567:                dec.setRow(new SimpleRow(new Object[] { "10:00:-1", format }));
568:                try {
569:                    function.evaluate(dec);
570:                    fail("Out-of-range second value (-1) for hh date-str input should have thrown an Exception");
571:                } catch (AxionException e) {
572:                    // Desired effect - ignore.
573:                }
574:            }
575:
576:            public void testMalformedAMPMThrowsException() throws Exception {
577:                CharToDateFunction function = new CharToDateFunction();
578:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
579:                ColumnIdentifier formatLbl = new ColumnIdentifier(
580:                        "formatLiteral");
581:
582:                function.addArgument(timestampLbl);
583:                function.addArgument(formatLbl);
584:
585:                HashMap map = new HashMap();
586:                map.put(timestampLbl, new Integer(0));
587:                map.put(formatLbl, new Integer(1));
588:
589:                RowDecorator dec = new RowDecorator(map);
590:
591:                // Test second range (00-59)
592:                Literal format = new Literal("hh24:mi:ss am");
593:                dec
594:                        .setRow(new SimpleRow(new Object[] { "10:00:00 DM",
595:                                format }));
596:                try {
597:                    function.evaluate(dec);
598:                    fail("Malformed text for AM date-str input should have thrown an Exception");
599:                } catch (AxionException e) {
600:                    // Desired effect - ignore.
601:                }
602:
603:            }
604:
605:            public void testInvalidFormatThrowsException() throws Exception {
606:                CharToDateFunction function = new CharToDateFunction();
607:                ColumnIdentifier timestampLbl = new ColumnIdentifier("dateStr");
608:                ColumnIdentifier formatLbl = new ColumnIdentifier("format");
609:
610:                function.addArgument(timestampLbl);
611:                function.addArgument(formatLbl);
612:
613:                HashMap map = new HashMap();
614:                map.put(timestampLbl, new Integer(0));
615:                map.put(formatLbl, new Integer(1));
616:
617:                RowDecorator dec = new RowDecorator(map);
618:                Literal format = new Literal("bcdef");
619:                dec
620:                        .setRow(new SimpleRow(new Object[] { "2004-04-01",
621:                                format }));
622:                try {
623:                    function.evaluate(dec);
624:                    fail("Invalid value for format input should have thrown an Exception");
625:                } catch (AxionException e) {
626:                    // Desired effect - ignore.
627:                }
628:            }
629:
630:            public void testNullFormatThrowsException() throws Exception {
631:                CharToDateFunction function = new CharToDateFunction();
632:                ColumnIdentifier timestampLbl = new ColumnIdentifier(
633:                        "timestamp");
634:                ColumnIdentifier formatLbl = new ColumnIdentifier(
635:                        "formatLiteral");
636:
637:                function.addArgument(timestampLbl);
638:                function.addArgument(formatLbl);
639:
640:                HashMap map = new HashMap();
641:                map.put(timestampLbl, new Integer(0));
642:                map.put(formatLbl, new Integer(1));
643:
644:                RowDecorator dec = new RowDecorator(map);
645:                dec.setRow(new SimpleRow(new Object[] { "2004-04-15", null }));
646:                try {
647:                    function.evaluate(dec);
648:                    fail("Null for format input should have thrown an Exception");
649:                } catch (AxionException e) {
650:                    // Desired effect - ignore.
651:                }
652:            }
653:
654:            public void testMakeNewInstance() {
655:                CharToDateFunction function = new CharToDateFunction();
656:                assertTrue(function.makeNewInstance() instanceof  CharToDateFunction);
657:                assertTrue(function.makeNewInstance() != function
658:                        .makeNewInstance());
659:            }
660:
661:            public void testInvalid() throws Exception {
662:                CharToDateFunction function = new CharToDateFunction();
663:                assertTrue(!function.isValid());
664:            }
665:
666:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.