~ubuntu-branches/ubuntu/trusty/libstruts1.2-java/trusty-proposed

« back to all changes in this revision

Viewing changes to src/test/org/apache/struts/taglib/logic/TestGreaterEqualTag.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 15:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20041119153525-mdu08a76z4zo67xt
Tags: upstream-1.2.4
ImportĀ upstreamĀ versionĀ 1.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Header: /home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/logic/TestGreaterEqualTag.java,v 1.7 2004/07/06 06:38:52 craigmcc Exp $
 
3
 * $Revision: 1.7 $
 
4
 * $Date: 2004/07/06 06:38:52 $
 
5
 *
 
6
 * Copyright 1999-2004 The Apache Software Foundation.
 
7
 * 
 
8
 * Licensed under the Apache License, Version 2.0 (the "License");
 
9
 * you may not use this file except in compliance with the License.
 
10
 * You may obtain a copy of the License at
 
11
 * 
 
12
 *      http://www.apache.org/licenses/LICENSE-2.0
 
13
 * 
 
14
 * Unless required by applicable law or agreed to in writing, software
 
15
 * distributed under the License is distributed on an "AS IS" BASIS,
 
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
17
 * See the License for the specific language governing permissions and
 
18
 * limitations under the License.
 
19
 */
 
20
package org.apache.struts.taglib.logic;
 
21
 
 
22
import javax.servlet.ServletException;
 
23
import javax.servlet.jsp.JspException;
 
24
import javax.servlet.jsp.PageContext;
 
25
import junit.framework.Test;
 
26
import junit.framework.TestSuite;
 
27
import org.apache.cactus.JspTestCase;
 
28
import org.apache.cactus.WebRequest;
 
29
import org.apache.struts.util.LabelValueBean;
 
30
 
 
31
/**
 
32
 * Suite of unit tests for the
 
33
 * <code>org.apache.struts.taglib.logic.GreaterEqualTag</code> class.
 
34
 *
 
35
 */
 
36
public class TestGreaterEqualTag extends JspTestCase {
 
37
        
 
38
    protected final static String COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY";
 
39
    protected final static String HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY";
 
40
    protected final static String PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY";
 
41
    protected final static String GREATER_VAL = "5";
 
42
    protected final static String LESSER_VAL = "5";
 
43
 
 
44
 
 
45
    /**
 
46
     * Defines the testcase name for JUnit.
 
47
     *
 
48
     * @param theName the testcase's name.
 
49
     */
 
50
    public TestGreaterEqualTag(String theName) {
 
51
        super(theName);
 
52
    }
 
53
 
 
54
    /**
 
55
     * Start the tests.
 
56
     *
 
57
     * @param theArgs the arguments. Not used
 
58
     */
 
59
    public static void main(String[] theArgs) {
 
60
        junit.awtui.TestRunner.main(new String[] {TestGreaterEqualTag.class.getName()});
 
61
    }
 
62
 
 
63
    /**
 
64
     * @return a test suite (<code>TestSuite</code>) that includes all methods
 
65
     *         starting with "test"
 
66
     */
 
67
    public static Test suite() {
 
68
        // All methods starting with "test" will be executed in the test suite.
 
69
        return new TestSuite(TestGreaterEqualTag.class);
 
70
    }
 
71
 
 
72
    //----- Test initApplication() method --------------------------------------
 
73
        
 
74
    /**
 
75
     * Create cookie for testCookiePresent method test.
 
76
    */
 
77
    /* FIXME: Cactus does not send cookies?
 
78
    public void beginCookieGreaterEqual(WebRequest testRequest) {
 
79
       testRequest.addCookie(COOKIE_KEY, GREATER_VAL);
 
80
    }
 
81
    */
 
82
 
 
83
    /**
 
84
     * Create header for testHeaderGreaterEqual method test.
 
85
    */
 
86
    public void beginHeaderGreaterEqual(WebRequest testRequest) {
 
87
       testRequest.addHeader(HEADER_KEY, GREATER_VAL);
 
88
    }
 
89
 
 
90
    /**
 
91
     * Create header for testParameterGreaterEqual method test.
 
92
    */
 
93
    public void beginParameterGreaterEqual(WebRequest testRequest) {
 
94
       testRequest.addParameter(PARAMETER_KEY, GREATER_VAL);
 
95
    }
 
96
 
 
97
    /**
 
98
     * Verify the value stored in a cookie using <code>GreaterEqualTag</code>.
 
99
    */
 
100
    /* FIXME: Cactus does not send cookies?
 
101
    public void testCookieGreaterEqual() throws ServletException,  JspException {
 
102
        GreaterEqualTag ge = new GreaterEqualTag();
 
103
        ge.setPageContext(pageContext);
 
104
        ge.setCookie(COOKIE_KEY);
 
105
        ge.setValue(LESSER_VAL);
 
106
 
 
107
        assertTrue(
 
108
                "Cookie Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 
 
109
                ge.condition());
 
110
    }
 
111
    */
 
112
    
 
113
    /**
 
114
     * Verify the value stored in header using <code>GreaterEqualTag</code>.
 
115
    */
 
116
    public void testHeaderGreaterEqual() throws ServletException,  JspException {
 
117
        GreaterEqualTag ge = new GreaterEqualTag();
 
118
        ge.setPageContext(pageContext);
 
119
        ge.setHeader(HEADER_KEY);
 
120
        ge.setValue(LESSER_VAL);
 
121
 
 
122
        assertTrue(
 
123
                "Header Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 
 
124
                ge.condition());
 
125
    }
 
126
 
 
127
    /**
 
128
     * Verify the value stored in parameter using <code>GreaterEqualTag</code>.
 
129
    */
 
130
    public void testParameterGreaterEqual() throws ServletException,  JspException {
 
131
        GreaterEqualTag ge = new GreaterEqualTag();
 
132
        ge.setPageContext(pageContext);
 
133
        ge.setParameter(PARAMETER_KEY);
 
134
        ge.setValue(LESSER_VAL);
 
135
 
 
136
        assertTrue(
 
137
                "Parameter Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 
 
138
                ge.condition());
 
139
    }
 
140
    
 
141
 
 
142
    /**
 
143
     * Testing <code>GreaterEqualTag</code> using name attribute in
 
144
     * the application scope.
 
145
    */
 
146
    public void testApplicationScopeNameGreaterEqual() 
 
147
        throws ServletException,  JspException {
 
148
    
 
149
        GreaterEqualTag ge = new GreaterEqualTag();
 
150
 
 
151
                String testKey = "testApplicationScopeNameGreaterEqual";
 
152
                Integer itgr = new Integer(GREATER_VAL);
 
153
                
 
154
                pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE);
 
155
                ge.setPageContext(pageContext);
 
156
                ge.setName(testKey);
 
157
                ge.setScope("application");
 
158
                ge.setValue(LESSER_VAL);
 
159
 
 
160
        assertTrue(
 
161
                "Application scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 
 
162
                ge.condition());
 
163
    }
 
164
 
 
165
    /**
 
166
     * Testing <code>GreaterEqualTag</code> using name attribute in
 
167
     * the session scope.
 
168
    */
 
169
    public void testSessionScopeNameGreaterEqual() 
 
170
        throws ServletException,  JspException {
 
171
    
 
172
        GreaterEqualTag ge = new GreaterEqualTag();
 
173
 
 
174
                String testKey = "testSessionScopeNameGreaterEqual";
 
175
                Integer itgr = new Integer(GREATER_VAL);
 
176
                
 
177
                pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE);
 
178
                ge.setPageContext(pageContext);
 
179
                ge.setName(testKey);
 
180
                ge.setScope("session");
 
181
                ge.setValue(LESSER_VAL);
 
182
 
 
183
        assertTrue(
 
184
                "Session scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 
 
185
                ge.condition());
 
186
    }
 
187
 
 
188
    /**
 
189
     * Testing <code>GreaterEqualTag</code> using name attribute in
 
190
     * the request scope.
 
191
    */
 
192
    public void testRequestScopeNameGreaterEqual() 
 
193
        throws ServletException,  JspException {
 
194
    
 
195
        GreaterEqualTag ge = new GreaterEqualTag();
 
196
 
 
197
                String testKey = "testRequestScopeNameGreaterEqual";
 
198
                Integer itgr = new Integer(GREATER_VAL);
 
199
                
 
200
                pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE);
 
201
                ge.setPageContext(pageContext);
 
202
                ge.setName(testKey);
 
203
                ge.setScope("request");
 
204
                ge.setValue(LESSER_VAL);
 
205
 
 
206
        assertTrue(
 
207
                "Request scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 
 
208
                ge.condition());
 
209
    }
 
210
 
 
211
 
 
212
 
 
213
 
 
214
    /**
 
215
     * Testing <code>GreaterEqualTag</code> using name and property attribute in
 
216
     * the application scope.
 
217
    */
 
218
    public void testApplicationScopePropertyGreaterEqual() 
 
219
        throws ServletException,  JspException {
 
220
    
 
221
        GreaterEqualTag ge = new GreaterEqualTag();
 
222
 
 
223
                String testKey = "testApplicationScopePropertyGreaterEqual";
 
224
                LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
 
225
                
 
226
                pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE);
 
227
                ge.setPageContext(pageContext);
 
228
                ge.setName(testKey);
 
229
                ge.setScope("application");
 
230
                ge.setProperty("value");
 
231
                ge.setValue(LESSER_VAL);
 
232
 
 
233
        assertTrue(
 
234
                "Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
 
235
                ge.condition());
 
236
    }
 
237
 
 
238
    /**
 
239
     * Testing <code>GreaterEqualTag</code> using name and property attribute in
 
240
     * the session scope.
 
241
    */
 
242
    public void testSessionScopePropertyGreaterEqual() 
 
243
        throws ServletException,  JspException {
 
244
    
 
245
        GreaterEqualTag ge = new GreaterEqualTag();
 
246
 
 
247
                String testKey = "testSessionScopePropertyGreaterEqual";
 
248
                LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
 
249
                
 
250
                pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE);
 
251
                ge.setPageContext(pageContext);
 
252
                ge.setName(testKey);
 
253
                ge.setScope("session");
 
254
                ge.setProperty("value");
 
255
                ge.setValue(LESSER_VAL);
 
256
 
 
257
        assertTrue(
 
258
                "Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
 
259
                ge.condition());
 
260
    }
 
261
    
 
262
    /**
 
263
     * Testing <code>GreaterEqualTag</code> using name and property attribute in
 
264
     * the request scope.
 
265
    */
 
266
    public void testRequestScopePropertyGreaterEqual() 
 
267
        throws ServletException,  JspException {
 
268
    
 
269
        GreaterEqualTag ge = new GreaterEqualTag();
 
270
 
 
271
                String testKey = "testRequestScopePropertyGreaterEqual";
 
272
                LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL);
 
273
                
 
274
                pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE);
 
275
                ge.setPageContext(pageContext);
 
276
                ge.setName(testKey);
 
277
                ge.setScope("request");
 
278
                ge.setProperty("value");
 
279
                ge.setValue(LESSER_VAL);
 
280
 
 
281
        assertTrue(
 
282
                "Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")",
 
283
                ge.condition());
 
284
    }
 
285
    
 
286
    
 
287
    
 
288
}