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


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.webwork.portlet.util;
006:
007:        import java.util.ArrayList;
008:        import java.util.List;
009:
010:        import javax.servlet.RequestDispatcher;
011:        import javax.servlet.ServletRequest;
012:        import javax.servlet.ServletResponse;
013:
014:        import org.springframework.mock.web.MockHttpServletRequest;
015:        import org.springframework.mock.web.MockHttpServletResponse;
016:        import org.springframework.mock.web.MockRequestDispatcher;
017:
018:        import com.opensymphony.webwork.TestAction;
019:        import com.opensymphony.webwork.util.ListEntry;
020:        import com.opensymphony.webwork.util.WebWorkUtil;
021:        import com.opensymphony.xwork.util.OgnlValueStack;
022:
023:        import junit.framework.TestCase;
024:
025:        /**
026:         * Test case for WebWorkUtil.
027:         * 
028:         * @author tm_jee
029:         * @version $Date: 2006-03-14 17:48:21 +0100 (Tue, 14 Mar 2006) $ $Id: WebWorkUtilTest.java 2404 2006-03-14 16:48:21Z tmjee $
030:         */
031:        public class WebWorkUtilTest extends TestCase {
032:
033:            protected OgnlValueStack stack = null;
034:            protected InternalMockHttpServletRequest request = null;
035:            protected MockHttpServletResponse response = null;
036:            protected WebWorkUtil webWorkUtil = null;
037:
038:            public void testBeanMethod() throws Exception {
039:                Object o = webWorkUtil
040:                        .bean("com.opensymphony.webwork.TestAction");
041:                assertNotNull(o);
042:                assertTrue(o instanceof  TestAction);
043:            }
044:
045:            public void testIsTrueMethod() throws Exception {
046:                stack.push(new Object() {
047:                    public String getMyString() {
048:                        return "myString";
049:                    }
050:
051:                    public boolean getMyBoolean(boolean bool) {
052:                        return bool;
053:                    }
054:                });
055:                assertTrue(webWorkUtil.isTrue("myString == 'myString'"));
056:                assertFalse(webWorkUtil.isTrue("myString == 'myOtherString'"));
057:                assertTrue(webWorkUtil.isTrue("getMyBoolean(true)"));
058:                assertFalse(webWorkUtil.isTrue("getMyBoolean(false)"));
059:            }
060:
061:            public void testFindStringMethod() throws Exception {
062:                stack.push(new Object() {
063:                    public String getMyString() {
064:                        return "myString";
065:                    }
066:
067:                    public boolean getMyBoolean(boolean bool) {
068:                        return bool;
069:                    }
070:                });
071:
072:                assertEquals(webWorkUtil.findString("myString"), "myString");
073:                assertNull(webWorkUtil.findString("myOtherString"));
074:                assertEquals(webWorkUtil.findString("getMyBoolean(true)"),
075:                        "true");
076:            }
077:
078:            public void testIncludeMethod() throws Exception {
079:                webWorkUtil.include("/some/includedJspFile.jsp");
080:
081:                // with include, this must have been created and should not be null
082:                assertNotNull(request.getDispatcher());
083:                // this must be true, indicating we actaully ask container to do an include
084:                assertTrue(request.getDispatcher().included);
085:            }
086:
087:            public void testTextToHtmlMethod() throws Exception {
088:                assertEquals(
089:                        webWorkUtil
090:                                .textToHtml("<html><head><title>some title</title><body>some content</body></html>"),
091:                        "&lt;html&gt;&lt;head&gt;&lt;title&gt;some title&lt;/title&gt;&lt;body&gt;some content&lt;/body&gt;&lt;/html&gt;");
092:            }
093:
094:            public void testUrlEncodeMethod() throws Exception {
095:                assertEquals(
096:                        webWorkUtil
097:                                .urlEncode("http://www.opensymphony.com/webwork/index.jsp?param1=value1"),
098:                        "http%3A%2F%2Fwww.opensymphony.com%2Fwebwork%2Findex.jsp%3Fparam1%3Dvalue1");
099:            }
100:
101:            public void testBuildUrlMethod() throws Exception {
102:                request.setContextPath("/myContextPath");
103:                assertEquals(webWorkUtil.buildUrl("/someUrl?param1=value1"),
104:                        "/myContextPath/someUrl?param1=value1");
105:            }
106:
107:            public void testFindValueMethod() throws Exception {
108:                stack.push(new Object() {
109:                    public String getMyString() {
110:                        return "myString";
111:                    }
112:
113:                    public boolean getMyBoolean(boolean bool) {
114:                        return bool;
115:                    }
116:                });
117:                Object obj1 = webWorkUtil.findValue("myString",
118:                        "java.lang.String");
119:                Object obj2 = webWorkUtil.findValue("getMyBoolean(true)",
120:                        "java.lang.Boolean");
121:
122:                assertNotNull(obj1);
123:                assertNotNull(obj2);
124:                assertTrue(obj1 instanceof  String);
125:                assertTrue(obj2 instanceof  Boolean);
126:                assertEquals(obj1, "myString");
127:                assertEquals(obj2, Boolean.TRUE);
128:            }
129:
130:            public void testGetTextMethod() throws Exception {
131:                // this should be in xwork-messages.properties (included by default 
132:                // by LocalizedTextUtil
133:                assertNotNull(webWorkUtil
134:                        .getText("xwork.error.action.execution"));
135:                assertEquals(webWorkUtil
136:                        .getText("xwork.error.action.execution"),
137:                        "Error during Action invocation");
138:            }
139:
140:            public void testGetContextMethod() throws Exception {
141:                request.setContextPath("/myContext");
142:                assertEquals(webWorkUtil.getContext(), "/myContext");
143:            }
144:
145:            public void testMakeSelectListMethod() throws Exception {
146:                String[] selectedList = new String[] { "Car", "Airplane", "Bus" };
147:                List list = new ArrayList();
148:                list.add("Lorry");
149:                list.add("Car");
150:                list.add("Helicopter");
151:
152:                stack.getContext().put("mySelectedList", selectedList);
153:                stack.getContext().put("myList", list);
154:
155:                List listMade = webWorkUtil.makeSelectList("#mySelectedList",
156:                        "#myList", null, null);
157:
158:                assertEquals(listMade.size(), 3);
159:                assertEquals(((ListEntry) listMade.get(0)).getKey(), "Lorry");
160:                assertEquals(((ListEntry) listMade.get(0)).getValue(), "Lorry");
161:                assertEquals(((ListEntry) listMade.get(0)).getIsSelected(),
162:                        false);
163:                assertEquals(((ListEntry) listMade.get(1)).getKey(), "Car");
164:                assertEquals(((ListEntry) listMade.get(1)).getValue(), "Car");
165:                assertEquals(((ListEntry) listMade.get(1)).getIsSelected(),
166:                        true);
167:                assertEquals(((ListEntry) listMade.get(2)).getKey(),
168:                        "Helicopter");
169:                assertEquals(((ListEntry) listMade.get(2)).getValue(),
170:                        "Helicopter");
171:                assertEquals(((ListEntry) listMade.get(2)).getIsSelected(),
172:                        false);
173:            }
174:
175:            public void testHtmlEncode() throws Exception {
176:                assertEquals(
177:                        webWorkUtil
178:                                .htmlEncode("<html><head><title>some title</title><body>some content</body></html>"),
179:                        "&lt;html&gt;&lt;head&gt;&lt;title&gt;some title&lt;/title&gt;&lt;body&gt;some content&lt;/body&gt;&lt;/html&gt;");
180:            }
181:
182:            public void testToInt() throws Exception {
183:                assertEquals(webWorkUtil.toInt(11l), 11);
184:            }
185:
186:            public void testToLong() throws Exception {
187:                assertEquals(webWorkUtil.toLong(11), 11l);
188:            }
189:
190:            public void testToString() throws Exception {
191:                assertEquals(webWorkUtil.toString(1), "1");
192:                assertEquals(webWorkUtil.toString(11l), "11");
193:            }
194:
195:            // === Junit Hook
196:
197:            protected void setUp() throws Exception {
198:                super .setUp();
199:                stack = new OgnlValueStack();
200:                request = new InternalMockHttpServletRequest();
201:                response = new MockHttpServletResponse();
202:                webWorkUtil = new WebWorkUtil(stack, request, response);
203:            }
204:
205:            protected void tearDown() throws Exception {
206:                stack = null;
207:                request = null;
208:                response = null;
209:                webWorkUtil = null;
210:                super .tearDown();
211:            }
212:
213:            // === internal class to assist in testing
214:
215:            class InternalMockHttpServletRequest extends MockHttpServletRequest {
216:                InternalMockRequestDispatcher dispatcher = null;
217:
218:                public RequestDispatcher getRequestDispatcher(String path) {
219:                    dispatcher = new InternalMockRequestDispatcher(path);
220:                    return dispatcher;
221:                }
222:
223:                public InternalMockRequestDispatcher getDispatcher() {
224:                    return dispatcher;
225:                }
226:            }
227:
228:            class InternalMockRequestDispatcher extends MockRequestDispatcher {
229:                private String url;
230:                boolean included = false;
231:
232:                public InternalMockRequestDispatcher(String url) {
233:                    super (url);
234:                    this .url = url;
235:                }
236:
237:                public void include(ServletRequest servletRequest,
238:                        ServletResponse servletResponse) {
239:                    if (servletResponse instanceof  MockHttpServletResponse) {
240:                        ((MockHttpServletResponse) servletResponse)
241:                                .setIncludedUrl(this .url);
242:                    }
243:                    included = true;
244:                }
245:            }
246:
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.