@Test
public void exceptionError() throws Exception {
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
this.chain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
super.doFilter(request, response);
throw new RuntimeException("BAD");
}
};
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
.isEqualTo(500);
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE))
.isEqualTo(500);
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE))
.isEqualTo("BAD");
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE))
.isEqualTo(RuntimeException.class.getName());
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI))
.isEqualTo("/test/path");
assertThat(this.response.isCommitted()).isTrue();
assertThat(this.response.getForwardedUrl()).isEqualTo("/500");
}
ErrorPageFilterTests.java 文件源码
java
阅读 38
收藏 0
点赞 0
评论 0
项目:spring-boot-concourse
作者:
评论列表
文章目录