KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > bean > TestMessageTag


1 /*
2  * $Id: TestMessageTag.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.bean;
19
20 import java.util.Locale JavaDoc;
21
22 import javax.servlet.jsp.PageContext JavaDoc;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import org.apache.cactus.WebResponse;
28 import org.apache.struts.Globals;
29 import org.apache.struts.taglib.SimpleBeanForTesting;
30 import org.apache.struts.taglib.TaglibTestBase;
31
32 /**
33   * These tests attempt to cover every single possible configuration of the
34   * org.apache.struts.taglib.bean.MessageTag
35   *
36   * I've tried to describe what I'm testing as best as possible by the method names.
37   * To see how I'm testing, refer to the jsp file that these tests forward to.
38   *
39   * All of these tests depend on a value being correctly written on the repose, then
40   * checked here in endXXX method.
41   *
42   */

43 public class TestMessageTag extends TaglibTestBase {
44
45     protected final static String JavaDoc TEST_KEY = "BeanKey";
46     protected final static String JavaDoc TEST_VAL = "Testing Message";
47
48     public TestMessageTag(String JavaDoc theName) {
49         super(theName);
50     }
51
52     /**
53      * Start the tests.
54      *
55      * @param theArgs the arguments. Not used
56      */

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

65     public static Test suite() {
66         // All methods starting with "test" will be executed in the test suite.
67
return new TestSuite(TestMessageTag.class);
68     }
69
70     private void runMyTest(String JavaDoc whichTest, Locale JavaDoc locale) throws Exception JavaDoc {
71         pageContext.setAttribute(Globals.LOCALE_KEY, locale, PageContext.SESSION_SCOPE);
72         request.setAttribute("runTest", whichTest);
73         pageContext.forward("/test/org/apache/struts/taglib/bean/TestMessageTag.jsp");
74     }
75
76         private void formatAndTest(String JavaDoc compare, String JavaDoc output) {
77                 //fix for introduced carriage return / line feeds
78
output = replace(output,"\r","");
79                 output = replace(output,"\n","");
80                 output = output.trim();
81                 //System.out.println("Testing [" + compare + "] == [" + output + "]");
82
assertEquals(compare, output);
83         }
84
85     /*
86      * ===========================================================
87      * Testing MessageTag (these comments serve as a divider of
88      * functionality being tested)
89      *
90      * Section: NoArg
91      * Locale: (default)
92      * ===========================================================
93      */

94
95
96     public void testMessageTagNoArgKeyNoScopeDefaultBundle() throws Exception JavaDoc {
97      runMyTest("testMessageTagNoArgKeyNoScopeDefaultBundle", new Locale JavaDoc("",""));
98         }
99         public void endMessageTagNoArgKeyNoScopeDefaultBundle(WebResponse response){
100                 formatAndTest(TEST_VAL, response.getText());
101         }
102
103     public void testMessageTagNoArgKeyApplicationScopeDefaultBundle() throws Exception JavaDoc {
104      runMyTest("testMessageTagNoArgKeyApplicationScopeDefaultBundle", new Locale JavaDoc("",""));
105         }
106         public void endMessageTagNoArgKeyApplicationScopeDefaultBundle(WebResponse response){
107                 formatAndTest(TEST_VAL, response.getText());
108         }
109
110     public void testMessageTagNoArgKeySessionScopeDefaultBundle() throws Exception JavaDoc {
111      runMyTest("testMessageTagNoArgKeySessionScopeDefaultBundle", new Locale JavaDoc("",""));
112         }
113         public void endMessageTagNoArgKeySessionScopeDefaultBundle(WebResponse response){
114                 formatAndTest(TEST_VAL, response.getText());
115         }
116
117     public void testMessageTagNoArgKeyRequestScopeDefaultBundle() throws Exception JavaDoc {
118      runMyTest("testMessageTagNoArgKeyRequestScopeDefaultBundle", new Locale JavaDoc("",""));
119         }
120         public void endMessageTagNoArgKeyRequestScopeDefaultBundle(WebResponse response){
121                 formatAndTest(TEST_VAL, response.getText());
122         }
123
124
125     public void testMessageTagNoArgKeyNoScopeAlternateBundle() throws Exception JavaDoc {
126      runMyTest("testMessageTagNoArgKeyNoScopeAlternateBundle", new Locale JavaDoc("",""));
127         }
128         public void endMessageTagNoArgKeyNoScopeAlternateBundle(WebResponse response){
129                 formatAndTest(TEST_VAL, response.getText());
130         }
131
132     public void testMessageTagNoArgKeyApplicationScopeAlternateBundle() throws Exception JavaDoc {
133      runMyTest("testMessageTagNoArgKeyApplicationScopeAlternateBundle", new Locale JavaDoc("",""));
134         }
135         public void endMessageTagNoArgKeyApplicationScopeAlternateBundle(WebResponse response){
136                 formatAndTest(TEST_VAL, response.getText());
137         }
138
139     public void testMessageTagNoArgKeySessionScopeAlternateBundle() throws Exception JavaDoc {
140      runMyTest("testMessageTagNoArgKeySessionScopeAlternateBundle", new Locale JavaDoc("",""));
141         }
142         public void endMessageTagNoArgKeySessionScopeAlternateBundle(WebResponse response){
143                 formatAndTest(TEST_VAL, response.getText());
144         }
145
146     public void testMessageTagNoArgKeyRequestScopeAlternateBundle() throws Exception JavaDoc {
147      runMyTest("testMessageTagNoArgKeyRequestScopeAlternateBundle", new Locale JavaDoc("",""));
148         }
149         public void endMessageTagNoArgKeyRequestScopeAlternateBundle(WebResponse response){
150                 formatAndTest(TEST_VAL, response.getText());
151         }
152
153
154
155     public void testMessageTagNoArgNameNoScopeDefaultBundle() throws Exception JavaDoc {
156      runMyTest("testMessageTagNoArgNameNoScopeDefaultBundle", new Locale JavaDoc("",""));
157         }
158         public void endMessageTagNoArgNameNoScopeDefaultBundle(WebResponse response){
159                 formatAndTest(TEST_VAL, response.getText());
160         }
161
162     public void testMessageTagNoArgNameApplicationScopeDefaultBundle() throws Exception JavaDoc {
163      runMyTest("testMessageTagNoArgNameApplicationScopeDefaultBundle", new Locale JavaDoc("",""));
164         }
165         public void endMessageTagNoArgNameApplicationScopeDefaultBundle(WebResponse response){
166                 formatAndTest(TEST_VAL, response.getText());
167         }
168
169     public void testMessageTagNoArgNameSessionScopeDefaultBundle() throws Exception JavaDoc {
170      runMyTest("testMessageTagNoArgNameSessionScopeDefaultBundle", new Locale JavaDoc("",""));
171         }
172         public void endMessageTagNoArgNameSessionScopeDefaultBundle(WebResponse response){
173                 formatAndTest(TEST_VAL, response.getText());
174         }
175
176     public void testMessageTagNoArgNameRequestScopeDefaultBundle() throws Exception JavaDoc {
177      runMyTest("testMessageTagNoArgNameRequestScopeDefaultBundle", new Locale JavaDoc("",""));
178         }
179         public void endMessageTagNoArgNameRequestScopeDefaultBundle(WebResponse response){
180                 formatAndTest(TEST_VAL, response.getText());
181         }
182
183
184     public void testMessageTagNoArgNameNoScopeAlternateBundle() throws Exception JavaDoc {
185      runMyTest("testMessageTagNoArgNameNoScopeAlternateBundle", new Locale JavaDoc("",""));
186         }
187         public void endMessageTagNoArgNameNoScopeAlternateBundle(WebResponse response){
188                 formatAndTest(TEST_VAL, response.getText());
189         }
190
191     public void testMessageTagNoArgNameApplicationScopeAlternateBundle() throws Exception JavaDoc {
192      runMyTest("testMessageTagNoArgNameApplicationScopeAlternateBundle", new Locale JavaDoc("",""));
193         }
194         public void endMessageTagNoArgNameApplicationScopeAlternateBundle(WebResponse response){
195                 formatAndTest(TEST_VAL, response.getText());
196         }
197
198     public void testMessageTagNoArgNameSessionScopeAlternateBundle() throws Exception JavaDoc {
199      runMyTest("testMessageTagNoArgNameSessionScopeAlternateBundle", new Locale JavaDoc("",""));
200         }
201         public void endMessageTagNoArgNameSessionScopeAlternateBundle(WebResponse response){
202                 formatAndTest(TEST_VAL, response.getText());
203         }
204
205     public void testMessageTagNoArgNameRequestScopeAlternateBundle() throws Exception JavaDoc {
206      runMyTest("testMessageTagNoArgNameRequestScopeAlternateBundle", new Locale JavaDoc("",""));
207         }
208         public void endMessageTagNoArgNameRequestScopeAlternateBundle(WebResponse response){
209                 formatAndTest(TEST_VAL, response.getText());
210         }
211
212
213
214
215     public void testMessageTagNoArgNamePropertyNoScopeDefaultBundle() throws Exception JavaDoc {
216         pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message"), PageContext.REQUEST_SCOPE);
217      runMyTest("testMessageTagNoArgNamePropertyNoScopeDefaultBundle", new Locale JavaDoc("",""));
218         }
219         public void endMessageTagNoArgNamePropertyNoScopeDefaultBundle(WebResponse response){
220                 formatAndTest(TEST_VAL, response.getText());
221         }
222
223     public void testMessageTagNoArgNamePropertyApplicationScopeDefaultBundle() throws Exception JavaDoc {
224         pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message"), PageContext.APPLICATION_SCOPE);
225      runMyTest("testMessageTagNoArgNamePropertyApplicationScopeDefaultBundle", new Locale JavaDoc("",""));
226         }
227         public void endMessageTagNoArgNamePropertyApplicationScopeDefaultBundle(WebResponse response){
228                 formatAndTest(TEST_VAL, response.getText());
229         }
230
231     public void testMessageTagNoArgNamePropertySessionScopeDefaultBundle() throws Exception JavaDoc {
232         pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message"), PageContext.SESSION_SCOPE);
233      runMyTest("testMessageTagNoArgNamePropertySessionScopeDefaultBundle", new Locale JavaDoc("",""));
234         }
235         public void endMessageTagNoArgNamePropertySessionScopeDefaultBundle(WebResponse response){
236                 formatAndTest(TEST_VAL, response.getText());
237         }
238
239     public void testMessageTagNoArgNamePropertyRequestScopeDefaultBundle() throws Exception JavaDoc {
240         pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message"), PageContext.REQUEST_SCOPE);
241      runMyTest("testMessageTagNoArgNamePropertyRequestScopeDefaultBundle", new Locale JavaDoc("",""));
242         }
243         public void endMessageTagNoArgNamePropertyRequestScopeDefaultBundle(WebResponse response){
244                 formatAndTest(TEST_VAL, response.getText());
245         }
246
247
248     public void testMessageTagNoArgNamePropertyNoScopeAlternateBundle() throws Exception JavaDoc {
249         pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message"), PageContext.REQUEST_SCOPE);
250      runMyTest("testMessageTagNoArgNamePropertyNoScopeAlternateBundle", new Locale JavaDoc("",""));
251         }
252         public void endMessageTagNoArgNamePropertyNoScopeAlternateBundle(WebResponse response){
253                 formatAndTest(TEST_VAL, response.getText());
254         }
255
256     public void testMessageTagNoArgNamePropertyApplicationScopeAlternateBundle() throws Exception JavaDoc {
257         pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message"), PageContext.APPLICATION_SCOPE);
258      runMyTest("testMessageTagNoArgNamePropertyApplicationScopeAlternateBundle", new Locale JavaDoc("",""));
259         }
260         public void endMessageTagNoArgNamePropertyApplicationScopeAlternateBundle(WebResponse response){
261                 formatAndTest(TEST_VAL, response.getText());
262         }
263
264     public void testMessageTagNoArgNamePropertySessionScopeAlternateBundle() throws Exception JavaDoc {
265         pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message"), PageContext.SESSION_SCOPE);
266      runMyTest("testMessageTagNoArgNamePropertySessionScopeAlternateBundle", new Locale JavaDoc("",""));
267         }
268         public void endMessageTagNoArgNamePropertySessionScopeAlternateBundle(WebResponse response){
269                 formatAndTest(TEST_VAL, response.getText());
270         }
271
272     public void testMessageTagNoArgNamePropertyRequestScopeAlternateBundle() throws Exception JavaDoc {
273         pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message"), PageContext.REQUEST_SCOPE);
274      runMyTest("testMessageTagNoArgNamePropertyRequestScopeAlternateBundle", new Locale JavaDoc("",""));
275         }
276         public void endMessageTagNoArgNamePropertyRequestScopeAlternateBundle(WebResponse response){
277                 formatAndTest(TEST_VAL, response.getText());
278         }
279
280
281
282
283
284
285
286
287 }
288
Popular Tags