FileDocCategorySizeDatePackage
AnchorTagTest.javaAPI DocExample4657Mon Jul 23 13:26:16 BST 2007org.apache.struts2.views.jsp

AnchorTagTest

public class AnchorTagTest extends AbstractUITagTest
Unit test for {@ link AnchorTag}.

Fields Summary
private StringWriter
writer
private org.apache.struts2.views.jsp.ui.AnchorTag
tag
Constructors Summary
Methods Summary
protected voidsetUp()


         
        super.setUp();

        request.setScheme("http");
        request.setServerName("localhost");
        request.setServerPort(80);

        tag = new AnchorTag();
        tag.setPageContext(pageContext);
        JspWriter jspWriter = new StrutsMockJspWriter(writer);
        pageContext.setJspWriter(jspWriter);
    
public voidtestAccessKey()

        tag.setHref("TestAction.action");
        tag.setAccesskey("T");
        tag.doStartTag();
        tag.doEndTag();
        assertTrue(writer.toString().indexOf("accesskey=\"T\"") > -1);
        assertFalse(writer.toString().endsWith("\n"));
    
public voidtestActionURL()

        tag.setHref("TestAction.action");
        tag.doStartTag();
        tag.doEndTag();
        assertTrue(writer.toString().indexOf("href=\"TestAction.action\"") > -1);
        assertEquals("<a href=\"TestAction.action\"></a>", writer.toString());
    
public voidtestAddParameters()

        tag.setHref("/TestAction.action");
        String bodyText = "<img src=\"#\"/>";
        StrutsBodyContent bodyContent = new StrutsBodyContent(null);
        bodyContent.print(bodyText);
        tag.setBodyContent(bodyContent);

        tag.doStartTag();
        tag.doEndTag();
    
public voidtestId()

        tag.setId("home&improvements");
        tag.doStartTag();
        tag.doEndTag();
        assertEquals("<a id=\"home&improvements\"></a>", writer.toString());
        assertFalse(writer.toString().endsWith("\n"));
    
public voidtestNoNewLineAtEnd()

        tag.setHref("TestAction.action");
        tag.doStartTag();
        tag.doEndTag();
        assertFalse(writer.toString().endsWith("\n"));
    
public voidtestOnMouseOver()

        tag.setHref("TestAction.action");
        tag.setOnmouseover("over");
        tag.doStartTag();
        tag.doEndTag();
        assertTrue(writer.toString().indexOf("onmouseover=\"over\"") > -1);
        assertFalse(writer.toString().endsWith("\n"));
    
public voidtestOnMouseOverAndFocus()

        tag.setHref("TestAction.action");
        tag.setOnmouseover("overme");
        tag.setOnfocus("focusme");
        tag.doStartTag();
        tag.doEndTag();
        assertTrue(writer.toString().indexOf("onmouseover=\"overme\"") > -1);
        assertTrue(writer.toString().indexOf("onfocus=\"focusme\"") > -1);
        assertFalse(writer.toString().endsWith("\n"));
    
public voidtestTitle()

    	tag.setHref("home.ftl");
        tag.setTitle("home & improvements");
        tag.doStartTag();
        tag.doEndTag();
        assertEquals("<a href=\"home.ftl\" title=\"home & improvements\"></a>", writer.toString());
        assertFalse(writer.toString().endsWith("\n"));
    
public voidtestWithContent()

        tag.setHref("TestAction.action");
        tag.doStartTag();
        writer.write("Home");       
        tag.doEndTag();
        assertEquals("<a href=\"TestAction.action\">Home</a>", writer.toString());
        assertFalse(writer.toString().endsWith("\n"));