public void testIndexedPropertiesWithDirectAccess() { IndexedTestBean bean = new IndexedTestBean(); BeanWrapper bw = new BeanWrapperImpl(bean); 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 tb6 = ((TestBean) bean.getSet().toArray()[0]); TestBean tb7 = ((TestBean) bean.getSet().toArray()[1]); TestBean tb4 = ((TestBean) bean.getMap().get("key1")); TestBean tb5 = ((TestBean) bean.getMap().get("key2")); assertEquals(tb0, bw.getPropertyValue("array[0]")); assertEquals(tb1, bw.getPropertyValue("array[1]")); assertEquals(tb2, bw.getPropertyValue("list[0]")); assertEquals(tb3, bw.getPropertyValue("list[1]")); assertEquals(tb6, bw.getPropertyValue("set[0]")); assertEquals(tb7, bw.getPropertyValue("set[1]")); assertEquals(tb4, bw.getPropertyValue("map[key1]")); assertEquals(tb5, bw.getPropertyValue("map[key2]")); assertEquals(tb4, bw.getPropertyValue("map['key1']")); assertEquals(tb5, bw.getPropertyValue("map[\"key2\"]")); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue("array[0]", tb5); pvs.addPropertyValue("array[1]", tb4); pvs.addPropertyValue("list[0]", tb3); pvs.addPropertyValue("list[1]", tb2); pvs.addPropertyValue("list[2]", tb0); pvs.addPropertyValue("list[4]", tb1); pvs.addPropertyValue("map[key1]", tb1); pvs.addPropertyValue("map['key2']", tb0); pvs.addPropertyValue("map[key5]", tb4); pvs.addPropertyValue("map['key9']", tb5); bw.setPropertyValues(pvs); assertEquals(tb5, bean.getArray()[0]); assertEquals(tb4, bean.getArray()[1]); assertEquals(tb3, ((TestBean) bean.getList().get(0))); assertEquals(tb2, ((TestBean) bean.getList().get(1))); assertEquals(tb0, ((TestBean) bean.getList().get(2))); assertEquals(null, ((TestBean) bean.getList().get(3))); assertEquals(tb1, ((TestBean) bean.getList().get(4))); assertEquals(tb1, ((TestBean) bean.getMap().get("key1"))); assertEquals(tb0, ((TestBean) bean.getMap().get("key2"))); assertEquals(tb4, ((TestBean) bean.getMap().get("key5"))); assertEquals(tb5, ((TestBean) bean.getMap().get("key9"))); assertEquals(tb5, bw.getPropertyValue("array[0]")); assertEquals(tb4, bw.getPropertyValue("array[1]")); assertEquals(tb3, bw.getPropertyValue("list[0]")); assertEquals(tb2, bw.getPropertyValue("list[1]")); assertEquals(tb0, bw.getPropertyValue("list[2]")); assertEquals(null, bw.getPropertyValue("list[3]")); assertEquals(tb1, bw.getPropertyValue("list[4]")); assertEquals(tb1, bw.getPropertyValue("map[\"key1\"]")); assertEquals(tb0, bw.getPropertyValue("map['key2']")); assertEquals(tb4, bw.getPropertyValue("map[\"key5\"]")); assertEquals(tb5, bw.getPropertyValue("map['key9']")); }
public void testIndexedProperties() { IndexedTestBean bean = new IndexedTestBean(); BeanWrapper bw = new BeanWrapperImpl(bean); 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 tb6 = ((TestBean) bean.getSet().toArray()[0]); TestBean tb7 = ((TestBean) bean.getSet().toArray()[1]); TestBean tb4 = ((TestBean) bean.getMap().get("key1")); TestBean tb5 = ((TestBean) bean.getMap().get("key2")); assertEquals("name0", tb0.getName()); assertEquals("name1", tb1.getName()); assertEquals("name2", tb2.getName()); assertEquals("name3", tb3.getName()); assertEquals("name6", tb6.getName()); assertEquals("name7", tb7.getName()); assertEquals("name4", tb4.getName()); assertEquals("name5", tb5.getName()); assertEquals("name0", bw.getPropertyValue("array[0].name")); assertEquals("name1", bw.getPropertyValue("array[1].name")); assertEquals("name2", bw.getPropertyValue("list[0].name")); assertEquals("name3", bw.getPropertyValue("list[1].name")); assertEquals("name6", bw.getPropertyValue("set[0].name")); assertEquals("name7", bw.getPropertyValue("set[1].name")); assertEquals("name4", bw.getPropertyValue("map[key1].name")); assertEquals("name5", bw.getPropertyValue("map[key2].name")); assertEquals("name4", bw.getPropertyValue("map['key1'].name")); assertEquals("name5", bw.getPropertyValue("map[\"key2\"].name")); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue("array[0].name", "name5"); pvs.addPropertyValue("array[1].name", "name4"); pvs.addPropertyValue("list[0].name", "name3"); pvs.addPropertyValue("list[1].name", "name2"); pvs.addPropertyValue("set[0].name", "name8"); pvs.addPropertyValue("set[1].name", "name9"); pvs.addPropertyValue("map[key1].name", "name1"); pvs.addPropertyValue("map['key2'].name", "name0"); bw.setPropertyValues(pvs); assertEquals("name5", tb0.getName()); assertEquals("name4", tb1.getName()); assertEquals("name3", tb2.getName()); assertEquals("name2", tb3.getName()); assertEquals("name1", tb4.getName()); assertEquals("name0", tb5.getName()); assertEquals("name5", bw.getPropertyValue("array[0].name")); assertEquals("name4", bw.getPropertyValue("array[1].name")); assertEquals("name3", bw.getPropertyValue("list[0].name")); assertEquals("name2", bw.getPropertyValue("list[1].name")); assertEquals("name8", bw.getPropertyValue("set[0].name")); assertEquals("name9", bw.getPropertyValue("set[1].name")); assertEquals("name1", bw.getPropertyValue("map[\"key1\"].name")); assertEquals("name0", bw.getPropertyValue("map['key2'].name")); }
public void testIndexedPropertiesWithCustomEditorForType() { IndexedTestBean bean = new IndexedTestBean(); BeanWrapper bw = new BeanWrapperImpl(bean); bw.registerCustomEditor( String.class, null, new PropertyEditorSupport() { public void setAsText(String text) throws IllegalArgumentException { setValue("prefix" + text); } }); 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")); 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].name")); assertEquals("name1", bw.getPropertyValue("array[1].name")); assertEquals("name2", bw.getPropertyValue("list[0].name")); assertEquals("name3", bw.getPropertyValue("list[1].name")); assertEquals("name4", bw.getPropertyValue("map[key1].name")); assertEquals("name5", bw.getPropertyValue("map[key2].name")); assertEquals("name4", bw.getPropertyValue("map['key1'].name")); assertEquals("name5", bw.getPropertyValue("map[\"key2\"].name")); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue("array[0].name", "name5"); pvs.addPropertyValue("array[1].name", "name4"); pvs.addPropertyValue("list[0].name", "name3"); pvs.addPropertyValue("list[1].name", "name2"); pvs.addPropertyValue("map[key1].name", "name1"); pvs.addPropertyValue("map['key2'].name", "name0"); bw.setPropertyValues(pvs); assertEquals("prefixname5", tb0.getName()); assertEquals("prefixname4", tb1.getName()); assertEquals("prefixname3", tb2.getName()); assertEquals("prefixname2", tb3.getName()); assertEquals("prefixname1", tb4.getName()); assertEquals("prefixname0", tb5.getName()); assertEquals("prefixname5", bw.getPropertyValue("array[0].name")); assertEquals("prefixname4", bw.getPropertyValue("array[1].name")); assertEquals("prefixname3", bw.getPropertyValue("list[0].name")); assertEquals("prefixname2", bw.getPropertyValue("list[1].name")); assertEquals("prefixname1", bw.getPropertyValue("map[\"key1\"].name")); assertEquals("prefixname0", bw.getPropertyValue("map['key2'].name")); }