KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestDefineTag.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 javax.servlet.jsp.PageContext JavaDoc;
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 import org.apache.cactus.WebResponse;
26 import org.apache.struts.util.LabelValueBean;
27 import org.apache.struts.taglib.TaglibTestBase;
28
29 /**
30  * Suite of unit tests for the
31  * <code>org.apache.struts.taglib.bean.DefineTag</code> class.
32  *
33  */

34 public class TestDefineTag extends TaglibTestBase {
35
36         protected final static String JavaDoc TEST_KEY = "TestDefineTag";
37         protected final static String JavaDoc TEST_VALUE = "Test Value";
38
39     /**
40      * Defines the testcase name for JUnit.
41      *
42      * @param theName the testcase's name.
43      */

44     public TestDefineTag(String JavaDoc theName) {
45         super(theName);
46     }
47
48     /**
49      * Start the tests.
50      *
51      * @param theArgs the arguments. Not used
52      */

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

61     public static Test suite() {
62         // All methods starting with "test" will be executed in the test suite.
63
return new TestSuite(TestDefineTag.class);
64     }
65
66     private void runMyTest(String JavaDoc whichTest) throws Exception JavaDoc{
67         request.setAttribute("runTest", whichTest);
68         pageContext.forward("/test/org/apache/struts/taglib/bean/TestDefineTag.jsp");
69     }
70
71         private void formatAndTest(String JavaDoc compare, String JavaDoc output) {
72                 //fix for introduced carriage return / line feeds
73
output = replace(output,"\r","");
74                 output = replace(output,"\n","");
75                 output = output.trim();
76             assertEquals(compare, output);
77         }
78
79     /*
80      * Testing DefineTag using Application scope, with Application Scope specified in tags.
81      */

82     public void testDefineNameApplicationScope() throws Exception JavaDoc {
83         pageContext.setAttribute(TEST_KEY, TEST_VALUE, PageContext.APPLICATION_SCOPE);
84         runMyTest("testDefineNameApplicationScope");
85         }
86         public void endDefineNameApplicationScope(WebResponse response){
87                 formatAndTest(TEST_VALUE, response.getText());
88         }
89
90     public void testDefineNamePropertyApplicationScope() throws Exception JavaDoc {
91         LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE);
92         pageContext.setAttribute(TEST_KEY, lvb, PageContext.APPLICATION_SCOPE);
93         runMyTest("testDefineNamePropertyApplicationScope");
94         }
95         public void endDefineNamePropertyApplicationScope(WebResponse response){
96                 formatAndTest(TEST_VALUE, response.getText());
97         }
98
99     public void testDefineValueApplicationScope() throws Exception JavaDoc {
100         LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE + " this will be set to the correct value");
101         pageContext.setAttribute(TEST_KEY, lvb, PageContext.APPLICATION_SCOPE);
102         runMyTest("testDefineValueApplicationScope");
103         }
104         public void endDefineValueApplicationScope(WebResponse response){
105                 formatAndTest(TEST_VALUE, response.getText());
106         }
107
108     public void testDefineBodyApplicationScope() throws Exception JavaDoc {
109         runMyTest("testDefineBodyApplicationScope");
110         }
111         public void endDefineBodyApplicationScope(WebResponse response){
112                 formatAndTest(TEST_VALUE, response.getText());
113         }
114
115
116     /*
117      * Testing DefineTag using Session scope, with Session Scope specified in tags.
118      */

119     public void testDefineNameSessionScope() throws Exception JavaDoc {
120         pageContext.setAttribute(TEST_KEY, TEST_VALUE, PageContext.SESSION_SCOPE);
121         runMyTest("testDefineNameSessionScope");
122         }
123         public void endDefineNameSessionScope(WebResponse response){
124                 formatAndTest(TEST_VALUE, response.getText());
125         }
126
127     public void testDefineNamePropertySessionScope() throws Exception JavaDoc {
128         LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE);
129         pageContext.setAttribute(TEST_KEY, lvb, PageContext.SESSION_SCOPE);
130         runMyTest("testDefineNamePropertySessionScope");
131         }
132         public void endDefineNamePropertySessionScope(WebResponse response){
133                 formatAndTest(TEST_VALUE, response.getText());
134         }
135
136     public void testDefineValueSessionScope() throws Exception JavaDoc {
137         LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE + " this will be set to the correct value");
138         pageContext.setAttribute(TEST_KEY, lvb, PageContext.SESSION_SCOPE);
139         runMyTest("testDefineValueSessionScope");
140         }
141         public void endDefineValueSessionScope(WebResponse response){
142                 formatAndTest(TEST_VALUE, response.getText());
143         }
144
145     public void testDefineBodySessionScope() throws Exception JavaDoc {
146         runMyTest("testDefineBodySessionScope");
147         }
148         public void endDefineBodySessionScope(WebResponse response){
149                 formatAndTest(TEST_VALUE, response.getText());
150         }
151
152     /*
153      * Testing DefineTag using Request scope, with Request Scope specified in tags.
154      */

155     public void testDefineNameRequestScope() throws Exception JavaDoc {
156         pageContext.setAttribute(TEST_KEY, TEST_VALUE, PageContext.REQUEST_SCOPE);
157         runMyTest("testDefineNameRequestScope");
158         }
159         public void endDefineNameRequestScope(WebResponse response){
160                 formatAndTest(TEST_VALUE, response.getText());
161         }
162
163     public void testDefineNamePropertyRequestScope() throws Exception JavaDoc {
164         LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE);
165         pageContext.setAttribute(TEST_KEY, lvb, PageContext.REQUEST_SCOPE);
166         runMyTest("testDefineNamePropertyRequestScope");
167         }
168         public void endDefineNamePropertyRequestScope(WebResponse response){
169                 formatAndTest(TEST_VALUE, response.getText());
170         }
171
172     public void testDefineValueRequestScope() throws Exception JavaDoc {
173         LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE + " this will be set to the correct value");
174         pageContext.setAttribute(TEST_KEY, lvb, PageContext.REQUEST_SCOPE);
175         runMyTest("testDefineValueRequestScope");
176         }
177         public void endDefineValueRequestScope(WebResponse response){
178                 formatAndTest(TEST_VALUE, response.getText());
179         }
180
181     public void testDefineBodyRequestScope() throws Exception JavaDoc {
182         runMyTest("testDefineBodyRequestScope");
183         }
184         public void endDefineBodyRequestScope(WebResponse response){
185                 formatAndTest(TEST_VALUE, response.getText());
186         }
187
188     /*
189      * Testing DefineTag using Request scope, with no Scope specified in tags.
190      */

191     public void testDefineNameNoScope() throws Exception JavaDoc {
192         request.setAttribute(TEST_KEY, TEST_VALUE);
193         runMyTest("testDefineNameNoScope");
194         }
195         public void endDefineNameNoScope(WebResponse response){
196                 formatAndTest(TEST_VALUE, response.getText());
197         }
198
199     public void testDefineNamePropertyNoScope() throws Exception JavaDoc {
200         LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE);
201         request.setAttribute(TEST_KEY, lvb);
202         runMyTest("testDefineNamePropertyNoScope");
203         }
204         public void endDefineNamePropertyNoScope(WebResponse response){
205                 formatAndTest(TEST_VALUE, response.getText());
206         }
207
208     public void testDefineValueNoScope() throws Exception JavaDoc {
209         LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE + " this will be set to the correct value");
210         request.setAttribute(TEST_KEY, lvb);
211         runMyTest("testDefineValueNoScope");
212         }
213         public void endDefineValueNoScope(WebResponse response){
214                 formatAndTest(TEST_VALUE, response.getText());
215         }
216
217     public void testDefineBodyNoScope() throws Exception JavaDoc {
218         runMyTest("testDefineBodyNoScope");
219         }
220         public void endDefineBodyNoScope(WebResponse response){
221                 formatAndTest(TEST_VALUE, response.getText());
222         }
223
224
225
226
227 }
228
Popular Tags