KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > logic > TestGreaterEqualTag


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

18 package org.apache.struts.taglib.logic;
19
20 import javax.servlet.ServletException JavaDoc;
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.PageContext JavaDoc;
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25 import org.apache.cactus.JspTestCase;
26 import org.apache.cactus.WebRequest;
27 import org.apache.struts.util.LabelValueBean;
28
29 /**
30  * Suite of unit tests for the
31  * <code>org.apache.struts.taglib.logic.GreaterEqualTag</code> class.
32  *
33  */

34 public class TestGreaterEqualTag extends JspTestCase {
35     
36     protected final static String JavaDoc COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY";
37     protected final static String JavaDoc HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY";
38     protected final static String JavaDoc PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY";
39     protected final static String JavaDoc GREATER_VAL = "5";
40     protected final static String JavaDoc LESSER_VAL = "5";
41
42
43     /**
44      * Defines the testcase name for JUnit.
45      *
46      * @param theName the testcase's name.
47      */

48     public TestGreaterEqualTag(String JavaDoc theName) {
49         super(theName);
50     }
51
52     /**
53      * Start the tests.
54      *
55      * @param theArgs the arguments. Not used
56      */

57     public static void main(String JavaDoc[] theArgs) {
58         junit.awtui.TestRunner.main(new String JavaDoc[] {TestGreaterEqualTag.class.getName()});
59     }
60
61     /**
62      * @return a test suite (<code>TestSuite</code>) that includes all methods
63      * starting with "test"
64      */

65     public static Test suite() {
66         // All methods starting with "test" will be executed in the test suite.
67
return new TestSuite(TestGreaterEqualTag.class);
68     }
69
70     //----- Test initApplication() method --------------------------------------
71

72     /**
73      * Create cookie for testCookiePresent method test.
74     */

75     /* FIXME: Cactus does not send cookies?
76     public void beginCookieGreaterEqual(WebRequest testRequest) {
77        testRequest.addCookie(COOKIE_KEY, GREATER_VAL);
78     }
79     */

80
81     /**
82      * Create header for testHeaderGreaterEqual method test.
83     */

84     public void beginHeaderGreaterEqual(WebRequest testRequest) {
85        testRequest.addHeader(HEADER_KEY, GREATER_VAL);
86     }
87
88     /**
89      * Create header for testParameterGreaterEqual method test.
90     */

91     public void beginParameterGreaterEqual(WebRequest testRequest) {
92        testRequest.addParameter(PARAMETER_KEY, GREATER_VAL);
93     }
94
95     /**
96      * Verify the value stored in a cookie using <code>GreaterEqualTag</code>.
97     */

98     /* FIXME: Cactus does not send cookies?
99     public void testCookieGreaterEqual() throws ServletException, JspException {
100         GreaterEqualTag ge = new GreaterEqualTag();
101         ge.setPageContext(pageContext);
102         ge.setCookie(COOKIE_KEY);
103         ge.setValue(LESSER_VAL);
104
105         assertTrue(
106             "Cookie Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
107             ge.condition());
108     }
109     */

110     
111     /**
112      * Verify the value stored in header using <code>GreaterEqualTag</code>.
113     */

114     public void testHeaderGreaterEqual() throws ServletException JavaDoc, JspException JavaDoc {
115         GreaterEqualTag ge = new GreaterEqualTag();
116         ge.setPageContext(pageContext);
117         ge.setHeader(HEADER_KEY);
118         ge.setValue(LESSER_VAL);
119
120         assertTrue(
121             "Header Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
122             ge.condition());
123     }
124
125     /**
126      * Verify the value stored in parameter using <code>GreaterEqualTag</code>.
127     */

128     public void testParameterGreaterEqual() throws ServletException JavaDoc, JspException JavaDoc {
129         GreaterEqualTag ge = new GreaterEqualTag();
130         ge.setPageContext(pageContext);
131         ge.setParameter(PARAMETER_KEY);
132         ge.setValue(LESSER_VAL);
133
134         assertTrue(
135             "Parameter Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
136             ge.condition());
137     }
138     
139
140     /**
141      * Testing <code>GreaterEqualTag</code> using name attribute in
142      * the application scope.
143     */

144     public void testApplicationScopeNameGreaterEqual()
145         throws ServletException JavaDoc, JspException JavaDoc {
146     
147         GreaterEqualTag ge = new GreaterEqualTag();
148
149         String JavaDoc testKey = "testApplicationScopeNameGreaterEqual";
150         Integer JavaDoc itgr = new Integer JavaDoc(GREATER_VAL);
151         
152         pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE);
153         ge.setPageContext(pageContext);
154         ge.setName(testKey);
155         ge.setScope("application");
156         ge.setValue(LESSER_VAL);
157
158         assertTrue(
159             "Application scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
160             ge.condition());
161     }
162
163     /**
164      * Testing <code>GreaterEqualTag</code> using name attribute in
165      * the session scope.
166     */

167     public void testSessionScopeNameGreaterEqual()
168         throws ServletException JavaDoc, JspException JavaDoc {
169     
170         GreaterEqualTag ge = new GreaterEqualTag();
171
172         String JavaDoc testKey = "testSessionScopeNameGreaterEqual";
173         Integer JavaDoc itgr = new Integer JavaDoc(GREATER_VAL);
174         
175         pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE);
176         ge.setPageContext(pageContext);
177         ge.setName(testKey);
178         ge.setScope("session");
179         ge.setValue(LESSER_VAL);
180
181         assertTrue(
182             "Session scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
183             ge.condition());
184     }
185
186     /**
187      * Testing <code>GreaterEqualTag</code> using name attribute in
188      * the request scope.
189     */

190     public void testRequestScopeNameGreaterEqual()
191         throws ServletException JavaDoc, JspException JavaDoc {
192     
193         GreaterEqualTag ge = new GreaterEqualTag();
194
195         String JavaDoc testKey = "testRequestScopeNameGreaterEqual";
196         Integer JavaDoc itgr = new Integer JavaDoc(GREATER_VAL);
197         
198         pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE);
199         ge.setPageContext(pageContext);
200         ge.setName(testKey);
201         ge.setScope("request");
202         ge.setValue(LESSER_VAL);
203
204         assertTrue(
205             "Request scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")",
206             ge.condition());
207     }
208
209
210
211
212     /**
213      * Testing <code>GreaterEqualTag</code> using name and property attribute in
214      * the application scope.
215     */

216     public void testApplicationScopePropertyGreaterEqual()
217         throws ServletException JavaDoc, JspException JavaDoc {
218     
219         GreaterEqualTag ge = new GreaterEqualTag();
220
221         String JavaDoc testKey = "testApplicationScopePropertyGreaterEqual";
222         LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
223         
224         pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE);
225         ge.setPageContext(pageContext);
226         ge.setName(testKey);
227         ge.setScope("application");
228         ge.setProperty("value");
229         ge.setValue(LESSER_VAL);
230
231         assertTrue(
232             "Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
233             ge.condition());
234     }
235
236     /**
237      * Testing <code>GreaterEqualTag</code> using name and property attribute in
238      * the session scope.
239     */

240     public void testSessionScopePropertyGreaterEqual()
241         throws ServletException JavaDoc, JspException JavaDoc {
242     
243         GreaterEqualTag ge = new GreaterEqualTag();
244
245         String JavaDoc testKey = "testSessionScopePropertyGreaterEqual";
246         LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
247         
248         pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE);
249         ge.setPageContext(pageContext);
250         ge.setName(testKey);
251         ge.setScope("session");
252         ge.setProperty("value");
253         ge.setValue(LESSER_VAL);
254
255         assertTrue(
256             "Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
257             ge.condition());
258     }
259     
260     /**
261      * Testing <code>GreaterEqualTag</code> using name and property attribute in
262      * the request scope.
263     */

264     public void testRequestScopePropertyGreaterEqual()
265         throws ServletException JavaDoc, JspException JavaDoc {
266     
267         GreaterEqualTag ge = new GreaterEqualTag();
268
269         String JavaDoc testKey = "testRequestScopePropertyGreaterEqual";
270         LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
271         
272         pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE);
273         ge.setPageContext(pageContext);
274         ge.setName(testKey);
275         ge.setScope("request");
276         ge.setProperty("value");
277         ge.setValue(LESSER_VAL);
278
279         assertTrue(
280             "Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
281             ge.condition());
282     }
283     
284     
285     
286 }
287
Popular Tags