Search in sources :

Example 1 with DataBinder

use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.

the class PropertySourcesPropertyValuesTests method testPlaceholdersBinding.

@Test
public void testPlaceholdersBinding() {
    TestBean target = new TestBean();
    DataBinder binder = new DataBinder(target);
    binder.bind(new PropertySourcesPropertyValues(this.propertySources));
    assertThat(target.getName()).isEqualTo("bar");
}
Also used : DataBinder(org.springframework.validation.DataBinder) Test(org.junit.Test)

Example 2 with DataBinder

use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.

the class PropertySourcesPropertyValuesTests method testPlaceholdersBindingWithError.

@Test
public void testPlaceholdersBindingWithError() {
    TestBean target = new TestBean();
    DataBinder binder = new DataBinder(target);
    this.propertySources.addFirst(new MapPropertySource("another", Collections.<String, Object>singletonMap("something", "${nonexistent}")));
    binder.bind(new PropertySourcesPropertyValues(this.propertySources));
    assertThat(target.getName()).isEqualTo("bar");
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) DataBinder(org.springframework.validation.DataBinder) Test(org.junit.Test)

Example 3 with DataBinder

use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.

the class PropertySourcesPropertyValuesTests method testPlaceholdersBindingNonEnumerable.

@Test
public void testPlaceholdersBindingNonEnumerable() {
    FooBean target = new FooBean();
    DataBinder binder = new DataBinder(target);
    binder.bind(new PropertySourcesPropertyValues(this.propertySources, (Collection<String>) null, Collections.singleton("foo")));
    assertThat(target.getFoo()).isEqualTo("bar");
}
Also used : Collection(java.util.Collection) DataBinder(org.springframework.validation.DataBinder) Test(org.junit.Test)

Example 4 with DataBinder

use of org.springframework.validation.DataBinder in project spring-framework by spring-projects.

the class MoneyFormattingTests method testAmountWithNumberFormat1.

@Test
public void testAmountWithNumberFormat1() {
    FormattedMoneyHolder1 bean = new FormattedMoneyHolder1();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "$10.50");
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount"));
    assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
    LocaleContextHolder.setLocale(Locale.CANADA);
    binder.bind(propertyValues);
    LocaleContextHolder.setLocale(Locale.US);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount"));
    assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    assertEquals("CAD", bean.getAmount().getCurrency().getCurrencyCode());
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) DataBinder(org.springframework.validation.DataBinder) Test(org.junit.Test)

Example 5 with DataBinder

use of org.springframework.validation.DataBinder in project spring-framework by spring-projects.

the class MoneyFormattingTests method testAmountWithNumberFormat2.

@Test
public void testAmountWithNumberFormat2() {
    FormattedMoneyHolder2 bean = new FormattedMoneyHolder2();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "10.50");
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    assertEquals("10.5", binder.getBindingResult().getFieldValue("amount"));
    assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) DataBinder(org.springframework.validation.DataBinder) Test(org.junit.Test)

Aggregations

DataBinder (org.springframework.validation.DataBinder)35 Test (org.junit.Test)15 Errors (org.springframework.validation.Errors)14 Locale (java.util.Locale)8 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)7 ArrayList (java.util.ArrayList)6 DOMSource (javax.xml.transform.dom.DOMSource)6 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)5 Element (org.w3c.dom.Element)5 HashMap (java.util.HashMap)4 FileItem (org.apache.commons.fileupload.FileItem)4 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)4 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)4 MapPropertySource (org.springframework.core.env.MapPropertySource)4 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)4 File (java.io.File)3 LinkedHashMap (java.util.LinkedHashMap)3 FileProperties (org.akaza.openclinica.bean.rule.FileProperties)3 Study (org.akaza.openclinica.domain.datamap.Study)3 PFormCache (org.akaza.openclinica.web.pform.PFormCache)3