KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestOptionsTag1.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.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.JspTestCase;
28 import org.apache.struts.Globals;
29 import org.apache.struts.taglib.SimpleBeanForTesting;
30 import org.apache.struts.util.LabelValueBean;
31
32 /**
33  * Suite of unit tests for the
34  * <code>org.apache.struts.taglib.html.OptionsTag</code> class.
35  *
36  */

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

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

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

62     public static Test suite() {
63         return new TestSuite(TestOptionsTag1.class);
64     }
65
66     private void runTest(String JavaDoc whichTest, String JavaDoc locale) throws Exception JavaDoc {
67         pageContext.setAttribute(Globals.LOCALE_KEY,
68                         new Locale JavaDoc(locale, locale),
69                         PageContext.SESSION_SCOPE);
70
71         pageContext.setAttribute("runTest", whichTest, PageContext.REQUEST_SCOPE);
72         pageContext.forward("/test/org/apache/struts/taglib/html/TestOptionsTag1.jsp");
73     }
74
75     private LabelValueBean[] createArrayOfLVB(){
76         LabelValueBean[] labelValueBeans = new LabelValueBean[5];
77         for (int i = 0; i < 5; i++){
78             labelValueBeans[i] =
79             new LabelValueBean("key" + i, "Test Message " + i);
80         }
81         return labelValueBeans;
82     }
83     
84     private String JavaDoc[] createArrayofStrings(){
85         String JavaDoc[] stringValues = new String JavaDoc[5];
86         for (int i = 0; i < 5; i++){
87             stringValues[i] = "val" + i;
88         }
89         return stringValues;
90     }
91
92     
93     public void testOptionsCollectionArrayItemValueInCollectionProperty() throws Exception JavaDoc {
94         pageContext.setAttribute("arrayOfLVB", createArrayOfLVB(), PageContext.REQUEST_SCOPE);
95         pageContext.setAttribute(Constants.BEAN_KEY,
96                 new SimpleBeanForTesting("key1"), PageContext.REQUEST_SCOPE);
97         runTest("testOptionsCollectionArrayItemValueInCollectionProperty", "");
98     }
99     
100     public void testOptionsCollectionArrayItemValueNotInCollectionProperty() throws Exception JavaDoc {
101         pageContext.setAttribute("arrayOfLVB", createArrayOfLVB(), PageContext.REQUEST_SCOPE);
102         pageContext.setAttribute(Constants.BEAN_KEY,
103                 new SimpleBeanForTesting("key15"), PageContext.REQUEST_SCOPE);
104         runTest("testOptionsCollectionArrayItemValueNotInCollectionProperty", "");
105     }
106
107     
108     public void testOptionsCollectionArrayItemValueInCollectionPropertyLabelProperty() throws Exception JavaDoc {
109         pageContext.setAttribute("arrayOfLVB", createArrayOfLVB(), PageContext.REQUEST_SCOPE);
110         pageContext.setAttribute(Constants.BEAN_KEY,
111                 new SimpleBeanForTesting("key1"), PageContext.REQUEST_SCOPE);
112         runTest("testOptionsCollectionArrayItemValueInCollectionPropertyLabelProperty", "");
113     }
114     
115     public void testOptionsCollectionArrayItemValueNotInCollectionPropertyLabelProperty() throws Exception JavaDoc {
116         pageContext.setAttribute("arrayOfLVB", createArrayOfLVB(), PageContext.REQUEST_SCOPE);
117         pageContext.setAttribute(Constants.BEAN_KEY,
118                 new SimpleBeanForTesting("key15"), PageContext.REQUEST_SCOPE);
119         runTest("testOptionsCollectionArrayItemValueNotInCollectionPropertyLabelProperty", "");
120     }
121     
122
123     public void testOptionsNameArrayItemValueInCollection() throws Exception JavaDoc {
124         pageContext.setAttribute("stringValues", createArrayofStrings(), PageContext.REQUEST_SCOPE);
125         pageContext.setAttribute(Constants.BEAN_KEY,
126                 new SimpleBeanForTesting("val1"), PageContext.REQUEST_SCOPE);
127         runTest("testOptionsNameArrayItemValueInCollection", "");
128     }
129     
130     public void testOptionsNameArrayItemValueNotInCollection() throws Exception JavaDoc {
131         pageContext.setAttribute("stringValues", createArrayofStrings(), PageContext.REQUEST_SCOPE);
132         pageContext.setAttribute(Constants.BEAN_KEY,
133                 new SimpleBeanForTesting("val15"), PageContext.REQUEST_SCOPE);
134         runTest("testOptionsNameArrayItemValueNotInCollection", "");
135     }
136
137     
138     public void testOptionsPropertyArrayItemValueInCollection() throws Exception JavaDoc {
139         SimpleBeanForTesting sbft = new SimpleBeanForTesting("val1");
140         sbft.setStringArray(createArrayofStrings());
141         pageContext.setAttribute(Constants.BEAN_KEY,
142                 sbft, PageContext.REQUEST_SCOPE);
143         runTest("testOptionsPropertyArrayItemValueInCollection", "");
144     }
145     
146     public void testOptionsPropertyArrayItemValueNotInCollection() throws Exception JavaDoc {
147         SimpleBeanForTesting sbft = new SimpleBeanForTesting("val15");
148         sbft.setStringArray(createArrayofStrings());
149         pageContext.setAttribute(Constants.BEAN_KEY,
150                 sbft, PageContext.REQUEST_SCOPE);
151         runTest("testOptionsPropertyArrayItemValueNotInCollection", "");
152     }
153     
154     
155     public void testOptionsNamePropertyArrayItemValueInCollection() throws Exception JavaDoc {
156         pageContext.setAttribute("stringValues",
157             new SimpleBeanForTesting(createArrayofStrings()), PageContext.REQUEST_SCOPE);
158         pageContext.setAttribute(Constants.BEAN_KEY,
159                 new SimpleBeanForTesting("val1"), PageContext.REQUEST_SCOPE);
160         runTest("testOptionsNamePropertyArrayItemValueInCollection", "");
161     }
162     
163     public void testOptionsNamePropertyArrayItemValueNotInCollection() throws Exception JavaDoc {
164         pageContext.setAttribute("stringValues",
165                 new SimpleBeanForTesting(createArrayofStrings()), PageContext.REQUEST_SCOPE);
166         pageContext.setAttribute(Constants.BEAN_KEY,
167                 new SimpleBeanForTesting("val15"), PageContext.REQUEST_SCOPE);
168         runTest("testOptionsNamePropertyArrayItemValueNotInCollection", "");
169     }
170 }
171
Popular Tags