001: /*
002: * $Id: HeadTagTest.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import org.apache.struts2.components.Head;
024: import org.apache.struts2.views.jsp.AbstractUITagTest;
025:
026: /**
027: * Unit test for {@link HeadTag}.
028: * <p/>
029: * Note: If unit test fails with encoding difference check the src/test/struts.properties
030: * and adjust the .txt files accordingly
031: *
032: */
033: public class HeadTagTest extends AbstractUITagTest {
034:
035: private HeadTag tag;
036:
037: public void testHead1() throws Exception {
038: tag.doStartTag();
039: tag.doEndTag();
040:
041: verify(HeadTagTest.class.getResource("HeadTagTest-1.txt"));
042: }
043:
044: public void testHead1NoCalender() throws Exception {
045: tag.doStartTag();
046: tag.doEndTag();
047: tag.setCalendarcss(null); // null = should use calendar-blue.css
048:
049: verify(HeadTagTest.class.getResource("HeadTagTest-1.txt"));
050: }
051:
052: public void testHead2() throws Exception {
053: tag.setTheme("ajax");
054: tag.doStartTag();
055: Head component = (Head) tag.getComponent();
056: assertTrue(!component.isDebug());
057: tag.doEndTag();
058:
059: verify(HeadTagTest.class.getResource("HeadTagTest-2.txt"));
060: assertTrue("should have debug false", writer.toString()
061: .indexOf("isDebug: false") > -1);
062: }
063:
064: public void testHead3() throws Exception {
065: tag.setTheme("ajax");
066: tag.setDebug("true");
067: tag.doStartTag();
068: Head component = (Head) tag.getComponent(); // must be done between start and end
069: assertTrue(component.isDebug());
070: tag.doEndTag();
071:
072: verify(HeadTagTest.class.getResource("HeadTagTest-3.txt"));
073: assertTrue("should have debug true", writer.toString().indexOf(
074: "isDebug: true") > -1);
075: }
076:
077: public void testHead4() throws Exception {
078: tag.setCalendarcss("my-calendar");
079: tag.doStartTag();
080: tag.doEndTag();
081:
082: verify(HeadTagTest.class.getResource("HeadTagTest-4.txt"));
083: assertEquals("my-calendar", tag.getCalendarcss());
084: }
085:
086: public void testHead4b() throws Exception {
087: tag.setCalendarcss("my-calendar.css");
088: tag.doStartTag();
089: Head component = (Head) tag.getComponent(); // must be done between start and end
090: assertEquals("my-calendar.css", component.getCalendarcss());
091: tag.doEndTag();
092:
093: verify(HeadTagTest.class.getResource("HeadTagTest-4.txt"));
094: assertEquals("my-calendar.css", tag.getCalendarcss());
095: }
096:
097: protected void setUp() throws Exception {
098: super .setUp();
099: tag = new HeadTag();
100: tag.setPageContext(pageContext);
101: }
102:
103: protected void tearDown() throws Exception {
104: super.tearDown();
105: }
106:
107: }
|