KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestEqualTag.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.http.Cookie JavaDoc;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25
26 import org.apache.cactus.JspTestCase;
27 import org.apache.cactus.WebRequest;
28
29 /**
30  * Suite of unit tests for the
31  * <code>org.apache.struts.taglib.logic.EqualTag</code> class.
32  *
33  */

34 public class TestEqualTag extends JspTestCase {
35
36     protected final static String JavaDoc COOKIE_KEY =
37         "org.apache.struts.taglib.logic.COOKIE_KEY";
38     protected final static String JavaDoc HEADER_KEY =
39         "org.apache.struts.taglib.logic.HEADER_KEY";
40     protected final static String JavaDoc PARAMETER_KEY =
41         "org.apache.struts.taglib.logic.PARAMETER_KEY";
42
43     protected final static String JavaDoc testStringKey = "testString";
44     protected final static String JavaDoc testStringValue = "abc";
45     protected final static String JavaDoc testStringValue1 = "abcd";
46     protected final static String JavaDoc testIntegerKey = "testInteger";
47     protected final static Integer JavaDoc testIntegerValue = new Integer JavaDoc(21);
48     protected final static Integer JavaDoc testIntegerValue1 =
49         new Integer JavaDoc(testIntegerValue.intValue() + 1);
50
51     protected EqualTag et = null;
52
53     /**
54      * Defines the testcase name for JUnit.
55      *
56      * @param theName the testcase's name.
57      */

58     public TestEqualTag(String JavaDoc theName) {
59         super(theName);
60     }
61
62     /**
63      * Start the tests.
64      *
65      * @param theArgs the arguments. Not used
66      */

67     public static void main(String JavaDoc[] theArgs) {
68         junit.awtui.TestRunner.main(new String JavaDoc[] {TestEqualTag.class.getName()});
69     }
70
71     /**
72      * @return a test suite (<code>TestSuite</code>) that includes all methods
73      * starting with "test"
74      */

75     public static Test suite() {
76         // All methods starting with "test" will be executed in the test suite.
77
return new TestSuite(TestEqualTag.class);
78     }
79
80     public void setUp() {
81         et = new EqualTag();
82         et.setPageContext(pageContext);
83
84     }
85
86     public void tearDown() {
87         et = null;
88     }
89
90
91
92     // --------------------------------------------------- Cookie String Equals
93

94
95     /* FIXME: Cactus does not send cookies?
96     public void beginCookieStringEquals(WebRequest testRequest) {
97
98         testRequest.addCookie(COOKIE_KEY, "abc");
99
100     }
101
102
103     public void testCookieStringEquals()
104         throws ServletException, JspException {
105
106         et.setCookie(COOKIE_KEY);
107         et.setValue(testStringValue);
108
109         assertEquals("Cookie string equals comparison", true,
110                      et.condition(0, 0));
111
112     }
113     */

114
115
116     // ----------------------------------------------- Cookie String Not Equals
117

118
119     public void beginCookieStringNotEquals(WebRequest testRequest) {
120
121         testRequest.addCookie(COOKIE_KEY, "abc");
122
123     }
124
125
126     public void testCookieStringNotEquals()
127         throws ServletException JavaDoc, JspException JavaDoc {
128
129         et.setCookie(COOKIE_KEY);
130         et.setValue(testStringValue1);
131
132         assertEquals("Cookie string not equals comparison", false,
133                      et.condition(0, 0));
134
135     }
136
137
138     // --------------------------------------------------- Header String Equals
139

140
141     public void beginHeaderStringEquals(WebRequest testRequest) {
142
143         testRequest.addHeader(HEADER_KEY, "abc");
144
145     }
146
147
148     public void testHeaderStringEquals()
149         throws ServletException JavaDoc, JspException JavaDoc {
150
151         et.setHeader(HEADER_KEY);
152         et.setValue(testStringValue);
153
154         assertEquals("Header string equals comparison", true,
155                      et.condition(0, 0));
156
157     }
158
159
160     // ----------------------------------------------- Header String Not Equals
161

162
163     public void beginHeaderStringNotEquals(WebRequest testRequest) {
164
165         testRequest.addHeader(HEADER_KEY, "abc");
166
167     }
168
169
170     public void testHeaderStringNotEquals()
171         throws ServletException JavaDoc, JspException JavaDoc {
172
173         et.setHeader(HEADER_KEY);
174         et.setValue(testStringValue1);
175
176         assertEquals("Header string not equals comparison", false,
177                      et.condition(0, 0));
178
179     }
180
181
182     // --------------------------------------------------------- Integer Equals
183

184
185     public void testIntegerEquals()
186         throws ServletException JavaDoc, JspException JavaDoc {
187
188         request.setAttribute(testIntegerKey, testIntegerValue);
189     et.setName(testIntegerKey);
190     et.setValue(testIntegerValue.toString());
191     
192         assertEquals("Integer equals comparison", true,
193                      et.condition(0, 0));
194
195     }
196
197
198     // ----------------------------------------------------- Integer Not Equals
199

200
201     public void testIntegerNotEquals()
202         throws ServletException JavaDoc, JspException JavaDoc {
203
204         request.setAttribute(testIntegerKey, testIntegerValue);
205     et.setName(testIntegerKey);
206     et.setValue(testIntegerValue1.toString());
207     
208         assertEquals("Integer not equals comparison", false,
209                      et.condition(0, 0));
210
211     }
212
213
214     // ------------------------------------------------ Parameter String Equals
215

216
217     public void beginParameterStringEquals(WebRequest testRequest) {
218
219         testRequest.addParameter(PARAMETER_KEY, "abc");
220
221     }
222
223
224     public void testParameterStringEquals()
225         throws ServletException JavaDoc, JspException JavaDoc {
226
227         et.setParameter(PARAMETER_KEY);
228         et.setValue(testStringValue);
229
230         assertEquals("Parameter string equals comparison", true,
231                      et.condition(0, 0));
232
233     }
234
235
236     // -------------------------------------------- Parameter String Not Equals
237

238
239     public void beginParameterStringNotEquals(WebRequest testRequest) {
240
241         testRequest.addParameter(PARAMETER_KEY, "abc");
242
243     }
244
245
246     public void testParameterStringNotEquals()
247         throws ServletException JavaDoc, JspException JavaDoc {
248
249         et.setParameter(PARAMETER_KEY);
250         et.setValue(testStringValue1);
251
252         assertEquals("Parameter string not equals comparison", false,
253                      et.condition(0, 0));
254
255     }
256
257
258     // ---------------------------------------------------------- String Equals
259

260
261     public void testStringEquals()
262         throws ServletException JavaDoc, JspException JavaDoc {
263
264         request.setAttribute(testStringKey, testStringValue);
265     et.setName(testStringKey);
266     et.setValue(testStringValue);
267     
268         assertEquals("String equals comparison", true,
269                      et.condition(0, 0));
270
271     }
272
273
274     // ------------------------------------------------------ String Not Equals
275

276
277     public void testStringNotEquals()
278         throws ServletException JavaDoc, JspException JavaDoc {
279
280         request.setAttribute(testStringKey, testStringValue);
281     et.setName(testStringKey);
282     et.setValue(testStringValue1);
283     
284         assertEquals("String not equals comparison", false,
285                      et.condition(0, 0));
286
287     }
288
289
290
291 }
292
Popular Tags