Search in sources :

Example 21 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project spring-boot by spring-projects.

the class BindingPreparationTests method testAutoGrowWithFuzzyNameUnderscores.

@Test
public void testAutoGrowWithFuzzyNameUnderscores() throws Exception {
    TargetWithNestedMap target = new TargetWithNestedMap();
    BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
    wrapper.setAutoGrowNestedPaths(true);
    RelaxedDataBinder binder = new RelaxedDataBinder(target);
    String result = binder.normalizePath(wrapper, "nes_ted[foo][bar]");
    assertThat(wrapper.getPropertyValue("nested")).isNotNull();
    assertThat("nested[foo][bar]").isEqualTo(result);
    assertThat(wrapper.getPropertyValue("nested[foo][bar]")).isNotNull();
}
Also used : BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Test(org.junit.Test)

Example 22 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project spring-boot by spring-projects.

the class BindingPreparationTests method testBeanWrapperCreatesNewMapEntries.

@Test
public void testBeanWrapperCreatesNewMapEntries() throws Exception {
    TargetWithNestedMapOfBean target = new TargetWithNestedMapOfBean();
    BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
    wrapper.setAutoGrowNestedPaths(true);
    // For a nested map, you only have to get an element of it for it to be created
    wrapper.getPropertyValue("nested[foo]");
    wrapper.setPropertyValue("nested[foo].foo", "bar");
    assertThat(wrapper.getPropertyValue("nested")).isNotNull();
    assertThat(wrapper.getPropertyValue("nested[foo]")).isNotNull();
}
Also used : BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Test(org.junit.Test)

Example 23 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project spring-boot by spring-projects.

the class BindingPreparationTests method testAutoGrowNewNestedMapOfMaps.

@Test
public void testAutoGrowNewNestedMapOfMaps() throws Exception {
    TargetWithNestedMap target = new TargetWithNestedMap();
    BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
    wrapper.setAutoGrowNestedPaths(true);
    RelaxedDataBinder binder = new RelaxedDataBinder(target);
    String result = binder.normalizePath(wrapper, "nested[foo][bar]");
    assertThat(wrapper.getPropertyValue("nested")).isNotNull();
    assertThat("nested[foo][bar]").isEqualTo(result);
    assertThat(wrapper.getPropertyValue("nested[foo][bar]")).isNotNull();
}
Also used : BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Test(org.junit.Test)

Example 24 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project spring-boot by spring-projects.

the class BindingPreparationTests method testAutoGrowListOfLists.

@Test
public void testAutoGrowListOfLists() throws Exception {
    TargetWithNestedListOfLists target = new TargetWithNestedListOfLists();
    BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
    wrapper.setAutoGrowNestedPaths(true);
    RelaxedDataBinder binder = new RelaxedDataBinder(target);
    binder.normalizePath(wrapper, "nested[0][1]");
    assertThat(wrapper.getPropertyValue("nested")).isNotNull();
    assertThat(wrapper.getPropertyValue("nested[0][1]")).isNotNull();
}
Also used : BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Test(org.junit.Test)

Example 25 with BeanWrapperImpl

use of org.springframework.beans.BeanWrapperImpl in project spring-boot by spring-projects.

the class BindingPreparationTests method testAutoGrowWithFuzzyNameCapitals.

@Test
public void testAutoGrowWithFuzzyNameCapitals() throws Exception {
    TargetWithNestedMap target = new TargetWithNestedMap();
    BeanWrapperImpl wrapper = new BeanWrapperImpl(target);
    wrapper.setAutoGrowNestedPaths(true);
    RelaxedDataBinder binder = new RelaxedDataBinder(target);
    String result = binder.normalizePath(wrapper, "NESTED[foo][bar]");
    assertThat(wrapper.getPropertyValue("nested")).isNotNull();
    assertThat("nested[foo][bar]").isEqualTo(result);
    assertThat(wrapper.getPropertyValue("nested[foo][bar]")).isNotNull();
}
Also used : BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Test(org.junit.Test)

Aggregations

BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)85 BeanWrapper (org.springframework.beans.BeanWrapper)57 Test (org.junit.Test)47 NumberTestBean (org.springframework.tests.sample.beans.NumberTestBean)21 BooleanTestBean (org.springframework.tests.sample.beans.BooleanTestBean)20 ITestBean (org.springframework.tests.sample.beans.ITestBean)17 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)17 TestBean (org.springframework.tests.sample.beans.TestBean)17 PropertyEditorSupport (java.beans.PropertyEditorSupport)14 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)11 PropertyDescriptor (java.beans.PropertyDescriptor)7 BeansException (org.springframework.beans.BeansException)7 ArrayList (java.util.ArrayList)5 BeanCreationException (org.springframework.beans.factory.BeanCreationException)5 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)5 GrailsDomainClassProperty (grails.core.GrailsDomainClassProperty)4 BigDecimal (java.math.BigDecimal)4 BigInteger (java.math.BigInteger)4 PrivilegedAction (java.security.PrivilegedAction)4 Map (java.util.Map)4