View Javadoc

    1   /*
    2    * $Id: RadioTest.java 472155 2006-11-07 16:37:43Z tmjee $
    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.HashMap;
    24  import java.util.LinkedHashMap;
    25
    26  import org.apache.struts2.TestAction;
    27  import org.apache.struts2.views.jsp.AbstractUITagTest;
    28
    29
    30  /***
    31   */
    32  public class RadioTest extends AbstractUITagTest {
    33
    34  	public void testMapWithBooleanAsKey() throws Exception {
    35  		TestAction testAction = (TestAction) action;
    36
    37  		HashMap map = new LinkedHashMap();
    38  		map.put(Boolean.TRUE, "male");
    39  		map.put(Boolean.FALSE, "female");
    40  		testAction.setMap(map);
    41
    42  		RadioTag tag = new RadioTag();
    43  		tag.setPageContext(pageContext);
    44  		tag.setLabel("mylabel");
    45  		tag.setName("myname");
    46  		tag.setValue("%{true}");
    47  		tag.setList("map");
    48
    49  		tag.doStartTag();
    50  		tag.doEndTag();
    51
    52  		verify(RadioTag.class.getResource("Radio-3.txt"));
    53  	}
    54
    55      public void testMapChecked() throws Exception {
    56          TestAction testAction = (TestAction) action;
    57          testAction.setFoo("bar");
    58
    59          HashMap map = new HashMap();
    60          map.put("1", "One");
    61          map.put("2", "Two");
    62          testAction.setMap(map);
    63
    64          RadioTag tag = new RadioTag();
    65          tag.setPageContext(pageContext);
    66          tag.setLabel("mylabel");
    67          tag.setName("myname");
    68          tag.setValue("\"1\"");
    69          tag.setList("map");
    70          tag.setListKey("key");
    71          tag.setListValue("value");
    72
    73          tag.doStartTag();
    74          tag.doEndTag();
    75
    76          verify(RadioTag.class.getResource("Radio-2.txt"));
    77      }
    78
    79      public void testSimple() throws Exception {
    80          TestAction testAction = (TestAction) action;
    81          testAction.setFoo("bar");
    82          testAction.setList(new String[][]{
    83                  {"hello", "world"},
    84                  {"foo", "bar"}
    85          });
    86
    87          RadioTag tag = new RadioTag();
    88          tag.setPageContext(pageContext);
    89          tag.setLabel("mylabel");
    90          tag.setName("myname");
    91          tag.setValue("");
    92          tag.setList("list");
    93          tag.setListKey("top[0]");
    94          tag.setListValue("top[1]");
    95
    96          tag.doStartTag();
    97          tag.doEndTag();
    98
    99          verify(RadioTag.class.getResource("Radio-1.txt"));
    100     }
    101
    102     public void testGenericSimple() throws Exception {
    103         RadioTag tag = new RadioTag();
    104         prepareTagGeneric(tag);
    105         verifyGenericProperties(tag, "simple", new String[]{"id","value"});
    106     }
    107
    108     public void testGenericXhtml() throws Exception {
    109         RadioTag tag = new RadioTag();
    110         prepareTagGeneric(tag);
    111         verifyGenericProperties(tag, "xhtml", new String[]{"id","value"});
    112     }
    113
    114     public void testGenericAjax() throws Exception {
    115         RadioTag tag = new RadioTag();
    116         prepareTagGeneric(tag);
    117         verifyGenericProperties(tag, "ajax", new String[]{"id","value"});
    118     }
    119
    120     private void prepareTagGeneric(RadioTag tag) {
    121         TestAction testAction = (TestAction) action;
    122         testAction.setFoo("bar");
    123         testAction.setList(new String[][]{
    124                 {"hello", "world"},
    125                 {"foo", "bar"}
    126         });
    127         tag.setList("list");
    128         tag.setListKey("top[0]");
    129         tag.setListValue("top[1]");
    130     }
    131
    132 }