Methods Summary |
---|
protected void | setUp()
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 void | tearDown()
super.tearDown();
tag = null;
controlRequestDispatcher = null;
mockRequestDispatcher = null;
|
public void | testIncludeNoParam()
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 void | testIncludeRelative2Dots()
// 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 void | testIncludeWithParameters()
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 void | testNoURL()
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());
}
|