use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testBindOverlappingNestedMaps.
@SuppressWarnings("unchecked")
@Test
public void testBindOverlappingNestedMaps() throws Exception {
Map<String, Object> target = new LinkedHashMap<>();
BindingResult result = bind(target, "a.b.c.d: abc\na.b.c1.d1: efg");
assertThat(result.getErrorCount()).isEqualTo(0);
Map<String, Object> a = (Map<String, Object>) target.get("a");
Map<String, Object> b = (Map<String, Object>) a.get("b");
Map<String, Object> c = (Map<String, Object>) b.get("c");
assertThat(c.get("d")).isEqualTo("abc");
Map<String, Object> c1 = (Map<String, Object>) b.get("c1");
assertThat(c1.get("d1")).isEqualTo("efg");
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testSimpleValidation.
@Test
public void testSimpleValidation() throws Exception {
ValidatedTarget target = new ValidatedTarget();
BindingResult result = bind(target, "");
assertThat(result.getErrorCount()).isEqualTo(1);
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testRequiredFieldsValidation.
@Test
public void testRequiredFieldsValidation() throws Exception {
TargetWithValidatedMap target = new TargetWithValidatedMap();
BindingResult result = bind(target, "info[foo]: bar");
assertThat(result.getErrorCount()).isEqualTo(2);
for (FieldError error : result.getFieldErrors()) {
System.err.println(new StaticMessageSource().getMessage(error, Locale.getDefault()));
}
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testBindMapWithDifferentDeepClashInProperties.
@Test
public void testBindMapWithDifferentDeepClashInProperties() throws Exception {
Map<String, Object> target = new LinkedHashMap<>();
BindingResult result = bind(target, "vanilla.spam.bar: bar\n" + "vanilla.spam.bar.value: 123", "vanilla");
assertThat(result.getErrorCount()).isEqualTo(0);
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) target.get("spam");
assertThat(map.get("bar.value")).isEqualTo("123");
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testBindErrorNotWritable.
@Test
public void testBindErrorNotWritable() throws Exception {
this.expected.expectMessage("property 'spam'");
this.expected.expectMessage("not writable");
VanillaTarget target = new VanillaTarget();
BindingResult result = bind(target, "spam: bar\n" + "value: 123");
assertThat(result.getErrorCount()).isEqualTo(1);
}
Aggregations