001: /*
002: * $Id: OptGroupTest.java 539819 2007-05-20 03:06:34Z mrdon $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import java.util.LinkedHashMap;
024:
025: import org.apache.struts2.TestAction;
026: import org.apache.struts2.views.jsp.AbstractUITagTest;
027:
028: /**
029: *
030: */
031: public class OptGroupTest extends AbstractUITagTest {
032:
033: public void testOptGroupSimple() throws Exception {
034: SelectTag selectTag = new SelectTag();
035: selectTag.setName("mySelection");
036: selectTag.setLabel("My Selection");
037: selectTag
038: .setList("%{#{'ONE':'one','TWO':'two','THREE':'three'}}");
039:
040: OptGroupTag optGroupTag1 = new OptGroupTag();
041: optGroupTag1.setLabel("My Label 1");
042: optGroupTag1
043: .setList("%{#{'AAA':'aaa','BBB':'bbb','CCC':'ccc'}}");
044:
045: OptGroupTag optGroupTag2 = new OptGroupTag();
046: optGroupTag2.setLabel("My Label 2");
047: optGroupTag2
048: .setList("%{#{'DDD':'ddd','EEE':'eee','FFF':'fff'}}");
049:
050: selectTag.setPageContext(pageContext);
051: selectTag.doStartTag();
052: optGroupTag1.setPageContext(pageContext);
053: optGroupTag1.doStartTag();
054: optGroupTag1.doEndTag();
055: optGroupTag2.setPageContext(pageContext);
056: optGroupTag2.doStartTag();
057: optGroupTag2.doEndTag();
058: selectTag.doEndTag();
059:
060: //System.out.println(writer.toString());
061: verify(SelectTag.class.getResource("OptGroup-1.txt"));
062: }
063:
064: public void testOptGroupWithSingleSelect() throws Exception {
065:
066: SelectTag selectTag = new SelectTag();
067: selectTag.setName("mySelection");
068: selectTag.setLabel("My Selection");
069: selectTag
070: .setList("%{#{'ONE':'one','TWO':'two','THREE':'three'}}");
071: selectTag.setValue("%{'EEE'}");
072:
073: OptGroupTag optGroupTag1 = new OptGroupTag();
074: optGroupTag1.setLabel("My Label 1");
075: optGroupTag1
076: .setList("%{#{'AAA':'aaa','BBB':'bbb','CCC':'ccc'}}");
077:
078: OptGroupTag optGroupTag2 = new OptGroupTag();
079: optGroupTag2.setLabel("My Label 2");
080: optGroupTag2
081: .setList("%{#{'DDD':'ddd','EEE':'eee','FFF':'fff'}}");
082:
083: selectTag.setPageContext(pageContext);
084: selectTag.doStartTag();
085: optGroupTag1.setPageContext(pageContext);
086: optGroupTag1.doStartTag();
087: optGroupTag1.doEndTag();
088: optGroupTag2.setPageContext(pageContext);
089: optGroupTag2.doStartTag();
090: optGroupTag2.doEndTag();
091: selectTag.doEndTag();
092:
093: //System.out.println(writer.toString());
094: verify(SelectTag.class.getResource("OptGroup-2.txt"));
095: }
096:
097: public void testOptGroupWithMultipleSelect() throws Exception {
098: SelectTag selectTag = new SelectTag();
099: selectTag.setMultiple("true");
100: selectTag.setName("mySelection");
101: selectTag.setLabel("My Selection");
102: selectTag
103: .setList("%{#{'ONE':'one','TWO':'two','THREE':'three'}}");
104: selectTag.setValue("%{{'EEE','BBB','TWO'}}");
105:
106: OptGroupTag optGroupTag1 = new OptGroupTag();
107: optGroupTag1.setLabel("My Label 1");
108: optGroupTag1
109: .setList("%{#{'AAA':'aaa','BBB':'bbb','CCC':'ccc'}}");
110:
111: OptGroupTag optGroupTag2 = new OptGroupTag();
112: optGroupTag2.setLabel("My Label 2");
113: optGroupTag2
114: .setList("%{#{'DDD':'ddd','EEE':'eee','FFF':'fff'}}");
115:
116: selectTag.setPageContext(pageContext);
117: selectTag.doStartTag();
118: optGroupTag1.setPageContext(pageContext);
119: optGroupTag1.doStartTag();
120: optGroupTag1.doEndTag();
121: optGroupTag2.setPageContext(pageContext);
122: optGroupTag2.doStartTag();
123: optGroupTag2.doEndTag();
124: selectTag.doEndTag();
125:
126: //System.out.println(writer.toString());
127: verify(SelectTag.class.getResource("OptGroup-3.txt"));
128: }
129:
130: public void testOptGroupNumbers() throws Exception {
131:
132: ((TestAction) action).setMap(new LinkedHashMap() {
133: {
134: put("AAA", "aaa");
135: put(new Long(111111), "bbb");
136: put("CCC", "ccc");
137: }
138: });
139:
140: SelectTag selectTag = new SelectTag();
141: selectTag.setName("mySelection");
142: selectTag.setLabel("My Selection");
143: selectTag
144: .setList("%{#{'ONE':'one','TWO':'two','THREE':'three'}}");
145:
146: OptGroupTag optGroupTag1 = new OptGroupTag();
147: optGroupTag1.setLabel("My Label 1");
148: optGroupTag1.setList("map");
149:
150: OptGroupTag optGroupTag2 = new OptGroupTag();
151: optGroupTag2.setLabel("My Label 2");
152: optGroupTag2
153: .setList("%{#{'DDD':'ddd','EEE':'eee','FFF':'fff'}}");
154:
155: selectTag.setPageContext(pageContext);
156: selectTag.doStartTag();
157: optGroupTag1.setPageContext(pageContext);
158: optGroupTag1.doStartTag();
159: optGroupTag1.doEndTag();
160: optGroupTag2.setPageContext(pageContext);
161: optGroupTag2.doStartTag();
162: optGroupTag2.doEndTag();
163: selectTag.doEndTag();
164:
165: //System.out.println(writer.toString());
166: verify(SelectTag.class.getResource("OptGroup-4.txt"));
167: }
168: }
|