KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestLessEqualTag.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.LessEqualTag</code> class.
32  *
33  */

34 public class TestLessEqualTag 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 TestLessEqualTag(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[] {TestLessEqualTag.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(TestLessEqualTag.class);
68     }
69
70     //----- Test initApplication() method --------------------------------------
71

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

75     public void beginCookieLessEqual(WebRequest testRequest) {
76        testRequest.addCookie(COOKIE_KEY, GREATER_VAL);
77     }
78
79     /**
80      * Create header for testHeaderLessEqual method test.
81     */

82     public void beginHeaderLessEqual(WebRequest testRequest) {
83        testRequest.addHeader(HEADER_KEY, GREATER_VAL);
84     }
85
86     /**
87      * Create header for testParameterLessEqual method test.
88     */

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

96     public void testCookieLessEqual() throws ServletException JavaDoc, JspException JavaDoc {
97         LessEqualTag ge = new LessEqualTag();
98         ge.setPageContext(pageContext);
99         ge.setCookie(COOKIE_KEY);
100         ge.setValue(LESSER_VAL);
101
102         assertTrue(
103             "Cookie Value (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")",
104             ge.condition());
105     }
106     
107     /**
108      * Verify the value stored in header using <code>LessEqualTag</code>.
109     */

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

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

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

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

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

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

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

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