use of cn.taketoday.validation.BeanPropertyBindingResult in project today-infrastructure by TAKETODAY.
the class ValidatorAdapterTests method testPatternMessage.
@Test
public void testPatternMessage() {
TestBean testBean = new TestBean();
testBean.setEmail("X");
testBean.setConfirmEmail("X");
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(testBean, "testBean");
validatorAdapter.validate(testBean, errors);
assertThat(errors.getFieldErrorCount("email")).isEqualTo(1);
assertThat(errors.getFieldValue("email")).isEqualTo("X");
FieldError error = errors.getFieldError("email");
assertThat(error).isNotNull();
assertThat(messageSource.getMessage(error, Locale.ENGLISH)).contains("[\\w.'-]{1,}@[\\w.'-]{1,}");
assertThat(error.contains(ConstraintViolation.class)).isTrue();
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("email");
}
use of cn.taketoday.validation.BeanPropertyBindingResult in project today-infrastructure by TAKETODAY.
the class ValidatorAdapterTests method testMapEntryConstraint.
// SPR-15839
@Test
public void testMapEntryConstraint() {
Map<String, String> property = new HashMap<>();
property.put(null, null);
BeanWithMapEntryConstraint bean = new BeanWithMapEntryConstraint();
bean.setProperty(property);
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(bean, "bean");
validatorAdapter.validate(bean, errors);
assertThat(errors.hasFieldErrors("property[]")).isTrue();
assertThat(errors.getFieldValue("property[]")).isNull();
}
use of cn.taketoday.validation.BeanPropertyBindingResult in project today-infrastructure by TAKETODAY.
the class ValidatorAdapterTests method testNoStringArgumentValue.
// SPR-13406
@Test
public void testNoStringArgumentValue() throws Exception {
TestBean testBean = new TestBean();
testBean.setPassword("pass");
testBean.setConfirmPassword("pass");
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(testBean, "testBean");
validatorAdapter.validate(testBean, errors);
assertThat(errors.getFieldErrorCount("password")).isEqualTo(1);
assertThat(errors.getFieldValue("password")).isEqualTo("pass");
FieldError error = errors.getFieldError("password");
assertThat(error).isNotNull();
assertThat(messageSource.getMessage(error, Locale.ENGLISH)).isEqualTo("Size of Password must be between 8 and 128");
assertThat(error.contains(ConstraintViolation.class)).isTrue();
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("password");
assertThat(SerializationTestUtils.serializeAndDeserialize(error.toString())).isEqualTo(error.toString());
}
use of cn.taketoday.validation.BeanPropertyBindingResult in project today-infrastructure by TAKETODAY.
the class ValidatorAdapterTests method testApplyMessageSourceResolvableToStringArgumentValueWithResolvedLogicalFieldName.
// SPR-13406
@Test
public void testApplyMessageSourceResolvableToStringArgumentValueWithResolvedLogicalFieldName() throws Exception {
TestBean testBean = new TestBean();
testBean.setPassword("password");
testBean.setConfirmPassword("PASSWORD");
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(testBean, "testBean");
validatorAdapter.validate(testBean, errors);
assertThat(errors.getFieldErrorCount("password")).isEqualTo(1);
assertThat(errors.getFieldValue("password")).isEqualTo("password");
FieldError error = errors.getFieldError("password");
assertThat(error).isNotNull();
assertThat(messageSource.getMessage(error, Locale.ENGLISH)).isEqualTo("Password must be same value as Password(Confirm)");
assertThat(error.contains(ConstraintViolation.class)).isTrue();
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("password");
assertThat(SerializationTestUtils.serializeAndDeserialize(error.toString())).isEqualTo(error.toString());
}
use of cn.taketoday.validation.BeanPropertyBindingResult in project today-infrastructure by TAKETODAY.
the class ValidatorAdapterTests method testWithList.
// SPR-16177
@Test
public void testWithList() {
Parent parent = new Parent();
parent.setName("Parent whit list");
parent.getChildList().addAll(createChildren(parent));
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(parent, "parent");
validatorAdapter.validate(parent, errors);
assertThat(errors.getErrorCount() > 0).isTrue();
}
Aggregations