use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class CustomEditorTests method testUninitializedArrayPropertyWithCustomEditor.
@Test
public void testUninitializedArrayPropertyWithCustomEditor() {
IndexedTestBean bean = new IndexedTestBean(false);
BeanWrapper bw = new BeanWrapperImpl(bean);
PropertyEditor pe = new CustomNumberEditor(Integer.class, true);
bw.registerCustomEditor(null, "list.age", pe);
TestBean tb = new TestBean();
bw.setPropertyValue("list", new ArrayList<>());
bw.setPropertyValue("list[0]", tb);
assertEquals(tb, bean.getList().get(0));
assertEquals(pe, bw.findCustomEditor(int.class, "list.age"));
assertEquals(pe, bw.findCustomEditor(null, "list.age"));
assertEquals(pe, bw.findCustomEditor(int.class, "list[0].age"));
assertEquals(pe, bw.findCustomEditor(null, "list[0].age"));
}
use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class CustomEditorTests method testArrayToArrayConversion.
@Test
public void testArrayToArrayConversion() throws PropertyVetoException {
IndexedTestBean tb = new IndexedTestBean();
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(new TestBean(text, 99));
}
});
bw.setPropertyValue("array", new String[] { "a", "b" });
assertEquals(2, tb.getArray().length);
assertEquals("a", tb.getArray()[0].getName());
assertEquals("b", tb.getArray()[1].getName());
}
use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method testNestedPropertyValue.
@Test
public void testNestedPropertyValue() {
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
IndexedTestBean bean = (IndexedTestBean) child.getBean("indexedTestBean");
assertEquals("name applied correctly", "myname", bean.getArray()[0].getName());
}
use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method testAutowireByConstructorWithSimpleValues.
@Test
public void testAutowireByConstructorWithSimpleValues() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
ConstructorDependenciesBean rod5 = (ConstructorDependenciesBean) xbf.getBean("rod5");
TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
TestBean kerry2 = (TestBean) xbf.getBean("kerry2");
IndexedTestBean other = (IndexedTestBean) xbf.getBean("other");
// should have been autowired
assertEquals(kerry2, rod5.getSpouse1());
assertEquals(kerry1, rod5.getSpouse2());
assertEquals(other, rod5.getOther());
assertEquals(99, rod5.getAge());
assertEquals("myname", rod5.getName());
DerivedConstructorDependenciesBean rod6 = (DerivedConstructorDependenciesBean) xbf.getBean("rod6");
// should have been autowired
assertTrue(rod6.initialized);
assertTrue(!rod6.destroyed);
assertEquals(kerry2, rod6.getSpouse1());
assertEquals(kerry1, rod6.getSpouse2());
assertEquals(other, rod6.getOther());
assertEquals(0, rod6.getAge());
assertEquals(null, rod6.getName());
xbf.destroySingletons();
assertTrue(rod6.destroyed);
}
use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method setMapProperty.
@Test
public void setMapProperty() {
IndexedTestBean target = new IndexedTestBean();
AbstractPropertyAccessor accessor = createAccessor(target);
Map<String, String> map = new HashMap<>();
map.put("key", "value");
accessor.setPropertyValue("map", map);
SortedMap<?, ?> sortedMap = new TreeMap<>();
map.put("sortedKey", "sortedValue");
accessor.setPropertyValue("sortedMap", sortedMap);
assertSame(map, target.getMap());
assertSame(sortedMap, target.getSortedMap());
}
Aggregations