View Javadoc

    1   /*
    2    * $Id: ComboBoxTest.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.TestAction;
    29  import org.apache.struts2.views.jsp.AbstractUITagTest;
    30
    31
    32  /***
    33   * Test case for ComboBox component.
    34   */
    35  public class ComboBoxTest extends AbstractUITagTest {
    36
    37      public void testGenericSimple() throws Exception {
    38          ComboBoxTag tag = new ComboBoxTag();
    39          prepareTagGeneric(tag);
    40          verifyGenericProperties(tag, "simple", null);
    41      }
    42
    43      public void testGenericXhtml() throws Exception {
    44          ComboBoxTag tag = new ComboBoxTag();
    45          prepareTagGeneric(tag);
    46          verifyGenericProperties(tag, "xhtml", null);
    47      }
    48
    49      public void testGenericAjax() throws Exception {
    50          ComboBoxTag tag = new ComboBoxTag();
    51          prepareTagGeneric(tag);
    52          verifyGenericProperties(tag, "ajax", null);
    53      }
    54
    55      private void prepareTagGeneric(ComboBoxTag tag) {
    56          TestAction testAction = (TestAction) action;
    57          ArrayList collection = new ArrayList();
    58          collection.add("foo");
    59          collection.add("bar");
    60          collection.add("baz");
    61
    62          testAction.setCollection(collection);
    63
    64          tag.setList("collection");
    65      }
    66
    67      public void testSimple() throws Exception {
    68          TestAction testAction = (TestAction) action;
    69          testAction.setFoo("hello");
    70
    71          ArrayList collection = new ArrayList();
    72          collection.add("foo");
    73          collection.add("bar");
    74          collection.add("baz");
    75          testAction.setCollection(collection);
    76
    77          ComboBoxTag tag = new ComboBoxTag();
    78          tag.setPageContext(pageContext);
    79          tag.setLabel("mylabel");
    80          tag.setName("foo");
    81          tag.setList("collection");
    82
    83          tag.doStartTag();
    84          tag.doEndTag();
    85
    86          verify(ComboBoxTag.class.getResource("ComboBox-1.txt"));
    87      }
    88
    89      public void testWithEmptyOptionAndHeader() throws Exception {
    90          TestAction testAction = (TestAction) action;
    91          testAction.setFoo("banana");
    92
    93          List l = new ArrayList();
    94          l.add("apple");
    95          l.add("banana");
    96          l.add("pineaple");
    97          l.add("grapes");
    98          testAction.setCollection(l);
    99
    100         ComboBoxTag tag = new ComboBoxTag();
    101         tag.setPageContext(pageContext);
    102         tag.setLabel("My Favourite Fruit");
    103         tag.setName("myFavouriteFruit");
    104         tag.setEmptyOption("true");
    105         tag.setHeaderKey("-1");
    106         tag.setHeaderValue("--- Please Select ---");
    107         tag.setList("collection");
    108         tag.setValue("%{foo}");
    109
    110         tag.doStartTag();
    111         tag.doEndTag();
    112
    113         verify(ComboBoxTag.class.getResource("ComboBox-2.txt"));
    114     }
    115
    116     public void testWithMap() throws Exception {
    117         TestAction testAction = (TestAction) action;
    118         testAction.setFoo("banana");
    119
    120         Map m = new LinkedHashMap();
    121         m.put("apple", "apple");
    122         m.put("banana", "banana");
    123         m.put("pineaple", "pineaple");
    124         m.put("grapes", "grapes");
    125         testAction.setMap(m);
    126
    127         ComboBoxTag tag = new ComboBoxTag();
    128         tag.setPageContext(pageContext);
    129         tag.setLabel("My Favourite Fruit");
    130         tag.setName("myFavouriteFruit");
    131         tag.setHeaderKey("-1");
    132         tag.setHeaderValue("--- Please Select ---");
    133         tag.setEmptyOption("true");
    134         tag.setList("map");
    135         tag.setValue("%{foo}");
    136
    137         tag.doStartTag();
    138         tag.doEndTag();
    139
    140         verify(ComboBoxTag.class.getResource("ComboBox-3.txt"));
    141     }
    142 }