Source Code Cross Referenced for URLTagTest.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » views » jsp » 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 
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;
006:
007:        import java.util.HashMap;
008:        import java.util.Map;
009:
010:        import javax.servlet.jsp.JspException;
011:        import javax.servlet.jsp.JspWriter;
012:        import java.io.StringWriter;
013:
014:        import com.opensymphony.webwork.components.URL;
015:
016:        import com.opensymphony.webwork.views.jsp.ParamTag;
017:        import org.springframework.mock.web.MockHttpServletRequest;
018:        import org.springframework.mock.web.MockHttpServletResponse;
019:
020:        import com.opensymphony.xwork.util.OgnlValueStack;
021:
022:        /**
023:         * Unit test for {@link URLTag}.
024:         *
025:         * @author Brock Bulger (brockman_bulger@hotmail.com)
026:         * @version $Date: 2006-08-31 20:31:11 +0200 (Thu, 31 Aug 2006) $ $Id: URLTagTest.java 2711 2006-08-31 18:31:11Z tmjee $
027:         */
028:        public class URLTagTest extends AbstractUITagTest {
029:
030:            private URLTag tag;
031:
032:            /**
033:             * To test priority of parameter passed in to url component though 
034:             * various way 
035:             *  - current request url
036:             *  - tag's value attribute
037:             *  - tag's nested param tag
038:             * 
039:             * id1
040:             * ===
041:             * - found in current request url
042:             * - found in tag's value attribute
043:             * - found in tag's param tag
044:             * CONCLUSION: tag's param tag takes precedence (paramId1)
045:             * 
046:             * id2
047:             * ===
048:             * - found in current request url
049:             * - found in tag's value attribute
050:             * CONCLUSION: tag's value attribute take precedence (tagId2)
051:             * 
052:             * urlParam1
053:             * =========
054:             * - found in current request url
055:             * CONCLUSION: param in current request url will be used (urlValue1)
056:             * 
057:             * urlParam2
058:             * =========
059:             * - found in current request url
060:             * CONCLUSION: param in current request url will be used. (urlValue2)
061:             * 
062:             * tagId
063:             * =====
064:             * - found in tag's value attribute
065:             * CONCLUSION: param in tag's value attribute wil; be used. (tagValue)
066:             * 
067:             * param1
068:             * ======
069:             * - found in nested param tag
070:             * CONCLUSION: param in nested param tag will be used. (param1value)
071:             * 
072:             * param2
073:             * ======
074:             * - found in nested param tag
075:             * CONCLUSION: param in nested param tag will be used. (param2value)
076:             */
077:            public void testParametersPriority() throws Exception {
078:                request
079:                        .setQueryString("id1=urlId1&id2=urlId2&urlParam1=urlValue1&urlParam2=urlValue2");
080:
081:                tag
082:                        .setValue("testAction.action?id1=tagId1&id2=tagId2&tagId=tagValue");
083:
084:                ParamTag param1 = new ParamTag();
085:                param1.setPageContext(pageContext);
086:                param1.setName("param1");
087:                param1.setValue("%{'param1value'}");
088:
089:                ParamTag param2 = new ParamTag();
090:                param2.setPageContext(pageContext);
091:                param2.setName("param2");
092:                param2.setValue("%{'param2value'}");
093:
094:                ParamTag param3 = new ParamTag();
095:                param3.setPageContext(pageContext);
096:                param3.setName("id1");
097:                param3.setValue("%{'paramId1'}");
098:
099:                tag.doStartTag();
100:                param1.doStartTag();
101:                param1.doEndTag();
102:                param2.doStartTag();
103:                param2.doEndTag();
104:                param3.doStartTag();
105:                param3.doEndTag();
106:
107:                URL url = (URL) tag.getComponent();
108:                Map parameters = url.getParameters();
109:
110:                assertNotNull(parameters);
111:                assertEquals(parameters.size(), 7);
112:                assertEquals(parameters.get("id1"), "paramId1");
113:                assertEquals(parameters.get("id2"), "tagId2");
114:                assertEquals(parameters.get("urlParam1"), "urlValue1");
115:                assertEquals(parameters.get("urlParam2"), "urlValue2");
116:                assertEquals(parameters.get("tagId"), "tagValue");
117:                assertEquals(parameters.get("param1"), "param1value");
118:                assertEquals(parameters.get("param2"), "param2value");
119:            }
120:
121:            /**
122:             * To test priority of parameter passed in to url component though 
123:             * various way, with includeParams="NONE"
124:             *  - current request url
125:             *  - tag's value attribute
126:             *  - tag's nested param tag
127:             *  
128:             *  In this case only parameters from the tag itself is taken into account.
129:             *  Those from request will not count, only those in tag's value attribute 
130:             *  and nested param tag.
131:             *  
132:             * @throws Exception
133:             */
134:            public void testParametersPriorityWithIncludeParamsAsNONE()
135:                    throws Exception {
136:                request
137:                        .setQueryString("id1=urlId1&id2=urlId2&urlParam1=urlValue1&urlParam2=urlValue2");
138:
139:                tag
140:                        .setValue("testAction.action?id1=tagId1&id2=tagId2&tagId=tagValue");
141:                tag.setIncludeParams("NONE");
142:
143:                ParamTag param1 = new ParamTag();
144:                param1.setPageContext(pageContext);
145:                param1.setName("param1");
146:                param1.setValue("%{'param1value'}");
147:
148:                ParamTag param2 = new ParamTag();
149:                param2.setPageContext(pageContext);
150:                param2.setName("param2");
151:                param2.setValue("%{'param2value'}");
152:
153:                ParamTag param3 = new ParamTag();
154:                param3.setPageContext(pageContext);
155:                param3.setName("id1");
156:                param3.setValue("%{'paramId1'}");
157:
158:                tag.doStartTag();
159:                param1.doStartTag();
160:                param1.doEndTag();
161:                param2.doStartTag();
162:                param2.doEndTag();
163:                param3.doStartTag();
164:                param3.doEndTag();
165:
166:                URL url = (URL) tag.getComponent();
167:                Map parameters = url.getParameters();
168:
169:                assertEquals(parameters.size(), 5);
170:                assertEquals(parameters.get("id1"), "paramId1");
171:                assertEquals(parameters.get("id2"), "tagId2");
172:                assertEquals(parameters.get("tagId"), "tagValue");
173:                assertEquals(parameters.get("param1"), "param1value");
174:                assertEquals(parameters.get("param2"), "param2value");
175:            }
176:
177:            public void testIncludeParamsDefaultToGET() throws Exception {
178:                request.setQueryString("one=oneVal&two=twoVal&three=threeVal");
179:
180:                // request parameter map should not have any effect, as includeParams
181:                // default to GET, which get its param from request.getQueryString()
182:                Map tmp = new HashMap();
183:                tmp.put("one", "aaa");
184:                tmp.put("two", "bbb");
185:                tmp.put("three", "ccc");
186:                request.setParameterMap(tmp);
187:
188:                tag.setValue("TestAction.acton");
189:
190:                tag.doStartTag();
191:
192:                URL url = (URL) tag.getComponent();
193:                Map parameters = url.getParameters();
194:
195:                tag.doEndTag();
196:
197:                assertEquals(parameters.get("one"), "oneVal");
198:                assertEquals(parameters.get("two"), "twoVal");
199:                assertEquals(parameters.get("three"), "threeVal");
200:            }
201:
202:            public void testActionURL() throws Exception {
203:                tag.setValue("TestAction.action");
204:
205:                tag.doStartTag();
206:                tag.doEndTag();
207:                assertEquals("TestAction.action", writer.toString());
208:            }
209:
210:            public void testAddParameters() throws Exception {
211:                request.setAttribute("webwork.request_uri", "/Test.action");
212:
213:                request.setAttribute("webwork.request_uri",
214:                        "/TestAction.action");
215:                request.setQueryString("param0=value0");
216:
217:                tag.doStartTag();
218:                tag.component.addParameter("param1", "value1");
219:                tag.component.addParameter("param2", "value2");
220:                tag.doEndTag();
221:                assertEquals(
222:                        "/TestAction.action?param2=value2&param0=value0&param1=value1",
223:                        writer.toString());
224:            }
225:
226:            public void testEvaluateValue() throws Exception {
227:                Foo foo = new Foo();
228:                foo.setTitle("test");
229:                stack.push(foo);
230:                tag.setValue("%{title}");
231:
232:                tag.doStartTag();
233:                tag.doEndTag();
234:                assertEquals("test", writer.toString());
235:            }
236:
237:            public void testHttps() throws Exception {
238:                request.setScheme("https");
239:                request.setServerName("localhost");
240:                request.setServerPort(443);
241:
242:                tag.setValue("list-members.action");
243:
244:                tag.doStartTag();
245:                tag.doEndTag();
246:                assertEquals("list-members.action", writer.toString());
247:            }
248:
249:            public void testAnchor() throws Exception {
250:                request.setScheme("https");
251:                request.setServerName("localhost");
252:                request.setServerPort(443);
253:
254:                tag.setValue("list-members.action");
255:                tag.setAnchor("test");
256:
257:                tag.doStartTag();
258:                tag.doEndTag();
259:                assertEquals("list-members.action#test", writer.toString());
260:            }
261:
262:            public void testParamPrecedence() throws Exception {
263:                request.setRequestURI("/context/someAction.action");
264:                request.setQueryString("id=22&name=John");
265:
266:                URLTag urlTag = new URLTag();
267:                urlTag.setPageContext(pageContext);
268:                urlTag.setIncludeParams("get");
269:                urlTag.setEncode("%{false}");
270:
271:                ParamTag paramTag = new ParamTag();
272:                paramTag.setPageContext(pageContext);
273:                paramTag.setName("id");
274:                paramTag.setValue("%{'33'}");
275:
276:                urlTag.doStartTag();
277:                paramTag.doStartTag();
278:                paramTag.doEndTag();
279:                urlTag.doEndTag();
280:
281:                assertEquals(writer.getBuffer().toString(),
282:                        "/context/someAction.action?name=John&id=33");
283:            }
284:
285:            public void testParamPrecedenceWithAnchor() throws Exception {
286:                request.setRequestURI("/context/someAction.action");
287:                request.setQueryString("id=22&name=John");
288:
289:                URLTag urlTag = new URLTag();
290:                urlTag.setPageContext(pageContext);
291:                urlTag.setIncludeParams("get");
292:                urlTag.setEncode("%{false}");
293:                urlTag.setAnchor("testAnchor");
294:
295:                ParamTag paramTag = new ParamTag();
296:                paramTag.setPageContext(pageContext);
297:                paramTag.setName("id");
298:                paramTag.setValue("%{'33'}");
299:
300:                urlTag.doStartTag();
301:                paramTag.doStartTag();
302:                paramTag.doEndTag();
303:                urlTag.doEndTag();
304:
305:                assertEquals(writer.getBuffer().toString(),
306:                        "/context/someAction.action?name=John&id=33#testAnchor");
307:            }
308:
309:            public void testPutId() throws Exception {
310:                tag.setValue("/public/about");
311:                assertEquals(null, stack.findString("myId")); // nothing in stack
312:                tag.setId("myId");
313:                tag.doStartTag();
314:                tag.doEndTag();
315:                assertEquals("", writer.toString());
316:                assertEquals("/public/about", stack.findString("myId")); // is in stack now
317:            }
318:
319:            public void testUsingValueOnly() throws Exception {
320:                tag.setValue("/public/about/team.jsp");
321:                tag.doStartTag();
322:                tag.doEndTag();
323:                assertEquals("/public/about/team.jsp", writer.toString());
324:            }
325:
326:            public void testRequestURIActionIncludeNone() throws Exception {
327:                request.setRequestURI("/public/about");
328:                request.setQueryString("section=team&company=acme inc");
329:
330:                tag.setAction("team");
331:                tag.setIncludeParams("none");
332:                tag.doStartTag();
333:                tag.doEndTag();
334:
335:                assertEquals("/team.action", writer.toString());
336:            }
337:
338:            public void testRequestURIActionIncludeGet() throws Exception {
339:                request.setRequestURI("/public/about");
340:                request.setQueryString("section=team&company=acme inc");
341:
342:                tag.setAction("team");
343:                tag.setIncludeParams("get");
344:                tag.doStartTag();
345:                tag.doEndTag();
346:
347:                assertEquals("/team.action?section=team&company=acme+inc",
348:                        writer.toString());
349:            }
350:
351:            public void testRequestURINoActionIncludeNone() throws Exception {
352:                request.setRequestURI("/public/about");
353:                request.setQueryString("section=team&company=acme inc");
354:
355:                tag.setAction(null);
356:                tag.setIncludeParams("none");
357:                tag.doStartTag();
358:                tag.doEndTag();
359:
360:                assertEquals("/public/about", writer.toString());
361:            }
362:
363:            public void testNoActionIncludeGet() throws Exception {
364:                request.setRequestURI("/public/about");
365:                request.setQueryString("section=team&company=acme inc");
366:
367:                tag.setAction(null);
368:                tag.setIncludeParams("get");
369:                tag.doStartTag();
370:                tag.doEndTag();
371:
372:                assertEquals("/public/about?section=team&company=acme+inc",
373:                        writer.toString());
374:            }
375:
376:            public void testRequestURIActionIncludeAll() throws Exception {
377:                request.setRequestURI("/public/about");
378:                request.setQueryString("section=team&company=acme inc");
379:
380:                tag.setAction("team");
381:                tag.setIncludeParams("all");
382:
383:                tag.doStartTag();
384:
385:                // include nested param tag
386:                ParamTag paramTag = new ParamTag();
387:                paramTag.setPageContext(pageContext);
388:                paramTag.setName("year");
389:                paramTag.setValue("2006");
390:                paramTag.doStartTag();
391:                paramTag.doEndTag();
392:
393:                tag.doEndTag();
394:
395:                assertEquals(
396:                        "/team.action?section=team&year=2006&company=acme+inc",
397:                        writer.toString());
398:            }
399:
400:            public void testRequestURINoActionIncludeAll() throws Exception {
401:                request.setRequestURI("/public/about");
402:                request.setQueryString("section=team&company=acme inc");
403:
404:                tag.setAction(null);
405:                tag.setIncludeParams("all");
406:
407:                tag.doStartTag();
408:
409:                // include nested param tag
410:                ParamTag paramTag = new ParamTag();
411:                paramTag.setPageContext(pageContext);
412:                paramTag.setName("year");
413:                paramTag.setValue("2006");
414:                paramTag.doStartTag();
415:                paramTag.doEndTag();
416:
417:                tag.doEndTag();
418:
419:                assertEquals(
420:                        "/public/about?section=team&year=2006&company=acme+inc",
421:                        writer.toString());
422:            }
423:
424:            public void testUnknownIncludeParam() throws Exception {
425:                request.setRequestURI("/public/about");
426:                request.setQueryString("section=team");
427:
428:                tag.setIncludeParams("unknown"); // will log at WARN level
429:                tag.doStartTag();
430:                tag.doEndTag();
431:                assertEquals("/public/about", writer.toString()); // should not add any request parameters
432:            }
433:
434:            public void testRequestURIWithAnchor() throws Exception {
435:                request.setRequestURI("/public/about");
436:                request.setQueryString("company=acme inc#canada");
437:
438:                tag.setAction("company");
439:                tag.setIncludeParams("get");
440:                tag.doStartTag();
441:                tag.doEndTag();
442:
443:                assertEquals("/company.action?company=acme+inc", writer
444:                        .toString()); // will always chop anchor if using requestURI
445:            }
446:
447:            public void testIncludeContext() throws Exception {
448:                request.setupGetContext("/myapp");
449:
450:                tag.setIncludeContext("true");
451:                tag.setAction("company");
452:                tag.doStartTag();
453:                tag.doEndTag();
454:
455:                assertEquals("/myapp/company.action", writer.toString());
456:            }
457:
458:            protected void setUp() throws Exception {
459:                super .setUp();
460:
461:                request.setScheme("http");
462:                request.setServerName("localhost");
463:                request.setServerPort(80);
464:
465:                tag = new URLTag();
466:                tag.setPageContext(pageContext);
467:                JspWriter jspWriter = new WebWorkMockJspWriter(writer);
468:                pageContext.setJspWriter(jspWriter);
469:            }
470:
471:            public class Foo {
472:                private String title;
473:
474:                public void setTitle(String title) {
475:                    this .title = title;
476:                }
477:
478:                public String getTitle() {
479:                    return title;
480:                }
481:
482:                public String toString() {
483:                    return "Foo is: " + title;
484:                }
485:            }
486:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.