|
|
|
@ -25,14 +25,17 @@ import javax.servlet.ServletResponse;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.servlet.http.HttpServletResponseWrapper;
|
|
|
|
|
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.springframework.boot.context.embedded.ErrorPage;
|
|
|
|
|
import org.springframework.boot.test.OutputCapture;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.mock.web.MockFilterChain;
|
|
|
|
|
import org.springframework.mock.web.MockFilterConfig;
|
|
|
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
|
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
|
|
@ -61,6 +64,9 @@ public class ErrorPageFilterTests {
|
|
|
|
|
|
|
|
|
|
private MockFilterChain chain = new MockFilterChain();
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
|
public OutputCapture output = new OutputCapture();
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void notAnError() throws Exception {
|
|
|
|
|
this.filter.doFilter(this.request, this.response, this.chain);
|
|
|
|
@ -359,4 +365,38 @@ public class ErrorPageFilterTests {
|
|
|
|
|
verify(committedResponse, times(0)).flushBuffer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void errorMessageForRequestWithoutPathInfo() throws IOException,
|
|
|
|
|
ServletException {
|
|
|
|
|
this.request.setServletPath("/test");
|
|
|
|
|
this.filter.addErrorPages(new ErrorPage("/error"));
|
|
|
|
|
this.chain = new MockFilterChain() {
|
|
|
|
|
@Override
|
|
|
|
|
public void doFilter(ServletRequest request, ServletResponse response)
|
|
|
|
|
throws IOException, ServletException {
|
|
|
|
|
super.doFilter(request, response);
|
|
|
|
|
throw new RuntimeException();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.filter.doFilter(this.request, this.response, this.chain);
|
|
|
|
|
assertThat(this.output.toString(), containsString("request [/test]"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void errorMessageForRequestWithPathInfo() throws IOException, ServletException {
|
|
|
|
|
this.request.setServletPath("/test");
|
|
|
|
|
this.request.setPathInfo("/alpha");
|
|
|
|
|
this.filter.addErrorPages(new ErrorPage("/error"));
|
|
|
|
|
this.chain = new MockFilterChain() {
|
|
|
|
|
@Override
|
|
|
|
|
public void doFilter(ServletRequest request, ServletResponse response)
|
|
|
|
|
throws IOException, ServletException {
|
|
|
|
|
super.doFilter(request, response);
|
|
|
|
|
throw new RuntimeException();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.filter.doFilter(this.request, this.response, this.chain);
|
|
|
|
|
assertThat(this.output.toString(), containsString("request [/test/alpha]"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|