use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testBindErrorTypeMismatch.
@Test
public void testBindErrorTypeMismatch() throws Exception {
VanillaTarget target = new VanillaTarget();
BindingResult result = bind(target, "foo: bar\n" + "value: foo");
assertThat(result.getErrorCount()).isEqualTo(1);
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testAllowedFields.
@Test
public void testAllowedFields() throws Exception {
VanillaTarget target = new VanillaTarget();
RelaxedDataBinder binder = getBinder(target, null);
binder.setAllowedFields("foo");
binder.setIgnoreUnknownFields(false);
BindingResult result = bind(binder, target, "foo: bar\n" + "value: 123\n" + "bar: spam");
assertThat(target.getValue()).isEqualTo(0);
assertThat(target.getFoo()).isEqualTo("bar");
assertThat(result.getErrorCount()).isEqualTo(0);
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testBindMapWithDeepClashInProperties.
@Test
public void testBindMapWithDeepClashInProperties() throws Exception {
Map<String, Object> target = new LinkedHashMap<>();
BindingResult result = bind(target, "vanilla.spam.foo: bar\n" + "vanilla.spam.foo.value: 123", "vanilla");
assertThat(result.getErrorCount()).isEqualTo(0);
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) target.get("spam");
assertThat(map.get("foo.value")).isEqualTo("123");
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method doTestBindCaseInsensitiveEnums.
private void doTestBindCaseInsensitiveEnums(VanillaTarget target) throws Exception {
BindingResult result = bind(target, "bingo: THIS");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target.getBingo()).isEqualTo(Bingo.THIS);
result = bind(target, "bingo: oR");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target.getBingo()).isEqualTo(Bingo.or);
result = bind(target, "bingo: that");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target.getBingo()).isEqualTo(Bingo.THAT);
result = bind(target, "bingo: the-other");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target.getBingo()).isEqualTo(Bingo.THE_OTHER);
result = bind(target, "bingo: the_other");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target.getBingo()).isEqualTo(Bingo.THE_OTHER);
result = bind(target, "bingo: The_Other");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target.getBingo()).isEqualTo(Bingo.THE_OTHER);
result = bind(target, "bingos: The_Other");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target.getBingos()).contains(Bingo.THE_OTHER);
result = bind(target, "bingos: The_Other, that");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target.getBingos()).contains(Bingo.THE_OTHER, Bingo.THAT);
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testNoNestedFields.
@Test
public void testNoNestedFields() throws Exception {
VanillaTarget target = new VanillaTarget();
RelaxedDataBinder binder = getBinder(target, "foo");
binder.setIgnoreUnknownFields(false);
binder.setIgnoreNestedProperties(true);
BindingResult result = bind(binder, target, "foo.foo: bar\n" + "foo.value: 123\n" + "foo.nested.bar: spam");
assertThat(target.getValue()).isEqualTo(123);
assertThat(target.getFoo()).isEqualTo("bar");
assertThat(result.getErrorCount()).isEqualTo(0);
}
Aggregations