View Javadoc

    1   /*
    2    * $Id: CheckboxListTest.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.Collection;
    25  import java.util.Map;
    26
    27  import org.apache.struts2.TestAction;
    28  import org.apache.struts2.views.jsp.AbstractUITagTest;
    29
    30
    31  /***
    32   * Test case for CheckboxList.
    33   *
    34   */
    35  public class CheckboxListTest extends AbstractUITagTest {
    36
    37      /***
    38       * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
    39       * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
    40       * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
    41       *
    42       * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
    43       *         as key.
    44       */
    45      protected Map initializedGenericTagTestProperties() {
    46          Map result = super.initializedGenericTagTestProperties();
    47          new PropertyHolder("value", "hello").addToMap(result);
    48          return result;
    49      }
    50
    51      public void testGenericSimple() throws Exception {
    52          CheckboxListTag tag = new CheckboxListTag();
    53          prepareTagGeneric(tag);
    54          verifyGenericProperties(tag, "simple", new String[]{"tabindex","cssClass","cssStyle","id"});
    55      }
    56
    57      public void testGenericXhtml() throws Exception {
    58          CheckboxListTag tag = new CheckboxListTag();
    59          prepareTagGeneric(tag);
    60          verifyGenericProperties(tag, "xhtml", new String[]{"tabindex","cssClass","cssStyle","id"});
    61      }
    62
    63      public void testGenericAjax() throws Exception {
    64          CheckboxListTag tag = new CheckboxListTag();
    65          prepareTagGeneric(tag);
    66          verifyGenericProperties(tag, "ajax", new String[]{"tabindex","cssClass","cssStyle","id"});
    67      }
    68
    69      private void prepareTagGeneric(CheckboxListTag tag) {
    70          TestAction testAction = (TestAction) action;
    71          Collection collection = new ArrayList(2);
    72          collection.add("hello");
    73          collection.add("foo");
    74          testAction.setCollection(collection);
    75          testAction.setList(new String[][]{
    76                  {"hello", "world"},
    77                  {"foo", "bar"},
    78          });
    79          tag.setName("collection");
    80          tag.setList("list");
    81          tag.setListKey("top[0]");
    82          tag.setListValue("top[1]");
    83      }
    84
    85      public void testMultiple() throws Exception {
    86          TestAction testAction = (TestAction) action;
    87          Collection collection = new ArrayList(2);
    88          collection.add("hello");
    89          collection.add("foo");
    90          testAction.setCollection(collection);
    91          testAction.setList(new String[][]{
    92                  {"hello", "world"},
    93                  {"foo", "bar"},
    94                  {"cat", "dog"}
    95          });
    96
    97          CheckboxListTag tag = new CheckboxListTag();
    98          tag.setPageContext(pageContext);
    99          tag.setLabel("mylabel");
    100         tag.setName("collection");
    101         tag.setList("list");
    102         tag.setListKey("top[0]");
    103         tag.setListValue("top[1]");
    104
    105         tag.doStartTag();
    106         tag.doEndTag();
    107
    108         verify(CheckboxListTag.class.getResource("CheckboxList-2.txt"));
    109     }
    110
    111     public void testMultipleWithDisabledOn() throws Exception {
    112         TestAction testAction = (TestAction) action;
    113         Collection collection = new ArrayList(2);
    114         collection.add("hello");
    115         collection.add("foo");
    116         testAction.setCollection(collection);
    117         testAction.setList(new String[][]{
    118                 {"hello", "world"},
    119                 {"foo", "bar"},
    120                 {"cat", "dog"}
    121         });
    122
    123         CheckboxListTag tag = new CheckboxListTag();
    124         tag.setPageContext(pageContext);
    125         tag.setLabel("mylabel");
    126         tag.setName("collection");
    127         tag.setList("list");
    128         tag.setListKey("top[0]");
    129         tag.setListValue("top[1]");
    130         tag.setDisabled("true");
    131
    132         tag.doStartTag();
    133         tag.doEndTag();
    134
    135         verify(CheckboxListTag.class.getResource("CheckboxList-3.txt"));
    136     }
    137
    138     public void testSimple() throws Exception {
    139         TestAction testAction = (TestAction) action;
    140         testAction.setFoo("hello");
    141         testAction.setList(new String[][]{
    142                 {"hello", "world"},
    143                 {"foo", "bar"}
    144         });
    145
    146         CheckboxListTag tag = new CheckboxListTag();
    147         tag.setPageContext(pageContext);
    148         tag.setLabel("mylabel");
    149         tag.setName("foo");
    150         tag.setList("list");
    151         tag.setListKey("top[0]");
    152         tag.setListValue("top[1]");
    153         tag.setOnchange("alert('foo');");
    154         tag.setTitle("mytitle");
    155
    156         tag.doStartTag();
    157         tag.doEndTag();
    158
    159         verify(CheckboxListTag.class.getResource("CheckboxList-1.txt"));
    160     }
    161
    162     public void testSimpleWithDisableOn() throws Exception {
    163         TestAction testAction = (TestAction) action;
    164         testAction.setFoo("hello");
    165         testAction.setList(new String[][]{
    166                 {"hello", "world"},
    167                 {"foo", "bar"}
    168         });
    169
    170         CheckboxListTag tag = new CheckboxListTag();
    171         tag.setPageContext(pageContext);
    172         tag.setLabel("mylabel");
    173         tag.setName("foo");
    174         tag.setList("list");
    175         tag.setListKey("top[0]");
    176         tag.setListValue("top[1]");
    177         tag.setOnchange("alert('foo');");
    178         tag.setDisabled("true");
    179
    180         tag.doStartTag();
    181         tag.doEndTag();
    182
    183         verify(CheckboxListTag.class.getResource("CheckboxList-4.txt"));
    184     }
    185 }