2
* $Header: /home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/logic/TestGreaterEqualTag.java,v 1.7 2004/07/06 06:38:52 craigmcc Exp $
4
* $Date: 2004/07/06 06:38:52 $
6
* Copyright 1999-2004 The Apache Software Foundation.
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
20
package org.apache.struts.taglib.logic;
22
import javax.servlet.ServletException;
23
import javax.servlet.jsp.JspException;
24
import javax.servlet.jsp.PageContext;
25
import junit.framework.Test;
26
import junit.framework.TestSuite;
27
import org.apache.cactus.JspTestCase;
28
import org.apache.cactus.WebRequest;
29
import org.apache.struts.util.LabelValueBean;
32
* Suite of unit tests for the
33
* <code>org.apache.struts.taglib.logic.GreaterEqualTag</code> class.
36
public class TestGreaterEqualTag extends JspTestCase {
38
protected final static String COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY";
39
protected final static String HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY";
40
protected final static String PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY";
41
protected final static String GREATER_VAL = "5";
42
protected final static String LESSER_VAL = "5";
46
* Defines the testcase name for JUnit.
48
* @param theName the testcase's name.
50
public TestGreaterEqualTag(String theName) {
57
* @param theArgs the arguments. Not used
59
public static void main(String[] theArgs) {
60
junit.awtui.TestRunner.main(new String[] {TestGreaterEqualTag.class.getName()});
64
* @return a test suite (<code>TestSuite</code>) that includes all methods
65
* starting with "test"
67
public static Test suite() {
68
// All methods starting with "test" will be executed in the test suite.
69
return new TestSuite(TestGreaterEqualTag.class);
72
//----- Test initApplication() method --------------------------------------
75
* Create cookie for testCookiePresent method test.
77
/* FIXME: Cactus does not send cookies?
78
public void beginCookieGreaterEqual(WebRequest testRequest) {
79
testRequest.addCookie(COOKIE_KEY, GREATER_VAL);
84
* Create header for testHeaderGreaterEqual method test.
86
public void beginHeaderGreaterEqual(WebRequest testRequest) {
87
testRequest.addHeader(HEADER_KEY, GREATER_VAL);
91
* Create header for testParameterGreaterEqual method test.
93
public void beginParameterGreaterEqual(WebRequest testRequest) {
94
testRequest.addParameter(PARAMETER_KEY, GREATER_VAL);
98
* Verify the value stored in a cookie using <code>GreaterEqualTag</code>.
100
/* FIXME: Cactus does not send cookies?
101
public void testCookieGreaterEqual() throws ServletException, JspException {
102
GreaterEqualTag ge = new GreaterEqualTag();
103
ge.setPageContext(pageContext);
104
ge.setCookie(COOKIE_KEY);
105
ge.setValue(LESSER_VAL);
108
"Cookie Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
114
* Verify the value stored in header using <code>GreaterEqualTag</code>.
116
public void testHeaderGreaterEqual() throws ServletException, JspException {
117
GreaterEqualTag ge = new GreaterEqualTag();
118
ge.setPageContext(pageContext);
119
ge.setHeader(HEADER_KEY);
120
ge.setValue(LESSER_VAL);
123
"Header Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
128
* Verify the value stored in parameter using <code>GreaterEqualTag</code>.
130
public void testParameterGreaterEqual() throws ServletException, JspException {
131
GreaterEqualTag ge = new GreaterEqualTag();
132
ge.setPageContext(pageContext);
133
ge.setParameter(PARAMETER_KEY);
134
ge.setValue(LESSER_VAL);
137
"Parameter Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
143
* Testing <code>GreaterEqualTag</code> using name attribute in
144
* the application scope.
146
public void testApplicationScopeNameGreaterEqual()
147
throws ServletException, JspException {
149
GreaterEqualTag ge = new GreaterEqualTag();
151
String testKey = "testApplicationScopeNameGreaterEqual";
152
Integer itgr = new Integer(GREATER_VAL);
154
pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE);
155
ge.setPageContext(pageContext);
157
ge.setScope("application");
158
ge.setValue(LESSER_VAL);
161
"Application scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
166
* Testing <code>GreaterEqualTag</code> using name attribute in
169
public void testSessionScopeNameGreaterEqual()
170
throws ServletException, JspException {
172
GreaterEqualTag ge = new GreaterEqualTag();
174
String testKey = "testSessionScopeNameGreaterEqual";
175
Integer itgr = new Integer(GREATER_VAL);
177
pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE);
178
ge.setPageContext(pageContext);
180
ge.setScope("session");
181
ge.setValue(LESSER_VAL);
184
"Session scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
189
* Testing <code>GreaterEqualTag</code> using name attribute in
192
public void testRequestScopeNameGreaterEqual()
193
throws ServletException, JspException {
195
GreaterEqualTag ge = new GreaterEqualTag();
197
String testKey = "testRequestScopeNameGreaterEqual";
198
Integer itgr = new Integer(GREATER_VAL);
200
pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE);
201
ge.setPageContext(pageContext);
203
ge.setScope("request");
204
ge.setValue(LESSER_VAL);
207
"Request scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
215
* Testing <code>GreaterEqualTag</code> using name and property attribute in
216
* the application scope.
218
public void testApplicationScopePropertyGreaterEqual()
219
throws ServletException, JspException {
221
GreaterEqualTag ge = new GreaterEqualTag();
223
String testKey = "testApplicationScopePropertyGreaterEqual";
224
LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
226
pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE);
227
ge.setPageContext(pageContext);
229
ge.setScope("application");
230
ge.setProperty("value");
231
ge.setValue(LESSER_VAL);
234
"Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
239
* Testing <code>GreaterEqualTag</code> using name and property attribute in
242
public void testSessionScopePropertyGreaterEqual()
243
throws ServletException, JspException {
245
GreaterEqualTag ge = new GreaterEqualTag();
247
String testKey = "testSessionScopePropertyGreaterEqual";
248
LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
250
pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE);
251
ge.setPageContext(pageContext);
253
ge.setScope("session");
254
ge.setProperty("value");
255
ge.setValue(LESSER_VAL);
258
"Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
263
* Testing <code>GreaterEqualTag</code> using name and property attribute in
266
public void testRequestScopePropertyGreaterEqual()
267
throws ServletException, JspException {
269
GreaterEqualTag ge = new GreaterEqualTag();
271
String testKey = "testRequestScopePropertyGreaterEqual";
272
LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
274
pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE);
275
ge.setPageContext(pageContext);
277
ge.setScope("request");
278
ge.setProperty("value");
279
ge.setValue(LESSER_VAL);
282
"Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",