Examples of IndexedTestBean


Examples of org.springframework.beans.IndexedTestBean

    assertEquals("mapkey1name1", bw.getPropertyValue("map[\"key1\"].name"));
    assertEquals("mapkey2name0", bw.getPropertyValue("map['key2'].name"));
  }

  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() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array" + text);
      }
View Full Code Here

Examples of org.springframework.beans.IndexedTestBean

    assertEquals("mapname1", bw.getPropertyValue("map['key1'].nestedIndexedBean.map[key1].name"));
    assertEquals("mapname0", bw.getPropertyValue("map[key2].nestedIndexedBean.map[\"key2\"].name"));
  }

  public void testNestedIndexedPropertiesWithIndexedCustomEditorForProperty() {
    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[0].nestedIndexedBean.array[0].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array" + text);
      }
View Full Code Here

Examples of org.springframework.beans.IndexedTestBean

    assertEquals("mapname1", ((TestBean) tb4.getNestedIndexedBean().getMap().get("key1")).getName());
    assertEquals("name0", ((TestBean) tb5.getNestedIndexedBean().getMap().get("key2")).getName());
  }

  public void testIndexedPropertiesWithDirectAccessAndPropertyEditors() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("array" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "list", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("list" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("map" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0]", "a");
    pvs.addPropertyValue("array[1]", "b");
    pvs.addPropertyValue("list[0]", "c");
    pvs.addPropertyValue("list[1]", "d");
    pvs.addPropertyValue("map[key1]", "e");
    pvs.addPropertyValue("map['key2']", "f");
    bw.setPropertyValues(pvs);
    assertEquals("arraya", bean.getArray()[0].getName());
    assertEquals("arrayb", bean.getArray()[1].getName());
    assertEquals("listc", ((TestBean) bean.getList().get(0)).getName());
    assertEquals("listd", ((TestBean) bean.getList().get(1)).getName());
    assertEquals("mape", ((TestBean) bean.getMap().get("key1")).getName());
    assertEquals("mapf", ((TestBean) bean.getMap().get("key2")).getName());
  }
View Full Code Here

Examples of org.springframework.beans.IndexedTestBean

    assertEquals("mape", ((TestBean) bean.getMap().get("key1")).getName());
    assertEquals("mapf", ((TestBean) bean.getMap().get("key2")).getName());
  }

  public void testIndexedPropertiesWithDirectAccessAndSpecificPropertyEditors() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, "array[0]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("array0" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "array[1]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("array1" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "list[0]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("list0" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "list[1]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("list1" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "map[key1]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("mapkey1" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "map[key2]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("mapkey2" + text, 99));
      }

      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0]", "a");
    pvs.addPropertyValue("array[1]", "b");
    pvs.addPropertyValue("list[0]", "c");
    pvs.addPropertyValue("list[1]", "d");
    pvs.addPropertyValue("map[key1]", "e");
    pvs.addPropertyValue("map['key2']", "f");
    bw.setPropertyValues(pvs);
    assertEquals("array0a", bean.getArray()[0].getName());
    assertEquals("array1b", bean.getArray()[1].getName());
    assertEquals("list0c", ((TestBean) bean.getList().get(0)).getName());
    assertEquals("list1d", ((TestBean) bean.getList().get(1)).getName());
    assertEquals("mapkey1e", ((TestBean) bean.getMap().get("key1")).getName());
    assertEquals("mapkey2f", ((TestBean) bean.getMap().get("key2")).getName());
  }
View Full Code Here

Examples of org.springframework.beans.IndexedTestBean

    assertEquals("mapkey1e", ((TestBean) bean.getMap().get("key1")).getName());
    assertEquals("mapkey2f", ((TestBean) bean.getMap().get("key2")).getName());
  }

  public void testIndexedPropertiesWithListPropertyEditor() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(List.class, "list", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        List result = new ArrayList();
        result.add(new TestBean("list" + text, 99));
        setValue(result);
      }
    });
    bw.setPropertyValue("list", "1");
    assertEquals("list1", ((TestBean) bean.getList().get(0)).getName());
    bw.setPropertyValue("list[0]", "test");
    assertEquals("test", bean.getList().get(0));
  }
View Full Code Here

Examples of org.springframework.beans.IndexedTestBean

    assertEquals(1, tb.getHashtable().size());
    assertEquals("bar", tb.getHashtable().get("foo"));
  }

  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"));
  }
View Full Code Here

Examples of org.springframework.beans.IndexedTestBean

    assertEquals(pe, bw.findCustomEditor(int.class, "list[0].age"));
    assertEquals(pe, bw.findCustomEditor(null, "list[0].age"));
  }

  public void testArrayToArrayConversion() throws PropertyVetoException {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
      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());
  }
View Full Code Here

Examples of org.springframework.beans.IndexedTestBean

  }

  public void testNestedPropertyValue() {
    XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
    XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
    IndexedTestBean bean = (IndexedTestBean) child.getBean("indexedTestBean");
    assertEquals("name applied correctly", "myname", bean.getArray()[0].getName());
  }
View Full Code Here

Examples of org.springframework.beans.IndexedTestBean

    DependenciesBean rod2a = (DependenciesBean) xbf.getBean("rod2a");
    // should have been set explicitly
    assertEquals(kerry, rod2a.getSpouse());

    ConstructorDependenciesBean rod3 = (ConstructorDependenciesBean) xbf.getBean("rod3");
    IndexedTestBean other = (IndexedTestBean) xbf.getBean("other");
    // should have been autowired
    assertEquals(kerry, rod3.getSpouse1());
    assertEquals(kerry, rod3.getSpouse2());
    assertEquals(other, rod3.getOther());
View Full Code Here

Examples of org.springframework.beans.IndexedTestBean

    assertEquals(kerry1, rod2.getSpouse2());
    assertEquals(0, rod2.getAge());
    assertEquals(null, rod2.getName());

    ConstructorDependenciesBean rod = (ConstructorDependenciesBean) xbf.getBean("rod3");
    IndexedTestBean other = (IndexedTestBean) xbf.getBean("other");
    // should have been autowired
    assertEquals(kerry, rod.getSpouse1());
    assertEquals(kerry, rod.getSpouse2());
    assertEquals(other, rod.getOther());
    assertEquals(0, rod.getAge());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.