use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.
the class PropertyResourceConfigurerTests method testPropertyOverrideConfigurerWithNestedMapPropertyAndDotInMapKey.
@Test
public void testPropertyOverrideConfigurerWithNestedMapPropertyAndDotInMapKey() {
BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition();
factory.registerBeanDefinition("tb", def);
PropertyOverrideConfigurer poc;
poc = new PropertyOverrideConfigurer();
Properties props = new Properties();
props.setProperty("tb.map[key1]", "99");
props.setProperty("tb.map[key2.ext]", "test");
poc.setProperties(props);
poc.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertThat(tb.getMap().get("key1")).isEqualTo("99");
assertThat(tb.getMap().get("key2.ext")).isEqualTo("test");
}
use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.
the class PropertyResourceConfigurerTests method testPropertyOverrideConfigurerWithNestedProperty.
@Test
public void testPropertyOverrideConfigurerWithNestedProperty() {
BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition();
factory.registerBeanDefinition("tb", def);
PropertyOverrideConfigurer poc;
poc = new PropertyOverrideConfigurer();
Properties props = new Properties();
props.setProperty("tb.array[0].age", "99");
props.setProperty("tb.list[1].name", "test");
poc.setProperties(props);
poc.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.
the class PropertyResourceConfigurerTests method testPropertyOverrideConfigurerWithInvalidPropertiesFile.
@Test
public void testPropertyOverrideConfigurerWithInvalidPropertiesFile() {
BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition();
factory.registerBeanDefinition("tb", def);
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
poc.setLocations(TEST_PROPS, XTEST_PROPS);
poc.setIgnoreResourceNotFound(true);
poc.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.
the class PropertyResourceConfigurerTests method testPropertyOverrideConfigurerWithConvertProperties.
@Test
public void testPropertyOverrideConfigurerWithConvertProperties() {
BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition();
factory.registerBeanDefinition("tb", def);
ConvertingOverrideConfigurer bfpp = new ConvertingOverrideConfigurer();
Properties props = new Properties();
props.setProperty("tb.array[0].name", "99");
props.setProperty("tb.list[1].name", "test");
bfpp.setProperties(props);
bfpp.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertThat(tb.getArray()[0].getName()).isEqualTo("X99");
assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("Xtest");
}
use of org.springframework.beans.testfixture.beans.IndexedTestBean in project spring-framework by spring-projects.
the class CustomEditorTests method testIndexedPropertiesWithDirectAccessAndPropertyEditors.
@Test
void testIndexedPropertiesWithDirectAccessAndPropertyEditors() {
IndexedTestBean bean = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(new TestBean("array" + text, 99));
}
@Override
public String getAsText() {
return ((TestBean) getValue()).getName();
}
});
bw.registerCustomEditor(TestBean.class, "list", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(new TestBean("list" + text, 99));
}
@Override
public String getAsText() {
return ((TestBean) getValue()).getName();
}
});
bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(new TestBean("map" + text, 99));
}
@Override
public String getAsText() {
return ((TestBean) getValue()).getName();
}
});
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("array[0]", "a");
pvs.add("array[1]", "b");
pvs.add("list[0]", "c");
pvs.add("list[1]", "d");
pvs.add("map[key1]", "e");
pvs.add("map['key2']", "f");
bw.setPropertyValues(pvs);
assertThat(bean.getArray()[0].getName()).isEqualTo("arraya");
assertThat(bean.getArray()[1].getName()).isEqualTo("arrayb");
assertThat(((TestBean) bean.getList().get(0)).getName()).isEqualTo("listc");
assertThat(((TestBean) bean.getList().get(1)).getName()).isEqualTo("listd");
assertThat(((TestBean) bean.getMap().get("key1")).getName()).isEqualTo("mape");
assertThat(((TestBean) bean.getMap().get("key2")).getName()).isEqualTo("mapf");
}
Aggregations