use of cn.taketoday.validation.ObjectError in project today-infrastructure by TAKETODAY.
the class BindValidationFailureAnalyzer method getBindValidationExceptionDetails.
private ExceptionDetails getBindValidationExceptionDetails(Throwable rootFailure) {
BindValidationException validationException = findCause(rootFailure, BindValidationException.class);
if (validationException != null) {
BindException target = findCause(rootFailure, BindException.class);
List<ObjectError> errors = validationException.getValidationErrors().getAllErrors();
return new ExceptionDetails(errors, target, validationException);
}
cn.taketoday.validation.BindException bindException = findCause(rootFailure, cn.taketoday.validation.BindException.class);
if (bindException != null) {
List<ObjectError> errors = bindException.getAllErrors();
return new ExceptionDetails(errors, bindException.getTarget(), bindException);
}
return null;
}
use of cn.taketoday.validation.ObjectError in project today-infrastructure by TAKETODAY.
the class ValidatorFactoryTests method testSpringValidationWithAutowiredValidator.
@Test
public void testSpringValidationWithAutowiredValidator() {
ConfigurableApplicationContext ctx = new StandardApplicationContext(LocalValidatorFactoryBean.class);
LocalValidatorFactoryBean validator = ctx.getBean(LocalValidatorFactoryBean.class);
ValidPerson person = new ValidPerson();
person.expectsAutowiredValidator = true;
person.setName("Juergen");
person.getAddress().setStreet("Juergen's Street");
BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
validator.validate(person, result);
assertThat(result.getErrorCount()).isEqualTo(1);
ObjectError globalError = result.getGlobalError();
List<String> errorCodes = Arrays.asList(globalError.getCodes());
assertThat(errorCodes.size()).isEqualTo(2);
assertThat(errorCodes.contains("NameAddressValid.person")).isTrue();
assertThat(errorCodes.contains("NameAddressValid")).isTrue();
ctx.close();
}
Aggregations