KickJava   Java API By Example, From Geeks To Geeks.

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


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

34 public class TestGreaterThanTag 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 = "6";
40     protected final static String JavaDoc LESSER_VAL = "4";
41
42
43     /**
44      * Defines the testcase name for JUnit.
45      *
46      * @param theName the testcase's name.
47      */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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