KickJava   Java API By Example, From Geeks To Geeks.

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


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

5 package com.opensymphony.webwork.views.jsp;
6
7 import com.mockobjects.servlet.MockHttpServletRequest;
8 import com.mockobjects.servlet.MockJspWriter;
9 import com.mockobjects.servlet.MockPageContext;
10 import com.opensymphony.xwork.ActionContext;
11 import com.opensymphony.xwork.util.OgnlValueStack;
12 import junit.framework.TestCase;
13
14 import javax.servlet.jsp.JspException JavaDoc;
15
16
17 /**
18  * @author $Author: jcarreira $
19  * @version $Revision: 1.7 $
20  */

21 public class PropertyTagTest extends TestCase {
22     //~ Instance fields ////////////////////////////////////////////////////////
23

24     MockHttpServletRequest request = new MockHttpServletRequest();
25     OgnlValueStack stack = new OgnlValueStack();
26
27     //~ Methods ////////////////////////////////////////////////////////////////
28

29     public void testDefaultValue() {
30         PropertyTag tag = new PropertyTag();
31
32         Foo foo = new Foo();
33
34         stack.push(foo);
35
36         MockJspWriter jspWriter = new MockJspWriter();
37         jspWriter.setExpectedData("TEST");
38
39         MockPageContext pageContext = new MockPageContext();
40         pageContext.setJspWriter(jspWriter);
41         pageContext.setRequest(request);
42
43         tag.setPageContext(pageContext);
44         tag.setValue("title");
45         tag.setDefault("TEST");
46
47         try {
48             tag.doStartTag();
49         } catch (JspException JavaDoc e) {
50             e.printStackTrace();
51             fail();
52         }
53
54         request.verify();
55         jspWriter.verify();
56         pageContext.verify();
57     }
58
59     public void testNull() {
60         PropertyTag tag = new PropertyTag();
61
62         Foo foo = new Foo();
63
64         stack.push(foo);
65
66         MockJspWriter jspWriter = new MockJspWriter();
67         jspWriter.setExpectedData("");
68
69         MockPageContext pageContext = new MockPageContext();
70         pageContext.setJspWriter(jspWriter);
71         pageContext.setRequest(request);
72
73         tag.setPageContext(pageContext);
74         tag.setValue("title");
75
76         try {
77             tag.doStartTag();
78         } catch (JspException JavaDoc e) {
79             e.printStackTrace();
80             fail();
81         }
82
83         request.verify();
84         jspWriter.verify();
85         pageContext.verify();
86     }
87
88     public void testSimple() {
89         PropertyTag tag = new PropertyTag();
90
91         Foo foo = new Foo();
92         foo.setTitle("test");
93
94         stack.push(foo);
95
96         MockJspWriter jspWriter = new MockJspWriter();
97         jspWriter.setExpectedData("test");
98
99         MockPageContext pageContext = new MockPageContext();
100         pageContext.setJspWriter(jspWriter);
101         pageContext.setRequest(request);
102
103         tag.setPageContext(pageContext);
104         tag.setValue("title");
105
106         try {
107             tag.doStartTag();
108         } catch (JspException JavaDoc e) {
109             e.printStackTrace();
110             fail();
111         }
112
113         request.verify();
114         jspWriter.verify();
115         pageContext.verify();
116     }
117
118     public void testTopOfStack() {
119         PropertyTag tag = new PropertyTag();
120
121         Foo foo = new Foo();
122         foo.setTitle("test");
123
124         stack.push(foo);
125
126         MockJspWriter jspWriter = new MockJspWriter();
127         jspWriter.setExpectedData("Foo is: test");
128
129         MockPageContext pageContext = new MockPageContext();
130         pageContext.setJspWriter(jspWriter);
131         pageContext.setRequest(request);
132
133         tag.setPageContext(pageContext);
134
135         try {
136             tag.doStartTag();
137         } catch (JspException JavaDoc e) {
138             e.printStackTrace();
139             fail();
140         }
141
142         request.verify();
143         jspWriter.verify();
144         pageContext.verify();
145     }
146
147     protected void setUp() throws Exception JavaDoc {
148         ActionContext.getContext().setValueStack(stack);
149         request.setupGetAttribute(stack);
150     }
151
152     //~ Inner Classes //////////////////////////////////////////////////////////
153

154     public class Foo {
155         private String JavaDoc title;
156
157         public void setTitle(String JavaDoc title) {
158             this.title = title;
159         }
160
161         public String JavaDoc getTitle() {
162             return title;
163         }
164
165         public String JavaDoc toString() {
166             return "Foo is: " + title;
167         }
168     }
169 }
170
Popular Tags