use of cn.taketoday.web.bind.MissingRequestParameterException in project today-framework by TAKETODAY.
the class ResponseEntityExceptionHandlerTests method missingServletRequestParameter.
@Test
public void missingServletRequestParameter() {
Exception ex = new MissingRequestParameterException("param", "type");
testException(ex);
}
use of cn.taketoday.web.bind.MissingRequestParameterException in project today-framework by TAKETODAY.
the class ErrorPageFilterTests method nestedServletExceptionWithNoCause.
@Test
void nestedServletExceptionWithNoCause() throws Exception {
this.filter.addErrorPages(new ErrorPage(MissingRequestParameterException.class, "/500"));
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new MissingRequestParameterException("test", "string");
});
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("Required request parameter 'test' for method parameter type string is not present");
Map<String, Object> requestAttributes = getAttributesForDispatch("/500");
assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isEqualTo(MissingRequestParameterException.class);
assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION)).isInstanceOf(MissingRequestParameterException.class);
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isNull();
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)).isNull();
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)).isEqualTo("/test/path");
assertThat(this.response.isCommitted()).isTrue();
assertThat(this.response.getForwardedUrl()).isEqualTo("/500");
}
use of cn.taketoday.web.bind.MissingRequestParameterException in project today-infrastructure by TAKETODAY.
the class ErrorPageFilterTests method nestedServletExceptionWithNoCause.
@Test
void nestedServletExceptionWithNoCause() throws Exception {
this.filter.addErrorPages(new ErrorPage(MissingRequestParameterException.class, "/500"));
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new MissingRequestParameterException("test", "string");
});
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("Required request parameter 'test' for method parameter type string is not present");
Map<String, Object> requestAttributes = getAttributesForDispatch("/500");
assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isEqualTo(MissingRequestParameterException.class);
assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION)).isInstanceOf(MissingRequestParameterException.class);
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isNull();
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)).isNull();
assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)).isEqualTo("/test/path");
assertThat(this.response.isCommitted()).isTrue();
assertThat(this.response.getForwardedUrl()).isEqualTo("/500");
}
Aggregations