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 $
4
* $Date: 2004/03/14 06:23:48 $
6
* Copyright 1999-2004 The Apache Software Foundation.
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
12
* http://www.apache.org/licenses/LICENSE-2.0
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.
20
package org.apache.struts.taglib.bean;
22
import java.util.Locale;
24
import javax.servlet.jsp.PageContext;
25
import junit.framework.Test;
26
import junit.framework.TestSuite;
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;
35
* These tests attempt to cover every single possible configuration of the
36
* org.apache.struts.taglib.bean.MessageTag
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.
41
* All of these tests depend on a value being correctly written on the repose, then
42
* checked here in endXXX method.
45
public class TestMessageTag4 extends JspTestCase {
47
protected final static String TEST_KEY = "BeanKey";
48
protected final static String TEST_VAL = "Testing Message 1 2 3 4";
50
public TestMessageTag4(String theName) {
57
* @param theArgs the arguments. Not used
59
public static void main(String[] theArgs) {
60
junit.awtui.TestRunner.main(new String[] {TestMessageTag4.class.getName()});
64
* @return a test suite (<code>TestSuite</code>) that includes all methods
65
* starting with "test"
67
public static Test suite() {
68
// All methods starting with "test" will be executed in the test suite.
69
return new TestSuite(TestMessageTag4.class);
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");
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);
88
* ===========================================================
89
* Testing MessageTag (these comments serve as a divider of
90
* functionality being tested)
94
* ===========================================================
98
public void testMessageTag4ArgKeyNoScopeDefaultBundle() throws Exception {
99
runMyTest("testMessageTag4ArgKeyNoScopeDefaultBundle", new Locale("",""));
101
public void endMessageTag4ArgKeyNoScopeDefaultBundle(WebResponse response){
102
formatAndTest(TEST_VAL, response.getText());
105
public void testMessageTag4ArgKeyApplicationScopeDefaultBundle() throws Exception {
106
runMyTest("testMessageTag4ArgKeyApplicationScopeDefaultBundle", new Locale("",""));
108
public void endMessageTag4ArgKeyApplicationScopeDefaultBundle(WebResponse response){
109
formatAndTest(TEST_VAL, response.getText());
112
public void testMessageTag4ArgKeySessionScopeDefaultBundle() throws Exception {
113
runMyTest("testMessageTag4ArgKeySessionScopeDefaultBundle", new Locale("",""));
115
public void endMessageTag4ArgKeySessionScopeDefaultBundle(WebResponse response){
116
formatAndTest(TEST_VAL, response.getText());
119
public void testMessageTag4ArgKeyRequestScopeDefaultBundle() throws Exception {
120
runMyTest("testMessageTag4ArgKeyRequestScopeDefaultBundle", new Locale("",""));
122
public void endMessageTag4ArgKeyRequestScopeDefaultBundle(WebResponse response){
123
formatAndTest(TEST_VAL, response.getText());
127
public void testMessageTag4ArgKeyNoScopeAlternateBundle() throws Exception {
128
runMyTest("testMessageTag4ArgKeyNoScopeAlternateBundle", new Locale("",""));
130
public void endMessageTag4ArgKeyNoScopeAlternateBundle(WebResponse response){
131
formatAndTest(TEST_VAL, response.getText());
134
public void testMessageTag4ArgKeyApplicationScopeAlternateBundle() throws Exception {
135
runMyTest("testMessageTag4ArgKeyApplicationScopeAlternateBundle", new Locale("",""));
137
public void endMessageTag4ArgKeyApplicationScopeAlternateBundle(WebResponse response){
138
formatAndTest(TEST_VAL, response.getText());
141
public void testMessageTag4ArgKeySessionScopeAlternateBundle() throws Exception {
142
runMyTest("testMessageTag4ArgKeySessionScopeAlternateBundle", new Locale("",""));
144
public void endMessageTag4ArgKeySessionScopeAlternateBundle(WebResponse response){
145
formatAndTest(TEST_VAL, response.getText());
148
public void testMessageTag4ArgKeyRequestScopeAlternateBundle() throws Exception {
149
runMyTest("testMessageTag4ArgKeyRequestScopeAlternateBundle", new Locale("",""));
151
public void endMessageTag4ArgKeyRequestScopeAlternateBundle(WebResponse response){
152
formatAndTest(TEST_VAL, response.getText());
157
public void testMessageTag4ArgNameNoScopeDefaultBundle() throws Exception {
158
runMyTest("testMessageTag4ArgNameNoScopeDefaultBundle", new Locale("",""));
160
public void endMessageTag4ArgNameNoScopeDefaultBundle(WebResponse response){
161
formatAndTest(TEST_VAL, response.getText());
164
public void testMessageTag4ArgNameApplicationScopeDefaultBundle() throws Exception {
165
runMyTest("testMessageTag4ArgNameApplicationScopeDefaultBundle", new Locale("",""));
167
public void endMessageTag4ArgNameApplicationScopeDefaultBundle(WebResponse response){
168
formatAndTest(TEST_VAL, response.getText());
171
public void testMessageTag4ArgNameSessionScopeDefaultBundle() throws Exception {
172
runMyTest("testMessageTag4ArgNameSessionScopeDefaultBundle", new Locale("",""));
174
public void endMessageTag4ArgNameSessionScopeDefaultBundle(WebResponse response){
175
formatAndTest(TEST_VAL, response.getText());
178
public void testMessageTag4ArgNameRequestScopeDefaultBundle() throws Exception {
179
runMyTest("testMessageTag4ArgNameRequestScopeDefaultBundle", new Locale("",""));
181
public void endMessageTag4ArgNameRequestScopeDefaultBundle(WebResponse response){
182
formatAndTest(TEST_VAL, response.getText());
186
public void testMessageTag4ArgNameNoScopeAlternateBundle() throws Exception {
187
runMyTest("testMessageTag4ArgNameNoScopeAlternateBundle", new Locale("",""));
189
public void endMessageTag4ArgNameNoScopeAlternateBundle(WebResponse response){
190
formatAndTest(TEST_VAL, response.getText());
193
public void testMessageTag4ArgNameApplicationScopeAlternateBundle() throws Exception {
194
runMyTest("testMessageTag4ArgNameApplicationScopeAlternateBundle", new Locale("",""));
196
public void endMessageTag4ArgNameApplicationScopeAlternateBundle(WebResponse response){
197
formatAndTest(TEST_VAL, response.getText());
200
public void testMessageTag4ArgNameSessionScopeAlternateBundle() throws Exception {
201
runMyTest("testMessageTag4ArgNameSessionScopeAlternateBundle", new Locale("",""));
203
public void endMessageTag4ArgNameSessionScopeAlternateBundle(WebResponse response){
204
formatAndTest(TEST_VAL, response.getText());
207
public void testMessageTag4ArgNameRequestScopeAlternateBundle() throws Exception {
208
runMyTest("testMessageTag4ArgNameRequestScopeAlternateBundle", new Locale("",""));
210
public void endMessageTag4ArgNameRequestScopeAlternateBundle(WebResponse response){
211
formatAndTest(TEST_VAL, response.getText());
217
public void testMessageTag4ArgNamePropertyNoScopeDefaultBundle() throws Exception {
218
pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message.4"), PageContext.REQUEST_SCOPE);
219
runMyTest("testMessageTag4ArgNamePropertyNoScopeDefaultBundle", new Locale("",""));
221
public void endMessageTag4ArgNamePropertyNoScopeDefaultBundle(WebResponse response){
222
formatAndTest(TEST_VAL, response.getText());
225
public void testMessageTag4ArgNamePropertyApplicationScopeDefaultBundle() throws Exception {
226
pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message.4"), PageContext.APPLICATION_SCOPE);
227
runMyTest("testMessageTag4ArgNamePropertyApplicationScopeDefaultBundle", new Locale("",""));
229
public void endMessageTag4ArgNamePropertyApplicationScopeDefaultBundle(WebResponse response){
230
formatAndTest(TEST_VAL, response.getText());
233
public void testMessageTag4ArgNamePropertySessionScopeDefaultBundle() throws Exception {
234
pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message.4"), PageContext.SESSION_SCOPE);
235
runMyTest("testMessageTag4ArgNamePropertySessionScopeDefaultBundle", new Locale("",""));
237
public void endMessageTag4ArgNamePropertySessionScopeDefaultBundle(WebResponse response){
238
formatAndTest(TEST_VAL, response.getText());
241
public void testMessageTag4ArgNamePropertyRequestScopeDefaultBundle() throws Exception {
242
pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message.4"), PageContext.REQUEST_SCOPE);
243
runMyTest("testMessageTag4ArgNamePropertyRequestScopeDefaultBundle", new Locale("",""));
245
public void endMessageTag4ArgNamePropertyRequestScopeDefaultBundle(WebResponse response){
246
formatAndTest(TEST_VAL, response.getText());
250
public void testMessageTag4ArgNamePropertyNoScopeAlternateBundle() throws Exception {
251
pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message.4"), PageContext.REQUEST_SCOPE);
252
runMyTest("testMessageTag4ArgNamePropertyNoScopeAlternateBundle", new Locale("",""));
254
public void endMessageTag4ArgNamePropertyNoScopeAlternateBundle(WebResponse response){
255
formatAndTest(TEST_VAL, response.getText());
258
public void testMessageTag4ArgNamePropertyApplicationScopeAlternateBundle() throws Exception {
259
pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message.4"), PageContext.APPLICATION_SCOPE);
260
runMyTest("testMessageTag4ArgNamePropertyApplicationScopeAlternateBundle", new Locale("",""));
262
public void endMessageTag4ArgNamePropertyApplicationScopeAlternateBundle(WebResponse response){
263
formatAndTest(TEST_VAL, response.getText());
266
public void testMessageTag4ArgNamePropertySessionScopeAlternateBundle() throws Exception {
267
pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message.4"), PageContext.SESSION_SCOPE);
268
runMyTest("testMessageTag4ArgNamePropertySessionScopeAlternateBundle", new Locale("",""));
270
public void endMessageTag4ArgNamePropertySessionScopeAlternateBundle(WebResponse response){
271
formatAndTest(TEST_VAL, response.getText());
274
public void testMessageTag4ArgNamePropertyRequestScopeAlternateBundle() throws Exception {
275
pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message.4"), PageContext.REQUEST_SCOPE);
276
runMyTest("testMessageTag4ArgNamePropertyRequestScopeAlternateBundle", new Locale("",""));
278
public void endMessageTag4ArgNamePropertyRequestScopeAlternateBundle(WebResponse response){
279
formatAndTest(TEST_VAL, response.getText());