KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > sysclient > ContextTestCase


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.struts.faces.sysclient;
18
19 import junit.framework.Test;
20 import junit.framework.TestSuite;
21
22 import com.gargoylesoftware.htmlunit.html.HtmlSpan;
23 import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
24
25
26 /**
27  * <p>Test case for verifying <code>FacesContext</code> information against
28  * what is visible in the Struts <code>Action</code> method that is invoked.</p>
29  *
30  * @version $Rev: 155885 $ $Date: 2005-03-02 06:04:30 +0000 (Wed, 02 Mar 2005) $
31  */

32
33 public class ContextTestCase extends AbstractTestCase {
34
35
36     // ------------------------------------------------------------ Constructors
37

38
39     /**
40      * <p>Construct a new instance of this test case.</p>
41      *
42      * @param name Name of the new test case
43      */

44     public ContextTestCase(String JavaDoc name) {
45
46         super(name);
47
48     }
49
50
51     // ------------------------------------------------------ Instance Variables
52

53
54     // ------------------------------------------------------ Test Setup Methods
55

56
57     /**
58      * <p>Set up the instance variables required for this test case.</p>
59      */

60     public void setUp() throws Exception JavaDoc {
61
62         super.setUp();
63         page("/context.faces");
64
65     }
66
67
68     /**
69      * <p>Return the set of tests included in this test suite.</p>
70      */

71     public static Test suite() {
72
73         return (new TestSuite(ContextTestCase.class));
74
75     }
76
77
78     /**
79      * <p>Tear down instance variables required by this test case.</p>
80      */

81     public void tearDown() {
82
83         super.tearDown();
84
85     }
86
87
88
89     // ------------------------------------------------- Individual Test Methods
90

91
92     /**
93      * <p>Verify the content of a pristine page returned when executing this
94      * view for the first time.</p>
95      */

96     public void testPristine() throws Exception JavaDoc {
97
98         HtmlSpan span = null;
99         assertEquals("context", title());
100
101         // Validate FacesContext Values
102

103         span = (HtmlSpan) element("form:renderKitIdFC");
104         assertEquals("HTML_BASIC", span.asText());
105
106         span = (HtmlSpan) element("form:viewIdFC");
107         assertEquals("/context.jsp", span.asText());
108
109         // Validate ExternalContext Values
110

111         span = (HtmlSpan) element("form:authTypeEC");
112         assertEquals("", span.asText());
113
114         span = (HtmlSpan) element("form:remoteUserEC");
115         assertEquals("", span.asText());
116
117         span = (HtmlSpan) element("form:requestContextPathEC");
118         assertEquals("/struts-faces-systest1", span.asText()); // FIXME - Ant property?
119

120
121         span = (HtmlSpan) element("form:requestLocaleEC");
122         String JavaDoc formRequestLocaleEC = span.asText(); // FIXME - validate this
123

124         span = (HtmlSpan) element("form:requestPathInfoEC");
125         assertEquals("", span.asText());
126
127         span = (HtmlSpan) element("form:requestServletPathEC");
128         assertEquals("/context.jsp", span.asText());
129
130         // Validate HttpServletRequest Values
131

132         span = (HtmlSpan) element("form:authTypeRQ");
133         assertEquals("", span.asText());
134
135         span = (HtmlSpan) element("form:contextPathRQ");
136         assertEquals("/struts-faces-systest1", span.asText()); // FIXME - Ant property?
137

138         span = (HtmlSpan) element("form:localeRQ");
139         assertEquals(formRequestLocaleEC, span.asText());
140
141         span = (HtmlSpan) element("form:pathInfoRQ");
142         assertEquals("", span.asText());
143
144         span = (HtmlSpan) element("form:remoteUserRQ");
145         assertEquals("", span.asText());
146
147         span = (HtmlSpan) element("form:servletPathRQ");
148         assertEquals("/context.jsp", span.asText());
149
150         // Validate ServletContext Values
151

152         span = (HtmlSpan) element("form:majorVersionSC");
153         assertEquals("2", span.asText());
154
155         span = (HtmlSpan) element("form:minorVersionSC");
156         assertTrue("3".equals(span.asText()) || "4".equals(span.asText()));
157
158     }
159
160
161     /**
162      * <p>Submit the initial form and validate the resulting values.</p>
163      */

164     public void testSubmit() throws Exception JavaDoc {
165
166         HtmlSpan span = null;
167         HtmlSpan spanCA = null;
168         HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit");
169         submit(submit);
170         assertEquals("context1", title());
171
172         // Validate FacesContext Values
173

174         span = (HtmlSpan) element("form:renderKitIdFC");
175         assertEquals("HTML_BASIC", span.asText());
176
177         span = (HtmlSpan) element("form:viewIdFC");
178         assertEquals("/context1.jsp", span.asText());
179
180         // Validate ExternalContext Values
181

182         span = (HtmlSpan) element("form:authTypeEC");
183         assertEquals("", span.asText());
184
185         span = (HtmlSpan) element("form:remoteUserEC");
186         assertEquals("", span.asText());
187
188         span = (HtmlSpan) element("form:requestContextPathEC");
189         assertEquals("/struts-faces-systest1", span.asText()); // FIXME - Ant property?
190

191         span = (HtmlSpan) element("form:requestLocaleEC");
192         String JavaDoc formRequestLocaleEC = span.asText(); // FIXME - validate this
193

194         span = (HtmlSpan) element("form:requestPathInfoEC");
195         assertEquals("", span.asText());
196
197         span = (HtmlSpan) element("form:requestServletPathEC");
198         assertEquals("/context1.jsp", span.asText());
199
200         // Validate HttpServletRequest Values
201

202         span = (HtmlSpan) element("form:authTypeRQ");
203         assertEquals("", span.asText());
204
205         span = (HtmlSpan) element("form:contextPathRQ");
206         assertEquals("/struts-faces-systest1", span.asText()); // FIXME - Ant property?
207
spanCA = (HtmlSpan) element("form:contextPathCA");
208         assertEquals(span.asText(), spanCA.asText());
209
210         span = (HtmlSpan) element("form:localeRQ");
211         assertEquals(formRequestLocaleEC, span.asText());
212         spanCA = (HtmlSpan) element("form:localeCA");
213         assertEquals(span.asText(), spanCA.asText());
214
215         span = (HtmlSpan) element("form:pathInfoRQ");
216         assertEquals("", span.asText());
217         spanCA = (HtmlSpan) element("form:pathInfoCA");
218         assertEquals(span.asText(), spanCA.asText());
219
220         span = (HtmlSpan) element("form:remoteUserRQ");
221         assertEquals("", span.asText());
222         spanCA = (HtmlSpan) element("form:remoteUserCA");
223         assertEquals(span.asText(), spanCA.asText());
224
225         span = (HtmlSpan) element("form:servletPathRQ");
226         assertEquals("/context1.jsp", span.asText());
227         spanCA = (HtmlSpan) element("form:servletPathCA");
228         assertEquals("/context.faces", spanCA.asText());
229
230         // Validate ServletContext Values
231

232         span = (HtmlSpan) element("form:majorVersionSC");
233         assertEquals("2", span.asText());
234
235         span = (HtmlSpan) element("form:minorVersionSC");
236         assertTrue("3".equals(span.asText()) || "4".equals(span.asText()));
237
238     }
239
240
241 }
242
Popular Tags