Source Code Cross Referenced for DateTagTest.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » views » jsp » ui » 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 » J2EE » webwork 2.2.6 » com.opensymphony.webwork.views.jsp.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.views.jsp.ui;
006:
007:        import com.opensymphony.webwork.views.jsp.AbstractTagTest;
008:        import com.opensymphony.webwork.views.jsp.DateTag;
009:        import com.opensymphony.xwork.ActionContext;
010:
011:        import java.text.DateFormat;
012:        import java.text.SimpleDateFormat;
013:        import java.util.Calendar;
014:        import java.util.Date;
015:
016:        /**
017:         * Unit test for {@link com.opensymphony.webwork.components.Date}.
018:         *
019:         * @author Claus Ibsen
020:         */
021:        public class DateTagTest extends AbstractTagTest {
022:
023:            private DateTag tag;
024:
025:            public void testCustomFormat() throws Exception {
026:                String format = "yyyy/MM/dd hh:mm:ss";
027:                Date now = new Date();
028:                String formatted = new SimpleDateFormat(format).format(now);
029:                context.put("myDate", now);
030:
031:                tag.setName("myDate");
032:                tag.setNice(false);
033:                tag.setFormat(format);
034:                tag.doStartTag();
035:                tag.doEndTag();
036:                assertEquals(formatted, writer.toString());
037:            }
038:
039:            public void testDefaultFormat() throws Exception {
040:                Date now = new Date();
041:                String formatted = DateFormat.getDateTimeInstance(
042:                        DateFormat.MEDIUM, DateFormat.MEDIUM,
043:                        ActionContext.getContext().getLocale()).format(now);
044:
045:                context.put("myDate", now);
046:                tag.setName("myDate");
047:                tag.setNice(false);
048:                tag.doStartTag();
049:                tag.doEndTag();
050:                assertEquals(formatted, writer.toString());
051:            }
052:
053:            public void testCustomFormatAndComponent() throws Exception {
054:                String format = "yyyy/MM/dd hh:mm:ss";
055:                Date now = new Date();
056:                String formatted = new SimpleDateFormat(format).format(now);
057:                context.put("myDate", now);
058:
059:                tag.setName("myDate");
060:                tag.setFormat(format);
061:                tag.setNice(false);
062:
063:                tag.doStartTag();
064:
065:                // component test must be done between start and end tag
066:                com.opensymphony.webwork.components.Date component = (com.opensymphony.webwork.components.Date) tag
067:                        .getComponent();
068:                assertEquals("myDate", component.getName());
069:                assertEquals(format, component.getFormat());
070:                assertEquals(false, component.isNice());
071:
072:                tag.doEndTag();
073:
074:                assertEquals(formatted, writer.toString());
075:            }
076:
077:            public void testSetId() throws Exception {
078:                String format = "yyyy/MM/dd hh:mm:ss";
079:                Date now = new Date();
080:                String formatted = new SimpleDateFormat(format).format(now);
081:                context.put("myDate", now);
082:
083:                tag.setName("myDate");
084:                tag.setNice(false);
085:                tag.setFormat(format);
086:                tag.setId("myId");
087:                tag.doStartTag();
088:                tag.doEndTag();
089:                assertEquals(formatted, context.get("myId"));
090:            }
091:
092:            public void testFutureNiceHour() throws Exception {
093:                Date now = new Date();
094:                Calendar future = Calendar.getInstance();
095:                future.setTime(now);
096:                future.add(Calendar.HOUR, 1);
097:                future.add(Calendar.SECOND, 5); // always add a little slack otherwise we could calculate wrong
098:
099:                context.put("myDate", future.getTime());
100:                tag.setName("myDate");
101:                tag.setNice(true);
102:                tag.doStartTag();
103:                tag.doEndTag();
104:                assertEquals("in one hour", writer.toString());
105:            }
106:
107:            public void testPastNiceHour() throws Exception {
108:                Date now = new Date();
109:                Calendar future = Calendar.getInstance();
110:                future.setTime(now);
111:                future.add(Calendar.HOUR, -1);
112:                future.add(Calendar.SECOND, -5); // always add a little slack otherwise we could calculate wrong
113:
114:                context.put("myDate", future.getTime());
115:                tag.setName("myDate");
116:                tag.setNice(true);
117:                tag.doStartTag();
118:                tag.doEndTag();
119:                assertEquals("one hour ago", writer.toString());
120:            }
121:
122:            public void testFutureNiceHourMinSec() throws Exception {
123:                Date now = new Date();
124:                Calendar future = Calendar.getInstance();
125:                future.setTime(now);
126:                future.add(Calendar.HOUR, 2);
127:                future.add(Calendar.MINUTE, 33);
128:                future.add(Calendar.SECOND, 5); // always add a little slack otherwise we could calculate wrong
129:
130:                context.put("myDate", future.getTime());
131:                tag.setName("myDate");
132:                tag.setNice(true);
133:                tag.doStartTag();
134:                tag.doEndTag();
135:                assertEquals("in 2 hours, 33 minutes", writer.toString());
136:            }
137:
138:            public void testPastNiceHourMin() throws Exception {
139:                Date now = new Date();
140:                Calendar past = Calendar.getInstance();
141:                past.setTime(now);
142:                past.add(Calendar.HOUR, -4);
143:                past.add(Calendar.MINUTE, -55);
144:                past.add(Calendar.SECOND, -5); // always add a little slack otherwise we could calculate wrong
145:
146:                context.put("myDate", past.getTime());
147:                tag.setName("myDate");
148:                tag.setNice(true);
149:                tag.doStartTag();
150:                tag.doEndTag();
151:                assertEquals("4 hours, 55 minutes ago", writer.toString());
152:            }
153:
154:            public void testFutureLessOneMin() throws Exception {
155:                Date now = new Date();
156:                Calendar future = Calendar.getInstance();
157:                future.setTime(now);
158:                future.add(Calendar.SECOND, 47);
159:                future.add(Calendar.SECOND, 5); // always add a little slack otherwise we could calculate wrong
160:
161:                context.put("myDate", future.getTime());
162:                tag.setName("myDate");
163:                tag.setNice(true);
164:                tag.doStartTag();
165:                tag.doEndTag();
166:                assertEquals("in an instant", writer.toString());
167:            }
168:
169:            public void testFutureLessOneHour() throws Exception {
170:                Date now = new Date();
171:                Calendar future = Calendar.getInstance();
172:                future.setTime(now);
173:                future.add(Calendar.MINUTE, 36);
174:                future.add(Calendar.SECOND, 5); // always add a little slack otherwise we could calculate wrong
175:
176:                context.put("myDate", future.getTime());
177:                tag.setName("myDate");
178:                tag.setNice(true);
179:                tag.doStartTag();
180:                tag.doEndTag();
181:                assertEquals("in 36 minutes", writer.toString());
182:            }
183:
184:            public void testFutureLessOneYear() throws Exception {
185:                Date now = new Date();
186:                Calendar future = Calendar.getInstance();
187:                future.setTime(now);
188:                future.add(Calendar.HOUR, 40 * 24);
189:                future.add(Calendar.SECOND, 5); // always add a little slack otherwise we could calculate wrong
190:
191:                context.put("myDate", future.getTime());
192:                tag.setName("myDate");
193:                tag.setNice(true);
194:                tag.doStartTag();
195:                tag.doEndTag();
196:                assertEquals("in 40 days", writer.toString());
197:            }
198:
199:            public void testFutureTwoYears() throws Exception {
200:                Date now = new Date();
201:                Calendar future = Calendar.getInstance();
202:                future.setTime(now);
203:                future.add(Calendar.YEAR, 2);
204:                future.add(Calendar.SECOND, 5); // always add a little slack otherwise we could calculate wrong
205:
206:                context.put("myDate", future.getTime());
207:                tag.setName("myDate");
208:                tag.setNice(true);
209:                tag.doStartTag();
210:                tag.doEndTag();
211:
212:                // hmmm the Date component isn't the best to calculate the excat difference so we'll just check
213:                // that it starts with in 2 years
214:                assertTrue(writer.toString().startsWith("in 2 years"));
215:            }
216:
217:            public void testNoDateObjectInContext() throws Exception {
218:                context.put("myDate", "this is not a java.util.Date object");
219:                tag.setName("myDate");
220:                tag.setNice(true);
221:                tag.doStartTag();
222:                tag.doEndTag();
223:                //should return a blank
224:                assertEquals("", writer.toString());
225:            }
226:
227:            protected void setUp() throws Exception {
228:                super .setUp();
229:                tag = new DateTag();
230:                tag.setPageContext(pageContext);
231:            }
232:
233:            protected void tearDown() throws Exception {
234:                super.tearDown();
235:            }
236:
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.