Source Code Cross Referenced for BaseValueParserCactusTest.java in  » Web-Framework » TURBINE » org » apache » turbine » util » parser » 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 » Web Framework » TURBINE » org.apache.turbine.util.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.util.parser;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.text.SimpleDateFormat;
023:        import java.util.Calendar;
024:        import java.util.Date;
025:        import junit.framework.Test;
026:        import junit.framework.TestSuite;
027:        import org.apache.cactus.ServletTestCase;
028:        import org.apache.turbine.Turbine;
029:        import org.apache.turbine.util.TimeSelector;
030:
031:        /**
032:         * Used to test how BaseValueParser works with TimeSelector fields.
033:         *
034:         * @author <a href="mailto:brekke@apache.org">Jeffrey D. Brekke</a>
035:         * @version $Id: BaseValueParserCactusTest.java 534527 2007-05-02 16:10:59Z tv $
036:         */
037:        public class BaseValueParserCactusTest extends ServletTestCase {
038:            Turbine turbine = null;
039:            BaseValueParser theBaseValueParser = null;
040:            SimpleDateFormat stf = null;
041:
042:            /**
043:             * Creates a new <code>BaseValueParserTest</code> instance.
044:             *
045:             * @param name a <code>String</code> value
046:             */
047:            public BaseValueParserCactusTest(String name) {
048:                super (name);
049:            }
050:
051:            /**
052:             * This setup will be running server side.  We startup Turbine and
053:             * get our test port from the properties.  This gets run before
054:             * each testXXX test.
055:             * @exception Exception if an error occurs
056:             */
057:            protected void setUp() throws Exception {
058:                super .setUp();
059:                /* Note: we are using the properties file from the cache test
060:                 *  since we don't really need any specific property at this
061:                 *  time.  Future tests may require a test case specific
062:                 *  properties file to be used.:
063:                 */
064:                config.setInitParameter("properties",
065:                        "/WEB-INF/conf/TurbineComplete.properties");
066:                turbine = new Turbine();
067:                turbine.init(config);
068:                theBaseValueParser = new BaseValueParser();
069:                stf = new SimpleDateFormat("hh:mm:ss a");
070:            }
071:
072:            /**
073:             * Shut down our turbine servlet and let our parents clean up also.
074:             *
075:             * @exception Exception if an error occurs
076:             */
077:            protected void tearDown() throws Exception {
078:                turbine.destroy();
079:                super .tearDown();
080:            }
081:
082:            /**
083:             * Return a test suite of all our tests.
084:             *
085:             * @return a <code>Test</code> value
086:             */
087:            public static Test suite() {
088:                return new TestSuite(BaseValueParserTest.class);
089:            }
090:
091:            /**
092:             * Test that a current time
093:             */
094:            public void testCurrentTime() {
095:                Calendar now = Calendar.getInstance();
096:                checkTime(now.get(Calendar.HOUR), now.get(Calendar.MINUTE), now
097:                        .get(Calendar.SECOND), now.get(Calendar.AM_PM), stf
098:                        .format(now.getTime()));
099:            }
100:
101:            /**
102:             * Test a time in the morning.
103:             */
104:            public void testMorning() {
105:                checkTime(10, 5, 30, Calendar.AM, "10:05:30 AM");
106:            }
107:
108:            /**
109:             * Test a time in the afternoon.
110:             */
111:            public void testAfternoon() {
112:                checkTime(5, 32, 6, Calendar.PM, "05:32:06 PM");
113:            }
114:
115:            /**
116:             * Test that an invalid time returns null.
117:             *
118:             */
119:            public void testInvalidTime() {
120:                theBaseValueParser.add(TimeSelector.HOUR_SUFFIX, 1);
121:                theBaseValueParser.add(TimeSelector.MINUTE_SUFFIX, 100);
122:                theBaseValueParser.add(TimeSelector.SECOND_SUFFIX, 0);
123:                theBaseValueParser.add(TimeSelector.AMPM_SUFFIX, Calendar.AM);
124:
125:                assertNull("Should not have received a date object.",
126:                        theBaseValueParser.getDate(""));
127:            }
128:
129:            /**
130:             * Test the midnight special case.
131:             */
132:            public void testMidnight() {
133:                checkTime(12, 0, 0, Calendar.AM, "12:00:00 AM");
134:            }
135:
136:            /**
137:             * Test the noon special case.
138:             */
139:            public void testNoon() {
140:                checkTime(12, 0, 0, Calendar.PM, "12:00:00 PM");
141:            }
142:
143:            /**
144:             * Helper method which sets up the parser and gets the date.
145:             *
146:             * @param hour an <code>int</code> value
147:             * @param min an <code>int</code> value
148:             * @param sec an <code>int</code> value
149:             * @param ampm an <code>int</code> value
150:             * @param results a <code>String</code> value
151:             */
152:            private void checkTime(int hour, int min, int sec, int ampm,
153:                    String results) {
154:                theBaseValueParser.add(TimeSelector.HOUR_SUFFIX, hour);
155:                theBaseValueParser.add(TimeSelector.MINUTE_SUFFIX, min);
156:                theBaseValueParser.add(TimeSelector.SECOND_SUFFIX, sec);
157:                theBaseValueParser.add(TimeSelector.AMPM_SUFFIX, ampm);
158:
159:                Date newDate = theBaseValueParser.getDate("");
160:                assertNotNull("Could not create date for " + results, newDate);
161:
162:                assertEquals(results, stf.format(newDate));
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.