use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testFirstCollectionPropertyWinsNestedAttributes.
@Test
public void testFirstCollectionPropertyWinsNestedAttributes() throws Exception {
ListTestBean target = new ListTestBean();
DataBinder binder = new DataBinder(target);
Map<String, Object> first = new LinkedHashMap<>();
first.put("list[0].description", "another description");
Map<String, Object> second = new LinkedHashMap<>();
second.put("list[0].name", "first name");
second.put("list[0].description", "first description");
second.put("list[1].name", "second name");
second.put("list[1].description", "second description");
this.propertySources.addFirst(new MapPropertySource("s", second));
this.propertySources.addFirst(new MapPropertySource("f", first));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getList()).hasSize(1);
assertThat(target.getList().get(0).getDescription()).isEqualTo("another description");
assertThat(target.getList().get(0).getName()).isNull();
}
use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testPlaceholdersErrorInNonEnumerable.
@Test
public void testPlaceholdersErrorInNonEnumerable() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
this.propertySources.addFirst(new PropertySource<Object>("application", "STUFF") {
@Override
public Object getProperty(String name) {
return new Object();
}
});
binder.bind(new PropertySourcesPropertyValues(this.propertySources, (Collection<String>) null, Collections.singleton("name")));
assertThat(target.getName()).isNull();
}
use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testFirstCollectionPropertyWins.
@Test
public void testFirstCollectionPropertyWins() throws Exception {
ListBean target = new ListBean();
DataBinder binder = new DataBinder(target);
Map<String, Object> first = new LinkedHashMap<>();
first.put("list[0]", "f0");
Map<String, Object> second = new LinkedHashMap<>();
second.put("list[0]", "s0");
second.put("list[1]", "s1");
this.propertySources.addFirst(new MapPropertySource("s", second));
this.propertySources.addFirst(new MapPropertySource("f", first));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getList()).containsExactly("f0");
}
use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testCollectionProperty.
@Test
public void testCollectionProperty() throws Exception {
ListBean target = new ListBean();
DataBinder binder = new DataBinder(target);
Map<String, Object> map = new LinkedHashMap<>();
map.put("list[0]", "v0");
map.put("list[1]", "v1");
this.propertySources.addFirst(new MapPropertySource("values", map));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getList()).containsExactly("v0", "v1");
}
use of org.springframework.validation.DataBinder in project spring-framework by spring-projects.
the class MoneyFormattingTests method testAmountWithNumberFormat4.
@Test
public void testAmountWithNumberFormat4() {
FormattedMoneyHolder4 bean = new FormattedMoneyHolder4();
DataBinder binder = new DataBinder(bean);
binder.setConversionService(conversionService);
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("amount", "010.500");
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
assertEquals("010.500", binder.getBindingResult().getFieldValue("amount"));
assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}
Aggregations