View Javadoc

    1   /*
    2    * $Id: LabelTest.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.HashMap;
    24  import java.util.Map;
    25
    26  import org.apache.struts2.TestAction;
    27  import org.apache.struts2.views.jsp.AbstractUITagTest;
    28
    29
    30  /***
    31   */
    32  public class LabelTest extends AbstractUITagTest {
    33
    34      public void testSimple() throws Exception {
    35          TestAction testAction = (TestAction) action;
    36          testAction.setFoo("bar");
    37
    38          LabelTag tag = new LabelTag();
    39          tag.setPageContext(pageContext);
    40          tag.setLabel("mylabel");
    41          tag.setName("myname");
    42          tag.setTitle("mytitle");
    43          tag.setValue("%{foo}");
    44
    45          tag.doStartTag();
    46          tag.doEndTag();
    47
    48          verify(LabelTest.class.getResource("Label-1.txt"));
    49      }
    50
    51      public void testSimpleWithLabelposition() throws Exception {
    52          TestAction testAction = (TestAction) action;
    53          testAction.setFoo("bar");
    54
    55          LabelTag tag = new LabelTag();
    56          tag.setPageContext(pageContext);
    57          tag.setLabel("mylabel");
    58          tag.setName("myname");
    59          tag.setValue("%{foo}");
    60          tag.setLabelposition("top");
    61
    62          tag.doStartTag();
    63          tag.doEndTag();
    64
    65          verify(LabelTest.class.getResource("Label-3.txt"));
    66      }
    67
    68      /***
    69       * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
    70       * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
    71       * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
    72       *
    73       * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
    74       *         as key.
    75       */
    76      protected Map initializedGenericTagTestProperties() {
    77          Map result = new HashMap();
    78          new PropertyHolder("title", "someTitle").addToMap(result);
    79          new PropertyHolder("cssClass", "cssClass1", "class=\"cssClass1\"").addToMap(result);
    80          new PropertyHolder("cssStyle", "cssStyle1", "style=\"cssStyle1\"").addToMap(result);
    81          new PropertyHolder("id", "someId").addToMap(result);
    82          new PropertyHolder("for", "someFor").addToMap(result);
    83          return result;
    84      }
    85
    86      public void testWithNoValue() throws Exception {
    87          TestAction testAction = (TestAction) action;
    88          testAction.setFoo("baz");
    89
    90          LabelTag tag = new LabelTag();
    91          tag.setPageContext(pageContext);
    92          tag.setLabel("mylabel");
    93          tag.setName("foo");
    94          tag.setFor("for");
    95
    96          tag.doStartTag();
    97          tag.doEndTag();
    98
    99          verify(LabelTest.class.getResource("Label-2.txt"));
    100     }
    101
    102     public void testGenericSimple() throws Exception {
    103         LabelTag tag = new LabelTag();
    104         verifyGenericProperties(tag, "simple", null);
    105     }
    106
    107     public void testGenericXhtml() throws Exception {
    108         LabelTag tag = new LabelTag();
    109         verifyGenericProperties(tag, "xhtml", null);
    110     }
    111
    112     public void testGenericAjax() throws Exception {
    113         LabelTag tag = new LabelTag();
    114         verifyGenericProperties(tag, "ajax", null);
    115     }
    116
    117 }