Search in sources :

Example 66 with BeanWrapperImpl

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

the class BindingPreparationTests method testBeanWrapperCreatesNewMaps.

@Test
public void testBeanWrapperCreatesNewMaps() throws Exception {
    TargetWithNestedMap target = new TargetWithNestedMap();
    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]");
    assertThat(wrapper.getPropertyValue("nested")).isNotNull();
}
Also used : BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Test(org.junit.Test)

Example 67 with BeanWrapperImpl

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

the class BindingPreparationTests method testListOfBeansWithListAndNoPeriod.

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

Example 68 with BeanWrapperImpl

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

the class BindingPreparationTests method testAutoGrowNewNestedMapOfBeans.

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

Example 69 with BeanWrapperImpl

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

the class JmxUtilsTests method testGetAttributeNameWithStrictCasing.

@Test
public void testGetAttributeNameWithStrictCasing() {
    PropertyDescriptor pd = new BeanWrapperImpl(AttributeTestBean.class).getPropertyDescriptor("name");
    String attributeName = JmxUtils.getAttributeName(pd, true);
    assertEquals("Incorrect casing on attribute name", "Name", attributeName);
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Test(org.junit.Test)

Example 70 with BeanWrapperImpl

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

the class JmxUtilsTests method testGetAttributeNameWithoutStrictCasing.

@Test
public void testGetAttributeNameWithoutStrictCasing() {
    PropertyDescriptor pd = new BeanWrapperImpl(AttributeTestBean.class).getPropertyDescriptor("name");
    String attributeName = JmxUtils.getAttributeName(pd, false);
    assertEquals("Incorrect casing on attribute name", "name", attributeName);
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) Test(org.junit.Test)

Aggregations

BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)113 BeanWrapper (org.springframework.beans.BeanWrapper)75 Test (org.junit.jupiter.api.Test)32 NumberTestBean (org.springframework.beans.testfixture.beans.NumberTestBean)21 BooleanTestBean (org.springframework.beans.testfixture.beans.BooleanTestBean)20 Test (org.junit.Test)19 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)17 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)17 TestBean (org.springframework.beans.testfixture.beans.TestBean)17 PropertyDescriptor (java.beans.PropertyDescriptor)14 PropertyEditorSupport (java.beans.PropertyEditorSupport)14 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)14 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)12 HashSet (java.util.HashSet)11 BeansException (org.springframework.beans.BeansException)9 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 BeanCreationException (org.springframework.beans.factory.BeanCreationException)5 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)5 IOException (java.io.IOException)4