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

IncludeTagTest

public class IncludeTagTest extends AbstractTagTest
Unit test of {@link IncludeTag}.

Fields Summary
private org.easymock.MockControl
controlRequestDispatcher
private RequestDispatcher
mockRequestDispatcher
private IncludeTag
tag
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        request.setupGetRequestDispatcher(new MockRequestDispatcher());
        tag = new IncludeTag();

        controlRequestDispatcher = MockControl.createNiceControl(RequestDispatcher.class);
        // use always matcher as we can not determine the excact objects used in mock.include(request, response) call
        controlRequestDispatcher.setDefaultMatcher(MockControl.ALWAYS_MATCHER);
        mockRequestDispatcher = (RequestDispatcher) controlRequestDispatcher.getMock();

        request.setupGetRequestDispatcher(mockRequestDispatcher);
        tag.setPageContext(pageContext);
        tag.setPageContext(pageContext);
    
protected voidtearDown()

        super.tearDown();
        tag = null;
        controlRequestDispatcher = null;
        mockRequestDispatcher = null;
    
public voidtestIncludeNoParam()

        mockRequestDispatcher.include(null, null);
        controlRequestDispatcher.setVoidCallable();
        controlRequestDispatcher.replay();

        tag.setValue("person/list.jsp");
        tag.doStartTag();
        tag.doEndTag();

        controlRequestDispatcher.verify();
        assertEquals("/person/list.jsp", request.getRequestDispatherString());
        assertEquals("", writer.toString());
    
public voidtestIncludeRelative2Dots()

        // TODO: we should test for .. in unit test - is this test correct?
        mockRequestDispatcher.include(null, null);
        controlRequestDispatcher.setVoidCallable();
        controlRequestDispatcher.replay();

        request.setupGetServletPath("app/manager");
        tag.setValue("../car/view.jsp");
        tag.doStartTag();
        tag.doEndTag();

        controlRequestDispatcher.verify();
        assertEquals("/car/view.jsp", request.getRequestDispatherString());
        assertEquals("", writer.toString());
    
public voidtestIncludeWithParameters()

        mockRequestDispatcher.include(null, null);
        controlRequestDispatcher.setVoidCallable();
        controlRequestDispatcher.replay();

        tag.setValue("person/create.jsp");
        tag.doStartTag();
        // adding param must be done after doStartTag()
        Include include = (Include) tag.getComponent();
        include.addParameter("user", "Santa Claus");
        tag.doEndTag();

        controlRequestDispatcher.verify();
        assertEquals("/person/create.jsp?user=Santa+Claus", request.getRequestDispatherString());
        assertEquals("", writer.toString());
    
public voidtestNoURL()

        try {
            tag.doStartTag();
            tag.doEndTag();
            fail("Should have thrown exception as no URL is specified in setValue");
        } catch (StrutsException e) {
            assertEquals("tag 'include', field 'value': You must specify the URL to include. Example: /foo.jsp", e.getMessage());
        }