KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestNotEqualTag.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.PageContext JavaDoc;
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 import org.apache.cactus.JspTestCase;
26 import org.apache.cactus.WebRequest;
27
28 /**
29  * Suite of unit tests for the
30  * <code>org.apache.struts.taglib.logic.NotEqualTag</code> class.
31  */

32 public class TestNotEqualTag extends JspTestCase {
33     protected final static String JavaDoc COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY";
34     protected final static String JavaDoc HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY";
35     protected final static String JavaDoc PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY";
36     protected NotEqualTag net = null;
37     protected static String JavaDoc testStringKey;
38     protected static String JavaDoc testStringValue;
39     protected static String JavaDoc testStringValue1;
40     protected static String JavaDoc testIntegerKey;
41     protected static Integer JavaDoc testIntegerValue;
42     protected static Integer JavaDoc testIntegerValue1;
43
44     /**
45      * Defines the testcase name for JUnit.
46      *
47      * @param theName the testcase's name.
48      */

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

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

66     public static Test suite() {
67         // All methods starting with "test" will be executed in the test suite.
68
return new TestSuite(TestNotEqualTag.class);
69     }
70
71     public void setUp()
72     {
73         testStringKey = "testString";
74         testStringValue = "abc";
75         testStringValue1 = "abcd";
76         testIntegerKey = "testInteger";
77         testIntegerValue = new Integer JavaDoc(21);
78         testIntegerValue1 = new Integer JavaDoc(testIntegerValue.intValue() + 1);
79
80         net = new NotEqualTag();
81         net.setPageContext(pageContext);
82     }
83
84     public void tearDown()
85     {
86         net = null;
87     }
88
89     /**
90      * Create cookie for testCookieStringEquals method test.
91     */

92     /* FIXME: Cactus does not send cookies?
93     public void beginCookieStringEquals(WebRequest testRequest) {
94        testRequest.addCookie(COOKIE_KEY, "abc");
95     }
96
97     public void testCookieStringEquals() throws ServletException, javax.servlet.jsp.JspException {
98         net.setCookie(COOKIE_KEY);
99         net.setValue(testStringValue);
100
101         assertEquals("Cookie string equals comparison", true, net.condition(0, 0));
102     }
103     */

104
105     /**
106      * Create cookie for testCookieStringNotEquals method test.
107     */

108     public void beginCookieStringNotEquals(WebRequest testRequest) {
109        testRequest.addCookie(COOKIE_KEY, "abc");
110     }
111
112     public void testCookieStringNotEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
113         net.setCookie(COOKIE_KEY);
114         net.setValue(testStringValue1);
115
116         assertEquals("Cookie string not equals comparison", false, net.condition(0, 0));
117     }
118
119     /**
120      * Create cookie for testHeaderStringEquals method test.
121     */

122     public void beginHeaderStringEquals(WebRequest testRequest) {
123        testRequest.addHeader(COOKIE_KEY, "abc");
124     }
125
126     public void testHeaderStringEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
127         net.setHeader(COOKIE_KEY);
128         net.setValue(testStringValue);
129
130         assertEquals("Header string equals comparison", true, net.condition(0, 0));
131     }
132
133     /**
134      * Create cookie for testHeaderStringNotEquals method test.
135     */

136     public void beginHeaderStringNotEquals(WebRequest testRequest) {
137        testRequest.addHeader(COOKIE_KEY, "abc");
138     }
139
140     public void testHeaderStringNotEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
141         net.setHeader(COOKIE_KEY);
142         net.setValue(testStringValue1);
143
144         assertEquals("Header string not equals comparison", false, net.condition(0, 0));
145     }
146
147     /**
148      * Create cookie for testParameterStringEquals method test.
149     */

150     public void beginParameterStringEquals(WebRequest testRequest) {
151        testRequest.addParameter(PARAMETER_KEY, "abc");
152     }
153
154     public void testParameterStringEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
155         net.setParameter(PARAMETER_KEY);
156         net.setValue(testStringValue);
157
158         assertEquals("Parameter string equals comparison", true, net.condition(0, 0));
159     }
160
161     /**
162      * Create cookie for testParameterStringNotEquals method test.
163     */

164     public void beginParameterStringNotEquals(WebRequest testRequest) {
165        testRequest.addParameter(PARAMETER_KEY, "abc");
166     }
167
168     public void testParameterStringNotEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
169         net.setParameter(PARAMETER_KEY);
170         net.setValue(testStringValue1);
171
172         assertEquals("Parameter string not equals comparison", false, net.condition(0, 0));
173     }
174
175     /**
176      * Verify that two <code>String</code>s match using the <code>NotEqualTag</code>.
177      */

178     public void testStringEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
179         request.setAttribute(testStringKey, testStringValue);
180         net.setName(testStringKey);
181         net.setValue(testStringValue);
182         System.out.println("testing");
183         assertEquals("String equals comparison", true, net.condition(0, 0));
184     }
185
186     /**
187      * Verify that two <code>String</code>s do not match using the <code>NotEqualTag</code>.
188      */

189     public void testStringNotEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
190         request.setAttribute(testStringKey, testStringValue);
191         net.setName(testStringKey);
192         net.setValue(testStringValue1);
193
194         assertEquals("String not equals comparison", false, net.condition(0, 0));
195     }
196
197     /**
198      * Verify that an <code>Integer</code> and a <code>String</code>
199      * match using the <code>NotEqualTag</code>.
200      */

201     public void testIntegerEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
202         request.setAttribute(testIntegerKey, testIntegerValue);
203         net.setName(testIntegerKey);
204         net.setValue(testIntegerValue.toString());
205
206         assertEquals("Integer equals comparison", true, net.condition(0, 0));
207     }
208
209     /**
210      * Verify that two <code>String</code>s do not match using the <code>NotEqualTag</code>.
211      */

212     public void testIntegerNotEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
213         request.setAttribute(testIntegerKey, testIntegerValue);
214         net.setName(testIntegerKey);
215         net.setValue(testIntegerValue1.toString());
216
217         assertEquals("Integer equals comparison", false, net.condition(0, 0));
218     }
219
220     /**
221      * Verify that there is an application scope String in scope using the <code>EqualTag</code>.
222     */

223     public void testApplicationScopeStringEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
224         String JavaDoc testKey = "testApplicationScopeStringEquals";
225
226         pageContext.setAttribute(testKey, testStringValue, PageContext.APPLICATION_SCOPE);
227         net.setPageContext(pageContext);
228         net.setName(testKey);
229         net.setScope("application");
230         net.setValue(testStringValue);
231
232         assertEquals("String in application scope equals", true, net.condition(0, 0));
233     }
234
235     /**
236      * Verify that there is an application scope String that is not equal using the <code>EqualTag</code>.
237     */

238     public void testApplicationScopeStringNotEquals() throws ServletException JavaDoc, javax.servlet.jsp.JspException JavaDoc {
239         String JavaDoc testKey = "testApplicationScopeStringNotEquals";
240
241         pageContext.setAttribute(testKey, testStringValue, PageContext.APPLICATION_SCOPE);
242         net.setPageContext(pageContext);
243         net.setName(testKey);
244         net.setScope("application");
245         net.setValue(testStringValue1);
246
247         assertEquals("String in application scope not equals", false, net.condition(0, 0));
248     }
249
250 }
251
Popular Tags