001: /*
002: * Copyright (c) 2002-2007 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.jsp;
006:
007: import com.opensymphony.webwork.views.jsp.ui.AnchorTag;
008: import com.opensymphony.webwork.views.jsp.ui.WebWorkBodyContent;
009:
010: import javax.servlet.jsp.JspWriter;
011: import java.io.StringWriter;
012:
013: /**
014: * @author Mike Porter
015: * @author Claus Ibsen
016: * @version $Date: 2007-03-21 05:59:08 +0100 (Wed, 21 Mar 2007) $ $Id: AnchorTagTest.java 2867 2007-03-21 04:59:08Z tm_jee $
017: */
018: public class AnchorTagTest extends AbstractUITagTest {
019: private StringWriter writer = new StringWriter();
020: private AnchorTag tag;
021:
022: public void testActionURL() throws Exception {
023: tag.setHref("TestAction.action");
024: tag.doStartTag();
025: tag.doEndTag();
026: assertTrue(writer.toString().indexOf(
027: "href=\"TestAction.action\"") > -1);
028: }
029:
030: public void testNoNewLineAtEnd() throws Exception {
031: tag.setHref("TestAction.action");
032: tag.doStartTag();
033: tag.doEndTag();
034: assertFalse(writer.toString().endsWith("\n"));
035: }
036:
037: public void testAccessKey() throws Exception {
038: tag.setHref("TestAction.action");
039: tag.setAccesskey("T");
040: tag.doStartTag();
041: tag.doEndTag();
042: assertTrue(writer.toString().indexOf("accesskey=\"T\"") > -1);
043: assertFalse(writer.toString().endsWith("\n"));
044: }
045:
046: public void testAddParameters() throws Exception {
047: tag.setHref("/TestAction.action");
048: String bodyText = "<img src=\"#\"/>";
049: WebWorkBodyContent bodyContent = new WebWorkBodyContent(null);
050: bodyContent.print(bodyText);
051: tag.setBodyContent(bodyContent);
052:
053: tag.doStartTag();
054: tag.doEndTag();
055: }
056:
057: public void testId() throws Exception {
058: tag.setId("home&improvements");
059: tag.doStartTag();
060: tag.doEndTag();
061: assertEquals("<a id=\"home&improvements\"></a>", writer
062: .toString());
063: assertFalse(writer.toString().endsWith("\n"));
064: }
065:
066: public void testTitle() throws Exception {
067: tag.setHref("home.ftl");
068: tag.setTitle("home & improvements");
069: tag.doStartTag();
070: tag.doEndTag();
071: assertEquals(
072: "<a href=\"home.ftl\" title=\"home & improvements\"></a>",
073: writer.toString());
074: assertFalse(writer.toString().endsWith("\n"));
075: }
076:
077: public void testOnMouseOver() throws Exception {
078: tag.setHref("TestAction.action");
079: tag.setOnmouseover("over");
080: tag.doStartTag();
081: tag.doEndTag();
082: assertTrue(writer.toString().indexOf("onmouseover=\"over\"") > -1);
083: assertFalse(writer.toString().endsWith("\n"));
084: }
085:
086: public void testOnMouseOverAndFocus() throws Exception {
087: tag.setHref("TestAction.action");
088: tag.setOnmouseover("overme");
089: tag.setOnfocus("focusme");
090: tag.doStartTag();
091: tag.doEndTag();
092: assertTrue(writer.toString().indexOf("onmouseover=\"overme\"") > -1);
093: assertTrue(writer.toString().indexOf("onfocus=\"focusme\"") > -1);
094: assertFalse(writer.toString().endsWith("\n"));
095: }
096:
097: public void testWithContent() throws Exception {
098: tag.setHref("TestAction.action");
099: tag.doStartTag();
100: writer.write("Home");
101: tag.doEndTag();
102: assertEquals("<a href=\"TestAction.action\">Home</a>", writer
103: .toString());
104: assertFalse(writer.toString().endsWith("\n"));
105: }
106:
107: protected void setUp() throws Exception {
108: super .setUp();
109:
110: request.setScheme("http");
111: request.setServerName("localhost");
112: request.setServerPort(80);
113:
114: tag = new AnchorTag();
115: tag.setPageContext(pageContext);
116: JspWriter jspWriter = new WebWorkMockJspWriter(writer);
117: pageContext.setJspWriter(jspWriter);
118: }
119:
120: }
|