View Javadoc

    1   /*
    2    * $Id: TooltipTest.java 474191 2006-11-13 08:30:40Z mrdon $
    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
    25  import org.apache.struts2.TestConfigurationProvider;
    26  import org.apache.struts2.views.jsp.AbstractUITagTest;
    27  import org.apache.struts2.views.jsp.ParamTag;
    28  import org.apache.struts2.views.jsp.StrutsMockBodyContent;
    29
    30  import com.mockobjects.servlet.MockJspWriter;
    31
    32  /***
    33   * UI components Tooltip test case.
    34   */
    35  public class TooltipTest extends AbstractUITagTest {
    36
    37      public void testWithoutFormOverriding() throws Exception {
    38
    39          // we test it on textfield component, but since the tooltip are common to
    40          // all components, it will be the same for other components as well.
    41          FormTag formTag = new FormTag();
    42          formTag.setPageContext(pageContext);
    43          formTag.setId("myFormId");
    44          formTag.setAction("testAction");
    45          formTag.setName("myForm");
    46
    47
    48          TextFieldTag tag = new TextFieldTag();
    49          tag.setPageContext(pageContext);
    50          tag.setLabel("MyLabel");
    51          tag.setId("myId");
    52
    53
    54          tag.setTooltip("myTooltip");
    55          tag.setTooltipConfig(
    56                  "#{" +
    57                          "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
    58                          "'tooltipDelay':'500', " +
    59                          "'jsTooltipEnabled':'true' "+
    60                          "}"
    61          );
    62
    63          formTag.doStartTag();
    64          tag.doStartTag();
    65          tag.doEndTag();
    66          formTag.doEndTag();
    67
    68          verify(TooltipTest.class.getResource("tooltip-1.txt"));
    69      }
    70
    71      public void testWithFormOverriding() throws Exception {
    72
    73          FormTag formTag = new FormTag();
    74          formTag.setPageContext(pageContext);
    75          formTag.setName("myForm");
    76          formTag.setId("myFormId");
    77          formTag.setAction("testAction");
    78
    79          formTag.setTooltipConfig(
    80                  "#{" +
    81                  "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
    82                  "'tooltipDelay':'500', " +
    83                  "'jsTooltipEnabled':'true' "+
    84                  "}"
    85          );
    86
    87
    88          TextFieldTag tag = new TextFieldTag();
    89          tag.setPageContext(pageContext);
    90          tag.setLabel("MyLabel");
    91          tag.setId("myId");
    92
    93          tag.setTooltip("myTooltip");
    94
    95          formTag.doStartTag();
    96          tag.doStartTag();
    97          tag.doEndTag();
    98          formTag.doEndTag();
    99
    100         verify(TooltipTest.class.getResource("tooltip-2.txt"));
    101     }
    102
    103     public void testWithPartialFormOverriding() throws Exception {
    104
    105         FormTag formTag = new FormTag();
    106         formTag.setName("myForm");
    107         formTag.setPageContext(pageContext);
    108         formTag.setId("myFormId");
    109         formTag.setAction("testAction");
    110
    111         formTag.setTooltipConfig(
    112                 "#{" +
    113                 "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
    114                 "'tooltipDelay':'500', " +
    115                 "'jsTooltipEnabled':'true' "+
    116                 "}"
    117         );
    118
    119
    120         TextFieldTag tag = new TextFieldTag();
    121         tag.setPageContext(pageContext);
    122         tag.setLabel("MyLabel");
    123         tag.setId("myId");
    124
    125         tag.setTooltip("myTooltip");
    126         tag.setTooltipConfig(
    127                 "#{" +
    128                 "'tooltipIcon':'/struts/tooltip/myTooltip2.gif', " +
    129                 "'tooltipDelay':'5000' " +
    130                 "}"
    131         );
    132
    133         formTag.doStartTag();
    134         tag.doStartTag();
    135         tag.doEndTag();
    136         formTag.doEndTag();
    137
    138         verify(TooltipTest.class.getResource("tooltip-3.txt"));
    139     }
    140
    141
    142     public void testUsingParamValueToSetConfigurations() throws Exception {
    143         FormTag formTag = new FormTag();
    144         formTag.setName("myForm");
    145         formTag.setPageContext(pageContext);
    146         formTag.setId("myFormId");
    147         formTag.setAction("testAction");
    148
    149
    150         ParamTag formParamTag = new ParamTag();
    151         formParamTag.setPageContext(pageContext);
    152         formParamTag.setName("tooltipConfig");
    153         formParamTag.setValue(
    154                 "#{" +
    155                 "'tooltipIcon':'/struts/tooltip/myTooltip.gif', " +
    156                 "'tooltipDelay':'500', " +
    157                 "'jsTooltipEnabled':'true' "+
    158                 "}"
    159         );
    160
    161
    162         TextFieldTag tag = new TextFieldTag();
    163         tag.setPageContext(pageContext);
    164         tag.setLabel("MyLabel");
    165         tag.setId("myId");
    166         tag.setTooltip("myTooltip");
    167
    168         ParamTag textFieldParamTag = new ParamTag();
    169         textFieldParamTag.setPageContext(pageContext);
    170         textFieldParamTag.setName("tooltipConfig");
    171         textFieldParamTag.setValue(
    172                 "#{" +
    173                 "'tooltipIcon':'/struts/tooltip/myTooltip2.gif', " +
    174                 "'tooltipDelay':'5000' "+
    175                 "}"
    176         );
    177
    178         formTag.doStartTag();
    179         formParamTag.doStartTag();
    180         formParamTag.doEndTag();
    181         tag.doStartTag();
    182         textFieldParamTag.doStartTag();
    183         textFieldParamTag.doEndTag();
    184         tag.doEndTag();
    185         formTag.doEndTag();
    186
    187         verify(TooltipTest.class.getResource("tooltip-3.txt"));
    188     }
    189
    190
    191     public void testUsingParamBodyValueToSetConfigurations() throws Exception {
    192
    193         FormTag formTag = new FormTag();
    194         formTag.setName("myForm");
    195         formTag.setPageContext(pageContext);
    196         formTag.setId("myFormId");
    197         formTag.setAction("testAction");
    198
    199
    200         ParamTag formParamTag = new ParamTag();
    201         formParamTag.setPageContext(pageContext);
    202         formParamTag.setName("tooltipConfig");
    203         StrutsMockBodyContent bodyContent = new StrutsMockBodyContent(new MockJspWriter());
    204         bodyContent.setString(
    205                 "tooltipIcon=/struts/tooltip/myTooltip.gif| " +
    206                 "tooltipDelay=500| " +
    207                 "jsTooltipEnabled=true "
    208         );
    209         formParamTag.setBodyContent(bodyContent);
    210
    211         TextFieldTag tag = new TextFieldTag();
    212         tag.setPageContext(pageContext);
    213         tag.setLabel("MyLabel");
    214         tag.setId("myId");
    215         tag.setTooltip("myTooltip");
    216
    217
    218         ParamTag textFieldParamTag = new ParamTag();
    219         textFieldParamTag.setPageContext(pageContext);
    220         textFieldParamTag.setName("tooltipConfig");
    221         StrutsMockBodyContent bodyContent2 = new StrutsMockBodyContent(new MockJspWriter());
    222         bodyContent2.setString(
    223                 "tooltipIcon=/struts/tooltip/myTooltip2.gif| " +
    224                 "tooltipDelay=5000 "
    225         );
    226         textFieldParamTag.setBodyContent(bodyContent2);
    227
    228         formTag.doStartTag();
    229         formParamTag.doStartTag();
    230         formParamTag.doEndTag();
    231         tag.doStartTag();
    232         textFieldParamTag.doStartTag();
    233         textFieldParamTag.doEndTag();
    234         tag.doEndTag();
    235         formTag.doEndTag();
    236
    237         System.out.println(writer.toString());
    238
    239         verify(TooltipTest.class.getResource("tooltip-3.txt"));
    240     }
    241
    242     /***
    243      * @throws Exception
    244      *
    245      */
    246     public void setUp() throws Exception {
    247         super.setUp();
    248         initDispatcher(new HashMap<String,String>(){{
    249             put("configProviders", TestConfigurationProvider.class.getName());
    250         }});
    251     }
    252 }