ServletDispatcherResultTestpublic class ServletDispatcherResultTest extends org.apache.struts2.StrutsTestCase implements org.apache.struts2.StrutsStatics
Methods Summary |
---|
public void | testInclude()
ServletDispatcherResult view = new ServletDispatcherResult();
view.setLocation("foo.jsp");
Mock dispatcherMock = new Mock(RequestDispatcher.class);
dispatcherMock.expect("include", C.ANY_ARGS);
Mock requestMock = new Mock(HttpServletRequest.class);
requestMock.expectAndReturn("getRequestDispatcher", C.args(C.eq("foo.jsp")), dispatcherMock.proxy());
Mock responseMock = new Mock(HttpServletResponse.class);
responseMock.expectAndReturn("isCommitted", Boolean.TRUE);
ActionContext ac = new ActionContext(Ognl.createDefaultContext(null));
ActionContext.setContext(ac);
ServletActionContext.setRequest((HttpServletRequest) requestMock.proxy());
ServletActionContext.setResponse((HttpServletResponse) responseMock.proxy());
try {
view.execute(null);
} catch (Exception e) {
e.printStackTrace();
fail();
}
dispatcherMock.verify();
requestMock.verify();
dispatcherMock.verify();
| public void | testSimple()
ServletDispatcherResult view = new ServletDispatcherResult();
view.setLocation("foo.jsp");
Mock dispatcherMock = new Mock(RequestDispatcher.class);
dispatcherMock.expect("forward", C.ANY_ARGS);
Mock requestMock = new Mock(HttpServletRequest.class);
requestMock.expectAndReturn("getAttribute", "javax.servlet.include.servlet_path", null);
requestMock.expectAndReturn("getRequestDispatcher", C.args(C.eq("foo.jsp")), dispatcherMock.proxy());
requestMock.expect("setAttribute", C.ANY_ARGS); // this is a bad mock, but it works
requestMock.expect("setAttribute", C.ANY_ARGS); // this is a bad mock, but it works
requestMock.matchAndReturn("getRequestURI", "foo.jsp");
Mock responseMock = new Mock(HttpServletResponse.class);
responseMock.expectAndReturn("isCommitted", Boolean.FALSE);
ActionContext ac = new ActionContext(Ognl.createDefaultContext(null));
ActionContext.setContext(ac);
ServletActionContext.setRequest((HttpServletRequest) requestMock.proxy());
ServletActionContext.setResponse((HttpServletResponse) responseMock.proxy());
try {
view.execute(null);
} catch (Exception e) {
e.printStackTrace();
fail();
}
dispatcherMock.verify();
requestMock.verify();
dispatcherMock.verify();
|
|