use of cn.taketoday.validation.ObjectError 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.ObjectError 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.ObjectError in project today-infrastructure by TAKETODAY.
the class ValidationErrorsTests method iteratorShouldIterateErrors.
@Test
void iteratorShouldIterateErrors() {
List<ObjectError> allErrors = new ArrayList<>();
allErrors.add(new ObjectError("foo", "bar"));
ValidationErrors errors = new ValidationErrors(NAME, Collections.emptySet(), allErrors);
assertThat(errors.iterator()).toIterable().containsExactlyElementsOf(allErrors);
}
use of cn.taketoday.validation.ObjectError in project today-infrastructure by TAKETODAY.
the class ValidationErrorsTests method getErrorsShouldAdaptFieldErrorsToBeOriginProviders.
@Test
void getErrorsShouldAdaptFieldErrorsToBeOriginProviders() {
Set<ConfigurationProperty> boundProperties = new LinkedHashSet<>();
ConfigurationPropertyName name1 = ConfigurationPropertyName.of("foo.bar");
Origin origin1 = MockOrigin.of("line1");
boundProperties.add(new ConfigurationProperty(name1, "boot", origin1));
ConfigurationPropertyName name2 = ConfigurationPropertyName.of("foo.baz.bar");
Origin origin2 = MockOrigin.of("line2");
boundProperties.add(new ConfigurationProperty(name2, "boot", origin2));
List<ObjectError> allErrors = new ArrayList<>();
allErrors.add(new FieldError("objectname", "bar", "message"));
ValidationErrors errors = new ValidationErrors(ConfigurationPropertyName.of("foo.baz"), boundProperties, allErrors);
assertThat(Origin.from(errors.getAllErrors().get(0))).isEqualTo(origin2);
}
use of cn.taketoday.validation.ObjectError in project today-infrastructure by TAKETODAY.
the class ValidationErrorsTests method getErrorsShouldReturnErrors.
@Test
void getErrorsShouldReturnErrors() {
List<ObjectError> allErrors = new ArrayList<>();
allErrors.add(new ObjectError("foo", "bar"));
ValidationErrors errors = new ValidationErrors(NAME, Collections.emptySet(), allErrors);
assertThat(errors.getAllErrors()).isEqualTo(allErrors);
}
Aggregations