Search in sources :

Example 11 with BindException

use of cn.taketoday.validation.BindException in project today-framework by TAKETODAY.

the class ErrorResponseExceptionTests method methodArgumentNotValidException.

@Test
void methodArgumentNotValidException() {
    BindingResult bindingResult = new BindException(new Object(), "object");
    bindingResult.addError(new FieldError("object", "field", "message"));
    ErrorResponse ex = new MethodArgumentNotValidException(this.methodParameter, bindingResult);
    assertStatus(ex, HttpStatus.BAD_REQUEST);
    assertDetail(ex, "Invalid request content.");
    assertThat(ex.getHeaders()).isEmpty();
}
Also used : BindingResult(cn.taketoday.validation.BindingResult) BindException(cn.taketoday.validation.BindException) FieldError(cn.taketoday.validation.FieldError) MethodArgumentNotValidException(cn.taketoday.web.bind.MethodArgumentNotValidException) Test(org.junit.jupiter.api.Test)

Aggregations

BindException (cn.taketoday.validation.BindException)11 Test (org.junit.jupiter.api.Test)11 BindingResult (cn.taketoday.validation.BindingResult)7 MethodArgumentNotValidException (cn.taketoday.web.bind.MethodArgumentNotValidException)7 ServletException (jakarta.servlet.ServletException)5 FieldError (cn.taketoday.validation.FieldError)4 MapBindingResult (cn.taketoday.validation.MapBindingResult)4 ObjectError (cn.taketoday.validation.ObjectError)4 BeanCreationException (cn.taketoday.beans.factory.BeanCreationException)2 FailureAnalysis (cn.taketoday.framework.diagnostics.FailureAnalysis)2 ConversionNotSupportedException (cn.taketoday.beans.ConversionNotSupportedException)1 PropertyValues (cn.taketoday.beans.PropertyValues)1 TypeMismatchException (cn.taketoday.beans.TypeMismatchException)1 DerivedTestBean (cn.taketoday.beans.testfixture.beans.DerivedTestBean)1 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)1 IndexedTestBean (cn.taketoday.beans.testfixture.beans.IndexedTestBean)1 SerializablePerson (cn.taketoday.beans.testfixture.beans.SerializablePerson)1 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)1 HttpMessageNotReadableException (cn.taketoday.http.converter.HttpMessageNotReadableException)1 HttpMessageNotWritableException (cn.taketoday.http.converter.HttpMessageNotWritableException)1