use of cn.taketoday.validation.BindException in project today-infrastructure by TAKETODAY.
the class DefaultErrorAttributesTests method withoutBindingErrors.
@Test
void withoutBindingErrors() {
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new BindException(bindingResult);
testBindingResult(bindingResult, ex, ErrorAttributeOptions.defaults());
}
use of cn.taketoday.validation.BindException in project today-infrastructure by TAKETODAY.
the class DefaultErrorAttributesTests method withBindingErrors.
@Test
void withBindingErrors() {
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new BindException(bindingResult);
testBindingResult(bindingResult, ex, ErrorAttributeOptions.of(Include.MESSAGE, Include.BINDING_ERRORS));
}
use of cn.taketoday.validation.BindException in project today-infrastructure 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();
}
use of cn.taketoday.validation.BindException in project today-infrastructure by TAKETODAY.
the class BindValidationFailureAnalyzerTests method otherBindExceptionShouldReturnAnalysis.
@Test
void otherBindExceptionShouldReturnAnalysis() {
BindException cause = new BindException(new FieldValidationFailureProperties(), "fieldValidationFailureProperties");
cause.addError(new FieldError("test", "value", "must not be null"));
BeanCreationException rootFailure = new BeanCreationException("bean creation failure", cause);
FailureAnalysis analysis = new BindValidationFailureAnalyzer().analyze(rootFailure, rootFailure);
assertThat(analysis.getDescription()).contains(failure("test.value", "null", "must not be null"));
}
use of cn.taketoday.validation.BindException in project today-framework by TAKETODAY.
the class DataBinderTests method testBindingNoErrors.
@Test
void testBindingNoErrors() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
PropertyValues pvs = new PropertyValues();
pvs.add("name", "Rod");
pvs.add("age", "032");
pvs.add("nonExisting", "someValue");
binder.bind(pvs);
binder.close();
assertThat(rod.getName().equals("Rod")).as("changed name correctly").isTrue();
assertThat(rod.getAge() == 32).as("changed age correctly").isTrue();
Map<?, ?> map = binder.getBindingResult().getModel();
assertThat(map.size() == 2).as("There is one element in map").isTrue();
TestBean tb = (TestBean) map.get("person");
assertThat(tb.equals(rod)).as("Same object").isTrue();
BindingResult other = new BeanPropertyBindingResult(rod, "person");
assertThat(binder.getBindingResult()).isEqualTo(other);
assertThat(other).isEqualTo(binder.getBindingResult());
BindException ex = new BindException(other);
assertThat(other).isEqualTo(ex);
assertThat(ex).isEqualTo(other);
assertThat(binder.getBindingResult()).isEqualTo(ex);
assertThat(ex).isEqualTo(binder.getBindingResult());
other.reject("xxx");
boolean condition = !other.equals(binder.getBindingResult());
assertThat(condition).isTrue();
}
Aggregations