KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > URLTagTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.jsp;
6
7 import javax.servlet.jsp.JspException JavaDoc;
8 import javax.servlet.jsp.JspWriter JavaDoc;
9 import java.io.StringWriter JavaDoc;
10
11
12 /**
13  * DOCUMENT ME!
14  *
15  * @author Brock Bulger (brockman_bulger@hotmail.com)
16  * @version $Revision: 1.15 $
17  */

18 public class URLTagTest extends AbstractUITagTest {
19     private StringWriter JavaDoc writer = new StringWriter JavaDoc();
20     private URLTag tag;
21
22     public void testActionURL() {
23         tag.setValue("TestAction.action");
24
25         try {
26             tag.doStartTag();
27             tag.doEndTag();
28             assertEquals("TestAction.action", writer.toString());
29         } catch (JspException JavaDoc ex) {
30             ex.printStackTrace();
31             fail();
32         }
33     }
34
35     public void testAddParameters() {
36         request.setAttribute("webwork.request_uri", "/Test.action");
37
38         request.setAttribute("webwork.request_uri", "/TestAction.action");
39         request.setQueryString("param0=value0");
40
41         try {
42             tag.doStartTag();
43             tag.addParameter("param1", "value1");
44             tag.addParameter("param2", "value2");
45             tag.doEndTag();
46             assertEquals("/TestAction.action?param2=value2&param0=value0&param1=value1", writer.toString());
47         } catch (JspException JavaDoc ex) {
48             ex.printStackTrace();
49             fail();
50         }
51     }
52
53     public void testEvaluateValue() {
54         Foo foo = new Foo();
55         foo.setTitle("test");
56         stack.push(foo);
57         tag.setValue("%{title}");
58
59         try {
60             tag.doStartTag();
61             tag.doEndTag();
62             assertEquals("test", writer.toString());
63         } catch (JspException JavaDoc ex) {
64             ex.printStackTrace();
65             fail();
66         }
67     }
68
69     public void testHttps() {
70         request.setScheme("https");
71         request.setServerName("localhost");
72         request.setServerPort(443);
73
74         tag.setValue("list-members.action");
75
76         try {
77             tag.doStartTag();
78             tag.doEndTag();
79             assertEquals("list-members.action", writer.toString());
80         } catch (JspException JavaDoc ex) {
81             ex.printStackTrace();
82             fail();
83         }
84     }
85
86     protected void setUp() throws Exception JavaDoc {
87         super.setUp();
88
89         request.setScheme("http");
90         request.setServerName("localhost");
91         request.setServerPort(80);
92
93         tag = new URLTag();
94         tag.setPageContext(pageContext);
95         JspWriter JavaDoc jspWriter = new WebWorkMockJspWriter(writer);
96         pageContext.setJspWriter(jspWriter);
97     }
98
99     public class Foo {
100         private String JavaDoc title;
101
102         public void setTitle(String JavaDoc title) {
103             this.title = title;
104         }
105
106         public String JavaDoc getTitle() {
107             return title;
108         }
109
110         public String JavaDoc toString() {
111             return "Foo is: " + title;
112         }
113     }
114 }
115
Popular Tags