View Javadoc

    1   /*
    2    * $Id: UpDownSelectTagTest.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 java.util.ArrayList;
    24  import java.util.LinkedHashMap;
    25  import java.util.List;
    26  import java.util.Map;
    27
    28  import org.apache.struts2.views.jsp.AbstractUITagTest;
    29
    30  import com.opensymphony.xwork2.Action;
    31  import com.opensymphony.xwork2.ActionSupport;
    32
    33  /***
    34   * Test case for UpDownSelectTag
    35   *
    36   */
    37  public class UpDownSelectTagTest extends AbstractUITagTest {
    38
    39      public void testWithAllSelected() throws Exception {
    40
    41          UpDownSelectTag tag = new UpDownSelectTag();
    42          tag.setPageContext(pageContext);
    43          tag.setId("myId");
    44          tag.setName("myName");
    45          tag.setList("myMap");
    46          tag.setValue("myAllSelectedMapIds");
    47          tag.setEmptyOption("true");
    48
    49          tag.doStartTag();
    50          tag.doEndTag();
    51
    52          verify(UpDownSelectTagTest.class.getResource("updownselecttag-1.txt"));
    53      }
    54
    55      public void testWithPartialSelected() throws Exception {
    56
    57          UpDownSelectTag tag = new UpDownSelectTag();
    58          tag.setPageContext(pageContext);
    59          tag.setId("myId");
    60          tag.setName("myName");
    61          tag.setList("myMap");
    62          tag.setValue("mySelectedMapIds");
    63          tag.setEmptyOption("false");
    64
    65          tag.doStartTag();
    66          tag.doEndTag();
    67
    68          verify(UpDownSelectTagTest.class.getResource("updownselecttag-2.txt"));
    69      }
    70
    71      public void testWithHeaderAndEmptyOption() throws Exception {
    72
    73          UpDownSelectTag tag = new UpDownSelectTag();
    74          tag.setPageContext(pageContext);
    75          tag.setId("myId");
    76          tag.setName("myName");
    77          tag.setList("myMap");
    78          tag.setValue("mySelectedMapIds");
    79          tag.setEmptyOption("true");
    80          tag.setHeaderKey("-1");
    81          tag.setHeaderValue("--- Please Order ---");
    82
    83          tag.doStartTag();
    84          tag.doEndTag();
    85
    86          verify(UpDownSelectTagTest.class.getResource("updownselecttag-3.txt"));
    87      }
    88
    89      public void testWithHeaderOnly() throws Exception {
    90
    91          UpDownSelectTag tag = new UpDownSelectTag();
    92          tag.setPageContext(pageContext);
    93          tag.setId("myId");
    94          tag.setName("myName");
    95          tag.setList("myMap");
    96          tag.setValue("mySelectedMapIds");
    97          tag.setEmptyOption("false");
    98          tag.setHeaderKey("-1");
    99          tag.setHeaderValue("--- Please Order ---");
    100
    101         tag.doStartTag();
    102         tag.doEndTag();
    103
    104         verify(UpDownSelectTagTest.class.getResource("updownselecttag-4.txt"));
    105     }
    106
    107     public void testWithEmptyOptionOnly() throws Exception {
    108
    109         UpDownSelectTag tag = new UpDownSelectTag();
    110         tag.setPageContext(pageContext);
    111         tag.setId("myId");
    112         tag.setName("myName");
    113         tag.setList("myMap");
    114         tag.setValue("mySelectedMapIds");
    115         tag.setEmptyOption("true");
    116
    117         tag.doStartTag();
    118         tag.doEndTag();
    119
    120         verify(UpDownSelectTagTest.class.getResource("updownselecttag-5.txt"));
    121     }
    122
    123
    124     public void testDisableSomeSelectAllButton() throws Exception {
    125
    126         UpDownSelectTag tag = new UpDownSelectTag();
    127         tag.setPageContext(pageContext);
    128         tag.setId("myId");
    129         tag.setName("myName");
    130         tag.setList("myMap");
    131         tag.setValue("mySelectedMapIds");
    132         tag.setEmptyOption("true");
    133         tag.setAllowSelectAll("false");
    134
    135         tag.doStartTag();
    136         tag.doEndTag();
    137
    138         verify(UpDownSelectTagTest.class.getResource("updownselecttag-6.txt"));
    139     }
    140
    141     public void testDisableMoveUpButton() throws Exception {
    142         UpDownSelectTag tag = new UpDownSelectTag();
    143         tag.setPageContext(pageContext);
    144         tag.setId("myId");
    145         tag.setName("myName");
    146         tag.setList("myMap");
    147         tag.setValue("mySelectedMapIds");
    148         tag.setEmptyOption("true");
    149         tag.setAllowMoveUp("false");
    150
    151         tag.doStartTag();
    152         tag.doEndTag();
    153
    154         verify(UpDownSelectTagTest.class.getResource("updownselecttag-7.txt"));
    155     }
    156
    157     public void testDisableMoveDownButton() throws Exception {
    158         UpDownSelectTag tag = new UpDownSelectTag();
    159         tag.setPageContext(pageContext);
    160         tag.setId("myId");
    161         tag.setName("myName");
    162         tag.setList("myMap");
    163         tag.setValue("mySelectedMapIds");
    164         tag.setEmptyOption("true");
    165         tag.setAllowMoveDown("false");
    166
    167         tag.doStartTag();
    168         tag.doEndTag();
    169
    170         verify(UpDownSelectTagTest.class.getResource("updownselecttag-8.txt"));
    171     }
    172
    173     public void testChangeSelectAllButtonText() throws Exception {
    174         UpDownSelectTag tag = new UpDownSelectTag();
    175         tag.setPageContext(pageContext);
    176         tag.setId("myId");
    177         tag.setName("myName");
    178         tag.setList("myMap");
    179         tag.setValue("mySelectedMapIds");
    180         tag.setEmptyOption("true");
    181         tag.setSelectAllLabel("Select All");
    182
    183         tag.doStartTag();
    184         tag.doEndTag();
    185
    186         verify(UpDownSelectTagTest.class.getResource("updownselecttag-9.txt"));
    187     }
    188
    189     public void testChangeMoveUpButtonText() throws Exception {
    190         UpDownSelectTag tag = new UpDownSelectTag();
    191         tag.setPageContext(pageContext);
    192         tag.setId("myId");
    193         tag.setName("myName");
    194         tag.setList("myMap");
    195         tag.setValue("mySelectedMapIds");
    196         tag.setEmptyOption("true");
    197         tag.setMoveUpLabel("Move Up");
    198
    199         tag.doStartTag();
    200         tag.doEndTag();
    201
    202         verify(UpDownSelectTagTest.class.getResource("updownselecttag-10.txt"));
    203     }
    204
    205     public void testChangeMoveDownButtonText() throws Exception {
    206         UpDownSelectTag tag = new UpDownSelectTag();
    207         tag.setPageContext(pageContext);
    208         tag.setId("myId");
    209         tag.setName("myName");
    210         tag.setList("myMap");
    211         tag.setValue("mySelectedMapIds");
    212         tag.setEmptyOption("true");
    213         tag.setMoveDownLabel("Move Down");
    214
    215         tag.doStartTag();
    216         tag.doEndTag();
    217
    218         verify(UpDownSelectTagTest.class.getResource("updownselecttag-11.txt"));
    219     }
    220
    221     public void testGenericSimple() throws Exception {
    222         UpDownSelectTag tag = new UpDownSelectTag();
    223         prepareTagGeneric(tag);
    224         verifyGenericProperties(tag, "simple", new String[]{"value"});
    225     }
    226
    227     public void testGenericXhtml() throws Exception {
    228         UpDownSelectTag tag = new UpDownSelectTag();
    229         prepareTagGeneric(tag);
    230         verifyGenericProperties(tag, "xhtml", new String[]{"value"});
    231     }
    232
    233     public void testGenericAjax() throws Exception {
    234         UpDownSelectTag tag = new UpDownSelectTag();
    235         prepareTagGeneric(tag);
    236         verifyGenericProperties(tag, "ajax", new String[]{"value"});
    237     }
    238
    239     private void prepareTagGeneric(UpDownSelectTag tag) {
    240         tag.setList("myMap");
    241     }
    242
    243
    244
    245     // ===============================
    246     public Action getAction() {
    247         return new ActionSupport() {
    248
    249             public Map getMyMap() {
    250                 Map _myMap = new LinkedHashMap();
    251                 _myMap.put("england", "England");
    252                 _myMap.put("america", "America");
    253                 _myMap.put("australia", "Australia");
    254                 _myMap.put("germany", "Germany");
    255                 return _myMap;
    256             }
    257
    258             public List getMySelectedMapIds() {
    259                 List _mySelectedMapIds = new ArrayList();
    260                 _mySelectedMapIds.add("america");
    261                 _mySelectedMapIds.add("germany");
    262                 return _mySelectedMapIds;
    263             }
    264
    265             public List getMyAllSelectedMapIds() {
    266                 List _mySelectedMapIds = new ArrayList();
    267                 _mySelectedMapIds.add("england");
    268                 _mySelectedMapIds.add("america");
    269                 _mySelectedMapIds.add("australia");
    270                 _mySelectedMapIds.add("germany");
    271                 return _mySelectedMapIds;
    272             }
    273         };
    274     }
    275 }