use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.
the class CustomEditorTests method testNestedIndexedPropertiesWithCustomEditorForProperty.
@Test
public void testNestedIndexedPropertiesWithCustomEditorForProperty() {
IndexedTestBean bean = new IndexedTestBean();
TestBean tb0 = bean.getArray()[0];
TestBean tb1 = bean.getArray()[1];
TestBean tb2 = ((TestBean) bean.getList().get(0));
TestBean tb3 = ((TestBean) bean.getList().get(1));
TestBean tb4 = ((TestBean) bean.getMap().get("key1"));
TestBean tb5 = ((TestBean) bean.getMap().get("key2"));
tb0.setNestedIndexedBean(new IndexedTestBean());
tb1.setNestedIndexedBean(new IndexedTestBean());
tb2.setNestedIndexedBean(new IndexedTestBean());
tb3.setNestedIndexedBean(new IndexedTestBean());
tb4.setNestedIndexedBean(new IndexedTestBean());
tb5.setNestedIndexedBean(new IndexedTestBean());
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.registerCustomEditor(String.class, "array.nestedIndexedBean.array.name", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue("array" + text);
}
@Override
public String getAsText() {
return ((String) getValue()).substring(5);
}
});
bw.registerCustomEditor(String.class, "list.nestedIndexedBean.list.name", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue("list" + text);
}
@Override
public String getAsText() {
return ((String) getValue()).substring(4);
}
});
bw.registerCustomEditor(String.class, "map.nestedIndexedBean.map.name", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue("map" + text);
}
@Override
public String getAsText() {
return ((String) getValue()).substring(4);
}
});
assertEquals("name0", tb0.getName());
assertEquals("name1", tb1.getName());
assertEquals("name2", tb2.getName());
assertEquals("name3", tb3.getName());
assertEquals("name4", tb4.getName());
assertEquals("name5", tb5.getName());
assertEquals("name0", bw.getPropertyValue("array[0].nestedIndexedBean.array[0].name"));
assertEquals("name1", bw.getPropertyValue("array[1].nestedIndexedBean.array[1].name"));
assertEquals("name2", bw.getPropertyValue("list[0].nestedIndexedBean.list[0].name"));
assertEquals("name3", bw.getPropertyValue("list[1].nestedIndexedBean.list[1].name"));
assertEquals("name4", bw.getPropertyValue("map[key1].nestedIndexedBean.map[key1].name"));
assertEquals("name5", bw.getPropertyValue("map['key2'].nestedIndexedBean.map[\"key2\"].name"));
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("array[0].nestedIndexedBean.array[0].name", "name5");
pvs.add("array[1].nestedIndexedBean.array[1].name", "name4");
pvs.add("list[0].nestedIndexedBean.list[0].name", "name3");
pvs.add("list[1].nestedIndexedBean.list[1].name", "name2");
pvs.add("map[key1].nestedIndexedBean.map[\"key1\"].name", "name1");
pvs.add("map['key2'].nestedIndexedBean.map[key2].name", "name0");
bw.setPropertyValues(pvs);
assertEquals("arrayname5", tb0.getNestedIndexedBean().getArray()[0].getName());
assertEquals("arrayname4", tb1.getNestedIndexedBean().getArray()[1].getName());
assertEquals("listname3", ((TestBean) tb2.getNestedIndexedBean().getList().get(0)).getName());
assertEquals("listname2", ((TestBean) tb3.getNestedIndexedBean().getList().get(1)).getName());
assertEquals("mapname1", ((TestBean) tb4.getNestedIndexedBean().getMap().get("key1")).getName());
assertEquals("mapname0", ((TestBean) tb5.getNestedIndexedBean().getMap().get("key2")).getName());
assertEquals("arrayname5", bw.getPropertyValue("array[0].nestedIndexedBean.array[0].name"));
assertEquals("arrayname4", bw.getPropertyValue("array[1].nestedIndexedBean.array[1].name"));
assertEquals("listname3", bw.getPropertyValue("list[0].nestedIndexedBean.list[0].name"));
assertEquals("listname2", bw.getPropertyValue("list[1].nestedIndexedBean.list[1].name"));
assertEquals("mapname1", bw.getPropertyValue("map['key1'].nestedIndexedBean.map[key1].name"));
assertEquals("mapname0", bw.getPropertyValue("map[key2].nestedIndexedBean.map[\"key2\"].name"));
}
use of org.springframework.beans.MutablePropertyValues in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method testAutowireWithParent.
@Test
public void testAutowireWithParent() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "kerry");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("spouse", bd);
xbf.setParentBeanFactory(lbf);
doTestAutowire(xbf);
}
use of org.springframework.beans.MutablePropertyValues in project spring-boot by spring-projects.
the class WebFilterHandlerTests method asyncSupported.
@Test
public void asyncSupported() throws IOException {
BeanDefinition filterRegistrationBean = getBeanDefinition(AsyncSupportedFilter.class);
MutablePropertyValues propertyValues = filterRegistrationBean.getPropertyValues();
assertThat(propertyValues.get("asyncSupported")).isEqualTo(true);
}
use of org.springframework.beans.MutablePropertyValues in project spring-boot by spring-projects.
the class WebFilterHandlerTests method filterWithCustomName.
@Test
public void filterWithCustomName() throws IOException {
ScannedGenericBeanDefinition scanned = new ScannedGenericBeanDefinition(new SimpleMetadataReaderFactory().getMetadataReader(CustomNameFilter.class.getName()));
this.handler.handle(scanned, this.registry);
BeanDefinition filterRegistrationBean = this.registry.getBeanDefinition("custom");
MutablePropertyValues propertyValues = filterRegistrationBean.getPropertyValues();
assertThat(propertyValues.get("name")).isEqualTo("custom");
}
use of org.springframework.beans.MutablePropertyValues in project spring-boot by spring-projects.
the class WebFilterHandlerTests method initParameters.
@SuppressWarnings("unchecked")
@Test
public void initParameters() throws IOException {
BeanDefinition filterRegistrationBean = getBeanDefinition(InitParametersFilter.class);
MutablePropertyValues propertyValues = filterRegistrationBean.getPropertyValues();
assertThat((Map<String, String>) propertyValues.get("initParameters")).containsEntry("a", "alpha").containsEntry("b", "bravo");
}
Aggregations