001: /*
002: * $Id: AnchorTagTest.java 520249 2007-03-20 03:18:23Z 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;
022:
023: import java.io.StringWriter;
024:
025: import javax.servlet.jsp.JspWriter;
026:
027: import org.apache.struts2.views.jsp.ui.AnchorTag;
028: import org.apache.struts2.views.jsp.ui.StrutsBodyContent;
029:
030: /**
031: * Unit test for {@ link AnchorTag}.
032: */
033: public class AnchorTagTest extends AbstractUITagTest {
034: private StringWriter writer = new StringWriter();
035: private AnchorTag tag;
036:
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: request.setScheme("http");
041: request.setServerName("localhost");
042: request.setServerPort(80);
043:
044: tag = new AnchorTag();
045: tag.setPageContext(pageContext);
046: JspWriter jspWriter = new StrutsMockJspWriter(writer);
047: pageContext.setJspWriter(jspWriter);
048: }
049:
050: public void testActionURL() throws Exception {
051: tag.setHref("TestAction.action");
052: tag.doStartTag();
053: tag.doEndTag();
054: assertTrue(writer.toString().indexOf(
055: "href=\"TestAction.action\"") > -1);
056: assertEquals("<a href=\"TestAction.action\"></a>", writer
057: .toString());
058: }
059:
060: public void testNoNewLineAtEnd() throws Exception {
061: tag.setHref("TestAction.action");
062: tag.doStartTag();
063: tag.doEndTag();
064: assertFalse(writer.toString().endsWith("\n"));
065: }
066:
067: public void testAccessKey() throws Exception {
068: tag.setHref("TestAction.action");
069: tag.setAccesskey("T");
070: tag.doStartTag();
071: tag.doEndTag();
072: assertTrue(writer.toString().indexOf("accesskey=\"T\"") > -1);
073: assertFalse(writer.toString().endsWith("\n"));
074: }
075:
076: public void testId() throws Exception {
077: tag.setId("home&improvements");
078: tag.doStartTag();
079: tag.doEndTag();
080: assertEquals("<a id=\"home&improvements\"></a>", writer
081: .toString());
082: assertFalse(writer.toString().endsWith("\n"));
083: }
084:
085: public void testTitle() throws Exception {
086: tag.setHref("home.ftl");
087: tag.setTitle("home & improvements");
088: tag.doStartTag();
089: tag.doEndTag();
090: assertEquals(
091: "<a href=\"home.ftl\" title=\"home & improvements\"></a>",
092: writer.toString());
093: assertFalse(writer.toString().endsWith("\n"));
094: }
095:
096: public void testOnMouseOver() throws Exception {
097: tag.setHref("TestAction.action");
098: tag.setOnmouseover("over");
099: tag.doStartTag();
100: tag.doEndTag();
101: assertTrue(writer.toString().indexOf("onmouseover=\"over\"") > -1);
102: assertFalse(writer.toString().endsWith("\n"));
103: }
104:
105: public void testOnMouseOverAndFocus() throws Exception {
106: tag.setHref("TestAction.action");
107: tag.setOnmouseover("overme");
108: tag.setOnfocus("focusme");
109: tag.doStartTag();
110: tag.doEndTag();
111: assertTrue(writer.toString().indexOf("onmouseover=\"overme\"") > -1);
112: assertTrue(writer.toString().indexOf("onfocus=\"focusme\"") > -1);
113: assertFalse(writer.toString().endsWith("\n"));
114: }
115:
116: public void testWithContent() throws Exception {
117: tag.setHref("TestAction.action");
118: tag.doStartTag();
119: writer.write("Home");
120: tag.doEndTag();
121: assertEquals("<a href=\"TestAction.action\">Home</a>", writer
122: .toString());
123: assertFalse(writer.toString().endsWith("\n"));
124: }
125:
126: public void testAddParameters() throws Exception {
127: tag.setHref("/TestAction.action");
128: String bodyText = "<img src=\"#\"/>";
129: StrutsBodyContent bodyContent = new StrutsBodyContent(null);
130: bodyContent.print(bodyText);
131: tag.setBodyContent(bodyContent);
132:
133: tag.doStartTag();
134: tag.doEndTag();
135: }
136:
137: }
|