ErrorPageFilterTests.java 文件源码

java
阅读 32 收藏 0 点赞 0 评论 0

项目:spring-boot-concourse 作者:
@Test
public void unauthorizedWithErrorPath() throws Exception {
    this.filter.addErrorPages(new ErrorPage("/error"));
    this.chain = new MockFilterChain() {
        @Override
        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            ((HttpServletResponse) response).sendError(401, "UNAUTHORIZED");
            super.doFilter(request, response);
        }
    };
    this.filter.doFilter(this.request, this.response, this.chain);
    assertThat(this.chain.getRequest()).isEqualTo(this.request);
    HttpServletResponseWrapper wrapper = (HttpServletResponseWrapper) this.chain
            .getResponse();
    assertThat(wrapper.getResponse()).isEqualTo(this.response);
    assertThat(this.response.isCommitted()).isTrue();
    assertThat(wrapper.getStatus()).isEqualTo(401);
    // The real response has to be 401 as well...
    assertThat(this.response.getStatus()).isEqualTo(401);
    assertThat(this.response.getForwardedUrl()).isEqualTo("/error");
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号