KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

44     public TestImgTag1a(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[] {TestImgTag1a.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(TestImgTag1a.class);
64     }
65
66     private void runMyTest(String JavaDoc whichTest, String JavaDoc locale) throws Exception JavaDoc {
67         pageContext.setAttribute(Globals.LOCALE_KEY, new Locale JavaDoc(locale, locale), PageContext.SESSION_SCOPE);
68         pageContext.setAttribute(Constants.BEAN_KEY, new SimpleBeanForTesting("Test Value"), PageContext.REQUEST_SCOPE);
69         request.setAttribute("runTest", whichTest);
70         pageContext.forward("/test/org/apache/struts/taglib/html/TestImgTag1a.jsp");
71     }
72
73     /*
74      * Testing ImgTag.
75      */

76
77 //--------Testing attributes using page------
78

79     public void testImgPageNameNoScope() throws Exception JavaDoc {
80                 HashMap JavaDoc map = new HashMap JavaDoc();
81                 map.put("param1","value1");
82                 map.put("param2","value2");
83                 map.put("param3","value3");
84                 map.put("param4","value4");
85                 pageContext.setAttribute("paramMapNoScope", map, PageContext.REQUEST_SCOPE);
86        runMyTest("testImgPageNameNoScope", "");
87     }
88
89     public void testImgPageNamePropertyNoScope() throws Exception JavaDoc {
90                 HashMap JavaDoc map = new HashMap JavaDoc();
91                 map.put("param1","value1");
92                 map.put("param2","value2");
93                 map.put("param3","value3");
94                 map.put("param4","value4");
95                 SimpleBeanForTesting sbft = new SimpleBeanForTesting(map);
96                 pageContext.setAttribute("paramPropertyMapNoScope", sbft, PageContext.REQUEST_SCOPE);
97        runMyTest("testImgPageNamePropertyNoScope", "");
98     }
99
100     public void testImgPageNameApplicationScope() throws Exception JavaDoc {
101                 HashMap JavaDoc map = new HashMap JavaDoc();
102                 map.put("param1","value1");
103                 map.put("param2","value2");
104                 map.put("param3","value3");
105                 map.put("param4","value4");
106                 pageContext.setAttribute("paramMapApplicationScope", map, PageContext.APPLICATION_SCOPE);
107        runMyTest("testImgPageNameApplicationScope", "");
108     }
109
110     public void testImgPageNamePropertyApplicationScope() throws Exception JavaDoc {
111                 HashMap JavaDoc map = new HashMap JavaDoc();
112                 map.put("param1","value1");
113                 map.put("param2","value2");
114                 map.put("param3","value3");
115                 map.put("param4","value4");
116                 SimpleBeanForTesting sbft = new SimpleBeanForTesting(map);
117                 pageContext.setAttribute("paramPropertyMapApplicationScope", sbft, PageContext.APPLICATION_SCOPE);
118        runMyTest("testImgPageNamePropertyApplicationScope", "");
119     }
120
121     public void testImgPageNameSessionScope() throws Exception JavaDoc {
122                 HashMap JavaDoc map = new HashMap JavaDoc();
123                 map.put("param1","value1");
124                 map.put("param2","value2");
125                 map.put("param3","value3");
126                 map.put("param4","value4");
127                 pageContext.setAttribute("paramMapSessionScope", map, PageContext.SESSION_SCOPE);
128        runMyTest("testImgPageNameSessionScope", "");
129     }
130
131     public void testImgPageNamePropertySessionScope() throws Exception JavaDoc {
132                 HashMap JavaDoc map = new HashMap JavaDoc();
133                 map.put("param1","value1");
134                 map.put("param2","value2");
135                 map.put("param3","value3");
136                 map.put("param4","value4");
137                 SimpleBeanForTesting sbft = new SimpleBeanForTesting(map);
138                 pageContext.setAttribute("paramPropertyMapSessionScope", sbft, PageContext.SESSION_SCOPE);
139        runMyTest("testImgPageNamePropertySessionScope", "");
140     }
141
142     public void testImgPageNameRequestScope() throws Exception JavaDoc {
143                 HashMap JavaDoc map = new HashMap JavaDoc();
144                 map.put("param1","value1");
145                 map.put("param2","value2");
146                 map.put("param3","value3");
147                 map.put("param4","value4");
148                 pageContext.setAttribute("paramMapRequestScope", map, PageContext.REQUEST_SCOPE);
149        runMyTest("testImgPageNameRequestScope", "");
150     }
151
152     public void testImgPageNamePropertyRequestScope() throws Exception JavaDoc {
153                 HashMap JavaDoc map = new HashMap JavaDoc();
154                 map.put("param1","value1");
155                 map.put("param2","value2");
156                 map.put("param3","value3");
157                 map.put("param4","value4");
158                 SimpleBeanForTesting sbft = new SimpleBeanForTesting(map);
159                 pageContext.setAttribute("paramPropertyMapRequestScope", sbft, PageContext.REQUEST_SCOPE);
160        runMyTest("testImgPageNamePropertyRequestScope", "");
161     }
162
163
164
165 }
166
Popular Tags