Search in sources :

Example 61 with MutablePropertyValues

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

the class PropertyResourceConfigurerIntegrationTests method testPropertyPlaceholderConfigurerWithNestedCircularReference.

@Test
public void testPropertyPlaceholderConfigurerWithNestedCircularReference() {
    StaticApplicationContext ac = new StaticApplicationContext();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("name", "name${var}");
    ac.registerSingleton("tb1", TestBean.class, pvs);
    pvs = new MutablePropertyValues();
    pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${m}");
    ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
    try {
        ac.refresh();
        fail("Should have thrown BeanDefinitionStoreException");
    } catch (BeanDefinitionStoreException ex) {
    // expected
    }
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 62 with MutablePropertyValues

use of org.springframework.beans.MutablePropertyValues 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 63 with MutablePropertyValues

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

the class JodaTimeFormattingTests method testBindLocalTimeWithSpecificStyle.

@Test
public void testBindLocalTimeWithSpecificStyle() throws Exception {
    JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar();
    registrar.setTimeStyle("M");
    setUp(registrar);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localTime", "12:00:00 PM");
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    assertEquals("12:00:00 PM", binder.getBindingResult().getFieldValue("localTime"));
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 64 with MutablePropertyValues

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

the class JodaTimeFormattingTests method testBindDateTime.

@Test
public void testBindDateTime() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("dateTime", new DateTime(2009, 10, 31, 12, 0, ISOChronology.getInstanceUTC()));
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    String value = binder.getBindingResult().getFieldValue("dateTime").toString();
    assertTrue(value.startsWith("10/31/09"));
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) Test(org.junit.Test)

Example 65 with MutablePropertyValues

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

the class JodaTimeFormattingTests method testBindLocalDateArray.

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

Aggregations

MutablePropertyValues (org.springframework.beans.MutablePropertyValues)305 Test (org.junit.Test)269 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 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)16 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)16 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)15 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