View Javadoc

    1   /*
    2    * $Id: HeadTagTest.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 org.apache.struts2.components.Head;
    24  import org.apache.struts2.views.jsp.AbstractUITagTest;
    25
    26  /***
    27   * Unit test for {@link HeadTag}.
    28   * <p/>
    29   * Note: If unit test fails with encoding difference check the src/test/struts.properties
    30   * and adjust the .txt files accordingly
    31   *
    32   */
    33  public class HeadTagTest extends AbstractUITagTest {
    34
    35      private HeadTag tag;
    36
    37      public void testHead1() throws Exception {
    38          tag.doStartTag();
    39          tag.doEndTag();
    40
    41          verify(HeadTagTest.class.getResource("HeadTagTest-1.txt"));
    42      }
    43
    44      public void testHead1NoCalender() throws Exception {
    45          tag.doStartTag();
    46          tag.doEndTag();
    47          tag.setCalendarcss(null); // null = should use calendar-blue.css
    48
    49          verify(HeadTagTest.class.getResource("HeadTagTest-1.txt"));
    50      }
    51
    52      public void testHead2() throws Exception {
    53          tag.setTheme("ajax");
    54          tag.doStartTag();
    55          Head component = (Head) tag.getComponent();
    56          assertTrue(!component.isDebug());
    57          tag.doEndTag();
    58
    59          verify(HeadTagTest.class.getResource("HeadTagTest-2.txt"));
    60          assertTrue("should have debug false", writer.toString().indexOf("isDebug: false") > -1);
    61      }
    62
    63      public void testHead3() throws Exception {
    64          tag.setTheme("ajax");
    65          tag.setDebug("true");
    66          tag.doStartTag();
    67          Head component = (Head) tag.getComponent(); // must be done between start and end
    68          assertTrue(component.isDebug());
    69          tag.doEndTag();
    70
    71          verify(HeadTagTest.class.getResource("HeadTagTest-3.txt"));
    72          assertTrue("should have debug true", writer.toString().indexOf("isDebug: true") > -1);
    73      }
    74
    75      public void testHead4() throws Exception {
    76          tag.setCalendarcss("my-calendar");
    77          tag.doStartTag();
    78          tag.doEndTag();
    79
    80          verify(HeadTagTest.class.getResource("HeadTagTest-4.txt"));
    81          assertEquals("my-calendar", tag.getCalendarcss());
    82      }
    83
    84      public void testHead4b() throws Exception {
    85          tag.setCalendarcss("my-calendar.css");
    86          tag.doStartTag();
    87          Head component = (Head) tag.getComponent(); // must be done between start and end
    88          assertEquals("my-calendar.css", component.getCalendarcss());
    89          tag.doEndTag();
    90
    91          verify(HeadTagTest.class.getResource("HeadTagTest-4.txt"));
    92          assertEquals("my-calendar.css", tag.getCalendarcss());
    93      }
    94
    95      protected void setUp() throws Exception {
    96          super.setUp();
    97          tag = new HeadTag();
    98          tag.setPageContext(pageContext);
    99      }
    100
    101     protected void tearDown() throws Exception {
    102         super.tearDown();
    103     }
    104
    105 }