KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > html > TestLinkTag5


1 /*
2  * $Id: TestLinkTag5.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.html;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Locale JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
24
25 import javax.servlet.jsp.PageContext JavaDoc;
26
27 import junit.framework.Test;
28 import junit.framework.TestSuite;
29
30 import org.apache.cactus.JspTestCase;
31 import org.apache.struts.Globals;
32 import org.apache.struts.taglib.SimpleBeanForTesting;
33
34 /**
35  * Suite of unit tests for the
36  * <code>org.apache.struts.taglib.html.LinkTag</code> class.
37  *
38  */

39 public class TestLinkTag5 extends JspTestCase {
40
41     /**
42      * Defines the testcase name for JUnit.
43      *
44      * @param theName the testcase's name.
45      */

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

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

63     public static Test suite() {
64         // All methods starting with "test" will be executed in the test suite.
65
return new TestSuite(TestLinkTag5.class);
66     }
67
68     private void runMyTest(String JavaDoc whichTest, String JavaDoc locale) throws Exception JavaDoc {
69         pageContext.setAttribute(Globals.LOCALE_KEY, new Locale JavaDoc(locale, locale), PageContext.SESSION_SCOPE);
70         request.setAttribute("runTest", whichTest);
71         pageContext.forward("/test/org/apache/struts/taglib/html/TestLinkTag5.jsp");
72     }
73
74     /*
75      * Testing LinkTag.
76      */

77
78 //--------Testing attributes using forward------
79

80     public void testLinkHref() throws Exception JavaDoc {
81         runMyTest("testLinkHref", "");
82     }
83
84     public void testLinkHrefAccesskey() throws Exception JavaDoc {
85         runMyTest("testLinkHrefAccesskey", "");
86     }
87
88     public void testLinkHrefAnchor() throws Exception JavaDoc {
89         runMyTest("testLinkHrefAnchor", "");
90     }
91
92     public void testLinkHrefIndexedArray() throws Exception JavaDoc {
93         ArrayList JavaDoc lst = new ArrayList JavaDoc();
94         lst.add("Test Message");
95         pageContext.setAttribute("lst", lst, PageContext.REQUEST_SCOPE);
96         runMyTest("testLinkHrefIndexedArray", "");
97         }
98
99     public void testLinkHrefIndexedArrayProperty() throws Exception JavaDoc {
100         SimpleBeanForTesting sbft = new SimpleBeanForTesting();
101         ArrayList JavaDoc lst = new ArrayList JavaDoc();
102         lst.add("Test Message");
103         sbft.setList(lst);
104         pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE);
105         runMyTest("testLinkHrefIndexedArrayProperty", "");
106         }
107
108     public void testLinkHrefIndexedMap() throws Exception JavaDoc {
109         HashMap JavaDoc map = new HashMap JavaDoc();
110         map.put("tst1", "Test Message");
111         pageContext.setAttribute("lst", map, PageContext.REQUEST_SCOPE);
112         runMyTest("testLinkHrefIndexedMap", "");
113         }
114
115     public void testLinkHrefIndexedMapProperty() throws Exception JavaDoc {
116         SimpleBeanForTesting sbft = new SimpleBeanForTesting();
117         HashMap JavaDoc map = new HashMap JavaDoc();
118         map.put("tst1", "Test Message");
119         sbft.setMap(map);
120         pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE);
121         runMyTest("testLinkHrefIndexedMapProperty", "");
122         }
123
124     public void testLinkHrefIndexedEnumeration() throws Exception JavaDoc {
125         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc("Test Message");
126         pageContext.setAttribute("lst", st, PageContext.REQUEST_SCOPE);
127         runMyTest("testLinkHrefIndexedEnumeration", "");
128         }
129
130     public void testLinkHrefIndexedEnumerationProperty() throws Exception JavaDoc {
131         SimpleBeanForTesting sbft = new SimpleBeanForTesting();
132         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc("Test Message");
133         sbft.setEnumeration(st);
134         pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE);
135         runMyTest("testLinkHrefIndexedEnumerationProperty", "");
136         }
137
138
139     public void testLinkHrefIndexedAlternateIdArray() throws Exception JavaDoc {
140         ArrayList JavaDoc lst = new ArrayList JavaDoc();
141         lst.add("Test Message");
142         pageContext.setAttribute("lst", lst, PageContext.REQUEST_SCOPE);
143         runMyTest("testLinkHrefIndexedAlternateIdArray", "");
144         }
145
146     public void testLinkHrefIndexedAlternateIdArrayProperty() throws Exception JavaDoc {
147         SimpleBeanForTesting sbft = new SimpleBeanForTesting();
148         ArrayList JavaDoc lst = new ArrayList JavaDoc();
149         lst.add("Test Message");
150         sbft.setList(lst);
151         pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE);
152         runMyTest("testLinkHrefIndexedAlternateIdArrayProperty", "");
153         }
154
155     public void testLinkHrefIndexedAlternateIdMap() throws Exception JavaDoc {
156         HashMap JavaDoc map = new HashMap JavaDoc();
157         map.put("tst1", "Test Message");
158         pageContext.setAttribute("lst", map, PageContext.REQUEST_SCOPE);
159         runMyTest("testLinkHrefIndexedAlternateIdMap", "");
160         }
161
162     public void testLinkHrefIndexedAlternateIdMapProperty() throws Exception JavaDoc {
163         SimpleBeanForTesting sbft = new SimpleBeanForTesting();
164         HashMap JavaDoc map = new HashMap JavaDoc();
165         map.put("tst1", "Test Message");
166         sbft.setMap(map);
167         pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE);
168         runMyTest("testLinkHrefIndexedAlternateIdMapProperty", "");
169         }
170
171     public void testLinkHrefIndexedAlternateIdEnumeration() throws Exception JavaDoc {
172         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc("Test Message");
173         pageContext.setAttribute("lst", st, PageContext.REQUEST_SCOPE);
174         runMyTest("testLinkHrefIndexedAlternateIdEnumeration", "");
175         }
176
177     public void testLinkHrefIndexedAlternateIdEnumerationProperty() throws Exception JavaDoc {
178         SimpleBeanForTesting sbft = new SimpleBeanForTesting();
179         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc("Test Message");
180         sbft.setEnumeration(st);
181         pageContext.setAttribute("lst", sbft, PageContext.REQUEST_SCOPE);
182         runMyTest("testLinkHrefIndexedAlternateIdEnumerationProperty", "");
183         }
184
185     public void testLinkHrefLinkName() throws Exception JavaDoc {
186        runMyTest("testLinkHrefLinkName", "");
187     }
188
189     public void testLinkHrefNameNoScope() throws Exception JavaDoc {
190                 HashMap JavaDoc map = new HashMap JavaDoc();
191                 map.put("param1","value1");
192                 map.put("param2","value2");
193                 map.put("param3","value3");
194                 map.put("param4","value4");
195                 pageContext.setAttribute("paramMap", map, PageContext.REQUEST_SCOPE);
196        runMyTest("testLinkHrefNameNoScope", "");
197     }
198
199     public void testLinkHrefNamePropertyNoScope() throws Exception JavaDoc {
200                 HashMap JavaDoc map = new HashMap JavaDoc();
201                 map.put("param1","value1");
202                 map.put("param2","value2");
203                 map.put("param3","value3");
204                 map.put("param4","value4");
205                 SimpleBeanForTesting sbft = new SimpleBeanForTesting(map);
206                 pageContext.setAttribute("paramPropertyMap", sbft, PageContext.REQUEST_SCOPE);
207        runMyTest("testLinkHrefNamePropertyNoScope", "");
208     }
209
210     public void testLinkHrefNameApplicationScope() throws Exception JavaDoc {
211                 HashMap JavaDoc map = new HashMap JavaDoc();
212                 map.put("param1","value1");
213                 map.put("param2","value2");
214                 map.put("param3","value3");
215                 map.put("param4","value4");
216                 pageContext.setAttribute("paramMap", map, PageContext.APPLICATION_SCOPE);
217        runMyTest("testLinkHrefNameApplicationScope", "");
218     }
219
220     public void testLinkHrefNamePropertyApplicationScope() throws Exception JavaDoc {
221                 HashMap JavaDoc map = new HashMap JavaDoc();
222                 map.put("param1","value1");
223                 map.put("param2","value2");
224                 map.put("param3","value3");
225                 map.put("param4","value4");
226                 SimpleBeanForTesting sbft = new SimpleBeanForTesting(map);
227                 pageContext.setAttribute("paramPropertyMap", sbft, PageContext.APPLICATION_SCOPE);
228        runMyTest("testLinkHrefNamePropertyApplicationScope", "");
229     }
230
231     public void testLinkHrefNameSessionScope() throws Exception JavaDoc {
232                 HashMap JavaDoc map = new HashMap JavaDoc();
233                 map.put("param1","value1");
234                 map.put("param2","value2");
235                 map.put("param3","value3");
236                 map.put("param4","value4");
237                 pageContext.setAttribute("paramMap", map, PageContext.SESSION_SCOPE);
238        runMyTest("testLinkHrefNameSessionScope", "");
239     }
240
241     public void testLinkHrefNamePropertySessionScope() throws Exception JavaDoc {
242                 HashMap JavaDoc map = new HashMap JavaDoc();
243                 map.put("param1","value1");
244                 map.put("param2","value2");
245                 map.put("param3","value3");
246                 map.put("param4","value4");
247                 SimpleBeanForTesting sbft = new SimpleBeanForTesting(map);
248                 pageContext.setAttribute("paramPropertyMap", sbft, PageContext.SESSION_SCOPE);
249        runMyTest("testLinkHrefNamePropertySessionScope", "");
250     }
251
252     public void testLinkHrefNameRequestScope() throws Exception JavaDoc {
253                 HashMap JavaDoc map = new HashMap JavaDoc();
254                 map.put("param1","value1");
255                 map.put("param2","value2");
256                 map.put("param3","value3");
257                 map.put("param4","value4");
258                 pageContext.setAttribute("paramMap", map, PageContext.REQUEST_SCOPE);
259        runMyTest("testLinkHrefNameRequestScope", "");
260     }
261
262     public void testLinkHrefNamePropertyRequestScope() throws Exception JavaDoc {
263                 HashMap JavaDoc map = new HashMap JavaDoc();
264                 map.put("param1","value1");
265                 map.put("param2","value2");
266                 map.put("param3","value3");
267                 map.put("param4","value4");
268                 SimpleBeanForTesting sbft = new SimpleBeanForTesting(map);
269                 pageContext.setAttribute("paramPropertyMap", sbft, PageContext.REQUEST_SCOPE);
270        runMyTest("testLinkHrefNamePropertyRequestScope", "");
271     }
272
273 }
274
Popular Tags