View Javadoc

1   /*
2    * $Id: OptGroupTest.java 471756 2006-11-06 15:01:43Z husted $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts2.views.jsp.ui;
22  
23  import org.apache.struts2.views.jsp.AbstractUITagTest;
24  
25  /***
26   *
27   */
28  public class OptGroupTest extends AbstractUITagTest {
29  
30  
31      public void testOptGroupSimple() throws Exception {
32          SelectTag selectTag = new SelectTag();
33          selectTag.setName("mySelection");
34          selectTag.setLabel("My Selection");
35          selectTag.setList("%{#{'ONE':'one','TWO':'two','THREE':'three'}}");
36  
37          OptGroupTag optGroupTag1 = new OptGroupTag();
38          optGroupTag1.setLabel("My Label 1");
39          optGroupTag1.setList("%{#{'AAA':'aaa','BBB':'bbb','CCC':'ccc'}}");
40  
41          OptGroupTag optGroupTag2 = new OptGroupTag();
42          optGroupTag2.setLabel("My Label 2");
43          optGroupTag2.setList("%{#{'DDD':'ddd','EEE':'eee','FFF':'fff'}}");
44  
45          selectTag.setPageContext(pageContext);
46          selectTag.doStartTag();
47          optGroupTag1.setPageContext(pageContext);
48          optGroupTag1.doStartTag();
49          optGroupTag1.doEndTag();
50          optGroupTag2.setPageContext(pageContext);
51          optGroupTag2.doStartTag();
52          optGroupTag2.doEndTag();
53          selectTag.doEndTag();
54  
55  
56          //System.out.println(writer.toString());
57          verify(SelectTag.class.getResource("OptGroup-1.txt"));
58      }
59  
60  
61      public void testOptGroupWithSingleSelect() throws Exception {
62  
63          SelectTag selectTag = new SelectTag();
64          selectTag.setName("mySelection");
65          selectTag.setLabel("My Selection");
66          selectTag.setList("%{#{'ONE':'one','TWO':'two','THREE':'three'}}");
67          selectTag.setValue("%{'EEE'}");
68  
69          OptGroupTag optGroupTag1 = new OptGroupTag();
70          optGroupTag1.setLabel("My Label 1");
71          optGroupTag1.setList("%{#{'AAA':'aaa','BBB':'bbb','CCC':'ccc'}}");
72  
73          OptGroupTag optGroupTag2 = new OptGroupTag();
74          optGroupTag2.setLabel("My Label 2");
75          optGroupTag2.setList("%{#{'DDD':'ddd','EEE':'eee','FFF':'fff'}}");
76  
77          selectTag.setPageContext(pageContext);
78          selectTag.doStartTag();
79          optGroupTag1.setPageContext(pageContext);
80          optGroupTag1.doStartTag();
81          optGroupTag1.doEndTag();
82          optGroupTag2.setPageContext(pageContext);
83          optGroupTag2.doStartTag();
84          optGroupTag2.doEndTag();
85          selectTag.doEndTag();
86  
87  
88          //System.out.println(writer.toString());
89          verify(SelectTag.class.getResource("OptGroup-2.txt"));
90      }
91  
92  
93      public void testOptGroupWithMultipleSelect() throws Exception {
94          SelectTag selectTag = new SelectTag();
95          selectTag.setMultiple("true");
96          selectTag.setName("mySelection");
97          selectTag.setLabel("My Selection");
98          selectTag.setList("%{#{'ONE':'one','TWO':'two','THREE':'three'}}");
99          selectTag.setValue("%{{'EEE','BBB','TWO'}}");
100 
101         OptGroupTag optGroupTag1 = new OptGroupTag();
102         optGroupTag1.setLabel("My Label 1");
103         optGroupTag1.setList("%{#{'AAA':'aaa','BBB':'bbb','CCC':'ccc'}}");
104 
105         OptGroupTag optGroupTag2 = new OptGroupTag();
106         optGroupTag2.setLabel("My Label 2");
107         optGroupTag2.setList("%{#{'DDD':'ddd','EEE':'eee','FFF':'fff'}}");
108 
109         selectTag.setPageContext(pageContext);
110         selectTag.doStartTag();
111         optGroupTag1.setPageContext(pageContext);
112         optGroupTag1.doStartTag();
113         optGroupTag1.doEndTag();
114         optGroupTag2.setPageContext(pageContext);
115         optGroupTag2.doStartTag();
116         optGroupTag2.doEndTag();
117         selectTag.doEndTag();
118 
119 
120         //System.out.println(writer.toString());
121         verify(SelectTag.class.getResource("OptGroup-3.txt"));
122     }
123 }