~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/bean/TestMessageTag4.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/bean/TestMessageTag4.java,v 1.10 2004/03/14 06:23:48 sraeburn Exp $
 
3
 * $Revision: 1.10 $
 
4
 * $Date: 2004/03/14 06:23:48 $
 
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.bean;
 
21
 
 
22
import java.util.Locale;
 
23
 
 
24
import javax.servlet.jsp.PageContext;
 
25
import junit.framework.Test;
 
26
import junit.framework.TestSuite;
 
27
 
 
28
import org.apache.cactus.JspTestCase;
 
29
import org.apache.cactus.WebResponse;
 
30
import org.apache.struts.Globals;
 
31
import org.apache.struts.taglib.SimpleBeanForTesting;
 
32
import org.apache.commons.lang.StringUtils;
 
33
 
 
34
/**
 
35
  * These tests attempt to cover every single possible configuration of the
 
36
  * org.apache.struts.taglib.bean.MessageTag
 
37
  *
 
38
  * I've tried to describe what I'm testing as best as possible by the method names.
 
39
  * To see how I'm testing, refer to the jsp file that these tests forward to.
 
40
  *
 
41
  * All of these tests depend on a value being correctly written on the repose, then
 
42
  * checked here in endXXX method.
 
43
  *
 
44
  */
 
45
public class TestMessageTag4 extends JspTestCase {
 
46
 
 
47
    protected final static String TEST_KEY = "BeanKey";
 
48
    protected final static String TEST_VAL = "Testing Message 1 2 3 4";
 
49
 
 
50
    public TestMessageTag4(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[] {TestMessageTag4.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(TestMessageTag4.class);
 
70
    }
 
71
 
 
72
    private void runMyTest(String whichTest, Locale locale) throws Exception {
 
73
        pageContext.setAttribute(Globals.LOCALE_KEY, locale, PageContext.SESSION_SCOPE);
 
74
        request.setAttribute("runTest", whichTest);
 
75
        pageContext.forward("/test/org/apache/struts/taglib/bean/TestMessageTag4.jsp");
 
76
    }
 
77
 
 
78
        private void formatAndTest(String compare, String output) {
 
79
                //fix for introduced carriage return / line feeds
 
80
                output = StringUtils.replace(output,"\r","");
 
81
                output = StringUtils.replace(output,"\n","");
 
82
                output = output.trim();
 
83
                //System.out.println("Testing [" + compare + "] == [" + output + "]");
 
84
            assertEquals(compare, output);
 
85
        }
 
86
 
 
87
    /*
 
88
     * ===========================================================
 
89
     * Testing MessageTag (these comments serve as a divider of
 
90
     *                     functionality being tested)
 
91
     *
 
92
     * Section: 4 Args
 
93
     * Locale:  (default)
 
94
     * ===========================================================
 
95
     */
 
96
 
 
97
 
 
98
    public void testMessageTag4ArgKeyNoScopeDefaultBundle() throws Exception {
 
99
     runMyTest("testMessageTag4ArgKeyNoScopeDefaultBundle", new Locale("",""));
 
100
        }
 
101
        public void endMessageTag4ArgKeyNoScopeDefaultBundle(WebResponse response){
 
102
                formatAndTest(TEST_VAL, response.getText());
 
103
        }
 
104
 
 
105
    public void testMessageTag4ArgKeyApplicationScopeDefaultBundle() throws Exception {
 
106
     runMyTest("testMessageTag4ArgKeyApplicationScopeDefaultBundle", new Locale("",""));
 
107
        }
 
108
        public void endMessageTag4ArgKeyApplicationScopeDefaultBundle(WebResponse response){
 
109
                formatAndTest(TEST_VAL, response.getText());
 
110
        }
 
111
 
 
112
    public void testMessageTag4ArgKeySessionScopeDefaultBundle() throws Exception {
 
113
     runMyTest("testMessageTag4ArgKeySessionScopeDefaultBundle", new Locale("",""));
 
114
        }
 
115
        public void endMessageTag4ArgKeySessionScopeDefaultBundle(WebResponse response){
 
116
                formatAndTest(TEST_VAL, response.getText());
 
117
        }
 
118
 
 
119
    public void testMessageTag4ArgKeyRequestScopeDefaultBundle() throws Exception {
 
120
     runMyTest("testMessageTag4ArgKeyRequestScopeDefaultBundle", new Locale("",""));
 
121
        }
 
122
        public void endMessageTag4ArgKeyRequestScopeDefaultBundle(WebResponse response){
 
123
                formatAndTest(TEST_VAL, response.getText());
 
124
        }
 
125
 
 
126
 
 
127
    public void testMessageTag4ArgKeyNoScopeAlternateBundle() throws Exception {
 
128
     runMyTest("testMessageTag4ArgKeyNoScopeAlternateBundle", new Locale("",""));
 
129
        }
 
130
        public void endMessageTag4ArgKeyNoScopeAlternateBundle(WebResponse response){
 
131
                formatAndTest(TEST_VAL, response.getText());
 
132
        }
 
133
 
 
134
    public void testMessageTag4ArgKeyApplicationScopeAlternateBundle() throws Exception {
 
135
     runMyTest("testMessageTag4ArgKeyApplicationScopeAlternateBundle", new Locale("",""));
 
136
        }
 
137
        public void endMessageTag4ArgKeyApplicationScopeAlternateBundle(WebResponse response){
 
138
                formatAndTest(TEST_VAL, response.getText());
 
139
        }
 
140
 
 
141
    public void testMessageTag4ArgKeySessionScopeAlternateBundle() throws Exception {
 
142
     runMyTest("testMessageTag4ArgKeySessionScopeAlternateBundle", new Locale("",""));
 
143
        }
 
144
        public void endMessageTag4ArgKeySessionScopeAlternateBundle(WebResponse response){
 
145
                formatAndTest(TEST_VAL, response.getText());
 
146
        }
 
147
 
 
148
    public void testMessageTag4ArgKeyRequestScopeAlternateBundle() throws Exception {
 
149
     runMyTest("testMessageTag4ArgKeyRequestScopeAlternateBundle", new Locale("",""));
 
150
        }
 
151
        public void endMessageTag4ArgKeyRequestScopeAlternateBundle(WebResponse response){
 
152
                formatAndTest(TEST_VAL, response.getText());
 
153
        }
 
154
 
 
155
 
 
156
 
 
157
    public void testMessageTag4ArgNameNoScopeDefaultBundle() throws Exception {
 
158
     runMyTest("testMessageTag4ArgNameNoScopeDefaultBundle", new Locale("",""));
 
159
        }
 
160
        public void endMessageTag4ArgNameNoScopeDefaultBundle(WebResponse response){
 
161
                formatAndTest(TEST_VAL, response.getText());
 
162
        }
 
163
 
 
164
    public void testMessageTag4ArgNameApplicationScopeDefaultBundle() throws Exception {
 
165
     runMyTest("testMessageTag4ArgNameApplicationScopeDefaultBundle", new Locale("",""));
 
166
        }
 
167
        public void endMessageTag4ArgNameApplicationScopeDefaultBundle(WebResponse response){
 
168
                formatAndTest(TEST_VAL, response.getText());
 
169
        }
 
170
 
 
171
    public void testMessageTag4ArgNameSessionScopeDefaultBundle() throws Exception {
 
172
     runMyTest("testMessageTag4ArgNameSessionScopeDefaultBundle", new Locale("",""));
 
173
        }
 
174
        public void endMessageTag4ArgNameSessionScopeDefaultBundle(WebResponse response){
 
175
                formatAndTest(TEST_VAL, response.getText());
 
176
        }
 
177
 
 
178
    public void testMessageTag4ArgNameRequestScopeDefaultBundle() throws Exception {
 
179
     runMyTest("testMessageTag4ArgNameRequestScopeDefaultBundle", new Locale("",""));
 
180
        }
 
181
        public void endMessageTag4ArgNameRequestScopeDefaultBundle(WebResponse response){
 
182
                formatAndTest(TEST_VAL, response.getText());
 
183
        }
 
184
 
 
185
 
 
186
    public void testMessageTag4ArgNameNoScopeAlternateBundle() throws Exception {
 
187
     runMyTest("testMessageTag4ArgNameNoScopeAlternateBundle", new Locale("",""));
 
188
        }
 
189
        public void endMessageTag4ArgNameNoScopeAlternateBundle(WebResponse response){
 
190
                formatAndTest(TEST_VAL, response.getText());
 
191
        }
 
192
 
 
193
    public void testMessageTag4ArgNameApplicationScopeAlternateBundle() throws Exception {
 
194
     runMyTest("testMessageTag4ArgNameApplicationScopeAlternateBundle", new Locale("",""));
 
195
        }
 
196
        public void endMessageTag4ArgNameApplicationScopeAlternateBundle(WebResponse response){
 
197
                formatAndTest(TEST_VAL, response.getText());
 
198
        }
 
199
 
 
200
    public void testMessageTag4ArgNameSessionScopeAlternateBundle() throws Exception {
 
201
     runMyTest("testMessageTag4ArgNameSessionScopeAlternateBundle", new Locale("",""));
 
202
        }
 
203
        public void endMessageTag4ArgNameSessionScopeAlternateBundle(WebResponse response){
 
204
                formatAndTest(TEST_VAL, response.getText());
 
205
        }
 
206
 
 
207
    public void testMessageTag4ArgNameRequestScopeAlternateBundle() throws Exception {
 
208
     runMyTest("testMessageTag4ArgNameRequestScopeAlternateBundle", new Locale("",""));
 
209
        }
 
210
        public void endMessageTag4ArgNameRequestScopeAlternateBundle(WebResponse response){
 
211
                formatAndTest(TEST_VAL, response.getText());
 
212
        }
 
213
 
 
214
 
 
215
 
 
216
 
 
217
    public void testMessageTag4ArgNamePropertyNoScopeDefaultBundle() throws Exception {
 
218
        pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message.4"), PageContext.REQUEST_SCOPE);
 
219
     runMyTest("testMessageTag4ArgNamePropertyNoScopeDefaultBundle", new Locale("",""));
 
220
        }
 
221
        public void endMessageTag4ArgNamePropertyNoScopeDefaultBundle(WebResponse response){
 
222
                formatAndTest(TEST_VAL, response.getText());
 
223
        }
 
224
 
 
225
    public void testMessageTag4ArgNamePropertyApplicationScopeDefaultBundle() throws Exception {
 
226
        pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message.4"), PageContext.APPLICATION_SCOPE);
 
227
     runMyTest("testMessageTag4ArgNamePropertyApplicationScopeDefaultBundle", new Locale("",""));
 
228
        }
 
229
        public void endMessageTag4ArgNamePropertyApplicationScopeDefaultBundle(WebResponse response){
 
230
                formatAndTest(TEST_VAL, response.getText());
 
231
        }
 
232
 
 
233
    public void testMessageTag4ArgNamePropertySessionScopeDefaultBundle() throws Exception {
 
234
        pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message.4"), PageContext.SESSION_SCOPE);
 
235
     runMyTest("testMessageTag4ArgNamePropertySessionScopeDefaultBundle", new Locale("",""));
 
236
        }
 
237
        public void endMessageTag4ArgNamePropertySessionScopeDefaultBundle(WebResponse response){
 
238
                formatAndTest(TEST_VAL, response.getText());
 
239
        }
 
240
 
 
241
    public void testMessageTag4ArgNamePropertyRequestScopeDefaultBundle() throws Exception {
 
242
        pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message.4"), PageContext.REQUEST_SCOPE);
 
243
     runMyTest("testMessageTag4ArgNamePropertyRequestScopeDefaultBundle", new Locale("",""));
 
244
        }
 
245
        public void endMessageTag4ArgNamePropertyRequestScopeDefaultBundle(WebResponse response){
 
246
                formatAndTest(TEST_VAL, response.getText());
 
247
        }
 
248
 
 
249
 
 
250
    public void testMessageTag4ArgNamePropertyNoScopeAlternateBundle() throws Exception {
 
251
        pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message.4"), PageContext.REQUEST_SCOPE);
 
252
     runMyTest("testMessageTag4ArgNamePropertyNoScopeAlternateBundle", new Locale("",""));
 
253
        }
 
254
        public void endMessageTag4ArgNamePropertyNoScopeAlternateBundle(WebResponse response){
 
255
                formatAndTest(TEST_VAL, response.getText());
 
256
        }
 
257
 
 
258
    public void testMessageTag4ArgNamePropertyApplicationScopeAlternateBundle() throws Exception {
 
259
        pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message.4"), PageContext.APPLICATION_SCOPE);
 
260
     runMyTest("testMessageTag4ArgNamePropertyApplicationScopeAlternateBundle", new Locale("",""));
 
261
        }
 
262
        public void endMessageTag4ArgNamePropertyApplicationScopeAlternateBundle(WebResponse response){
 
263
                formatAndTest(TEST_VAL, response.getText());
 
264
        }
 
265
 
 
266
    public void testMessageTag4ArgNamePropertySessionScopeAlternateBundle() throws Exception {
 
267
        pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message.4"), PageContext.SESSION_SCOPE);
 
268
     runMyTest("testMessageTag4ArgNamePropertySessionScopeAlternateBundle", new Locale("",""));
 
269
        }
 
270
        public void endMessageTag4ArgNamePropertySessionScopeAlternateBundle(WebResponse response){
 
271
                formatAndTest(TEST_VAL, response.getText());
 
272
        }
 
273
 
 
274
    public void testMessageTag4ArgNamePropertyRequestScopeAlternateBundle() throws Exception {
 
275
        pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message.4"), PageContext.REQUEST_SCOPE);
 
276
     runMyTest("testMessageTag4ArgNamePropertyRequestScopeAlternateBundle", new Locale("",""));
 
277
        }
 
278
        public void endMessageTag4ArgNamePropertyRequestScopeAlternateBundle(WebResponse response){
 
279
                formatAndTest(TEST_VAL, response.getText());
 
280
        }
 
281
 
 
282
 
 
283
}