Search in sources :

Example 96 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class JodaTimeFormattingTests method testBindDateTimeISO.

@Test
public void testBindDateTimeISO() throws Exception {
    JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
    registrar.setUseIsoFormat(true);
    setUp(registrar);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("dateTime", "2009-10-31T12:00:00.000Z");
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    assertEquals("2009-10-31T07:00:00.000-05:00", binder.getBindingResult().getFieldValue("dateTime"));
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 97 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class JodaTimeFormattingTests method testBindLocalDateAnnotatedWithError.

@Test
public void testBindLocalDateAnnotatedWithError() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDateAnnotated", "Oct 031, 2009");
    binder.bind(propertyValues);
    assertEquals(1, binder.getBindingResult().getFieldErrorCount("localDateAnnotated"));
    assertEquals("Oct 031, 2009", binder.getBindingResult().getFieldValue("localDateAnnotated"));
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 98 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class JodaTimeFormattingTests method testBindLocalDate.

@Test
public void testBindLocalDate() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDate", "10/31/09");
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    assertEquals("10/31/09", binder.getBindingResult().getFieldValue("localDate"));
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 99 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class JodaTimeFormattingTests method testBindLocalDateTimeAnnotated.

@Test
public void testBindLocalDateTimeAnnotated() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDateTimeAnnotated", new LocalDateTime(2009, 10, 31, 12, 0));
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    String value = binder.getBindingResult().getFieldValue("localDateTimeAnnotated").toString();
    assertTrue(value.startsWith("Oct 31, 2009"));
    assertTrue(value.endsWith("12:00 PM"));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 100 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.

the class DataBinderFieldAccessTests method nestedBindingWithDefaultConversionNoErrors.

@Test
public void nestedBindingWithDefaultConversionNoErrors() throws Exception {
    FieldAccessBean rod = new FieldAccessBean();
    DataBinder binder = new DataBinder(rod, "person");
    assertTrue(binder.isIgnoreUnknownFields());
    binder.initDirectFieldAccess();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue(new PropertyValue("spouse.name", "Kerry"));
    pvs.addPropertyValue(new PropertyValue("spouse.jedi", "on"));
    binder.bind(pvs);
    binder.close();
    assertEquals("Kerry", rod.getSpouse().getName());
    assertTrue((rod.getSpouse()).isJedi());
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) FieldAccessBean(org.springframework.tests.sample.beans.FieldAccessBean) PropertyValue(org.springframework.beans.PropertyValue) Test(org.junit.Test)

Aggregations

MutablePropertyValues (org.springframework.beans.MutablePropertyValues)301 Test (org.junit.Test)268 TestBean (org.springframework.tests.sample.beans.TestBean)86 ITestBean (org.springframework.tests.sample.beans.ITestBean)82 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)73 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)68 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)35 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)24 PropertyEditorSupport (java.beans.PropertyEditorSupport)23 PropertyValue (org.springframework.beans.PropertyValue)16 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)16 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)15 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)14 ScannedGenericBeanDefinition (org.springframework.context.annotation.ScannedGenericBeanDefinition)14 HashMap (java.util.HashMap)13 BeanWrapper (org.springframework.beans.BeanWrapper)12 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)11 ParseException (java.text.ParseException)9 RelaxedDataBinder (org.springframework.boot.bind.RelaxedDataBinder)9 BooleanTestBean (org.springframework.tests.sample.beans.BooleanTestBean)9