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);
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testDisallowedFields.
@Test
public void testDisallowedFields() throws Exception {
VanillaTarget target = new VanillaTarget();
RelaxedDataBinder binder = getBinder(target, null);
// Disallowed fields are not unknown...
binder.setDisallowedFields("foo", "bar");
binder.setIgnoreUnknownFields(false);
BindingResult result = bind(binder, target, "foo: bar\n" + "value: 123\n" + "bar: spam");
assertThat(target.getValue()).isEqualTo(123);
assertThat(target.getFoo()).isNull();
assertThat(result.getErrorCount()).isEqualTo(0);
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testBindMapWithClashInProperties.
@Test
public void testBindMapWithClashInProperties() throws Exception {
Map<String, Object> target = new LinkedHashMap<>();
BindingResult result = bind(target, "vanilla.spam: bar\n" + "vanilla.spam.value: 123", "vanilla");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target).hasSize(2);
assertThat(target.get("spam")).isEqualTo("bar");
assertThat(target.get("spam.value")).isEqualTo("123");
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testBindMapNestedMap.
@Test
public void testBindMapNestedMap() throws Exception {
Map<String, Object> target = new LinkedHashMap<>();
BindingResult result = bind(target, "spam: bar\n" + "vanilla.foo.value: 123", "vanilla");
assertThat(result.getErrorCount()).isEqualTo(0);
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) target.get("foo");
assertThat(map.get("value")).isEqualTo("123");
}
use of org.springframework.validation.BindingResult in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testBindShallowMap.
@Test
public void testBindShallowMap() throws Exception {
Map<String, Object> target = new LinkedHashMap<>();
BindingResult result = bind(target, "vanilla.spam: bar\n" + "vanilla.value: 123", "vanilla");
assertThat(result.getErrorCount()).isEqualTo(0);
assertThat(target.get("value")).isEqualTo("123");
}
Aggregations