Package org.springframework.beans

Examples of org.springframework.beans.IndexedTestBean


    XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));

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


    assertTrue(tb.getSet() instanceof TreeSet);
    assertTrue(tb.getSet().isEmpty());
  }

  public void testBindingToIndexedField() {
    IndexedTestBean tb = new IndexedTestBean();
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(String.class, "array.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array" + text);
      }
View Full Code Here

    assertEquals("NOT_ROD.java.lang.String", errors.getFieldError("map[key1].name").getCodes()[5]);
    assertEquals("NOT_ROD", errors.getFieldError("map[key1].name").getCodes()[6]);
  }

  public void testBindingToNestedIndexedField() {
    IndexedTestBean tb = new IndexedTestBean();
    tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
    tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(String.class, "array.nestedIndexedBean.list.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list" + text);
      }
View Full Code Here

        errors.getFieldError("array[0].nestedIndexedBean.list[0].name").getCodes()[7]);
    assertEquals("NOT_ROD", errors.getFieldError("array[0].nestedIndexedBean.list[0].name").getCodes()[8]);
  }

  public void testEditorForNestedIndexedField() {
    IndexedTestBean tb = new IndexedTestBean();
    tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
    tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(String.class, "array.nestedIndexedBean.list.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list" + text);
      }
      public String getAsText() {
        return ((String) getValue()).substring(4);
      }
    });
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0].nestedIndexedBean.list[0].name", "test1");
    pvs.addPropertyValue("array[1].nestedIndexedBean.list[1].name", "test2");
    binder.bind(pvs);
    assertEquals("listtest1", ((TestBean) tb.getArray()[0].getNestedIndexedBean().getList().get(0)).getName());
    assertEquals("listtest2", ((TestBean) tb.getArray()[1].getNestedIndexedBean().getList().get(1)).getName());
    assertEquals("test1", binder.getBindingResult().getFieldValue("array[0].nestedIndexedBean.list[0].name"));
    assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name"));
  }
View Full Code Here

    assertEquals("test1", binder.getBindingResult().getFieldValue("array[0].nestedIndexedBean.list[0].name"));
    assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name"));
  }

  public void testSpecificEditorForNestedIndexedField() {
    IndexedTestBean tb = new IndexedTestBean();
    tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
    tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(String.class, "array[0].nestedIndexedBean.list.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list" + text);
      }
      public String getAsText() {
        return ((String) getValue()).substring(4);
      }
    });
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0].nestedIndexedBean.list[0].name", "test1");
    pvs.addPropertyValue("array[1].nestedIndexedBean.list[1].name", "test2");
    binder.bind(pvs);
    assertEquals("listtest1", ((TestBean) tb.getArray()[0].getNestedIndexedBean().getList().get(0)).getName());
    assertEquals("test2", ((TestBean) tb.getArray()[1].getNestedIndexedBean().getList().get(1)).getName());
    assertEquals("test1", binder.getBindingResult().getFieldValue("array[0].nestedIndexedBean.list[0].name"));
    assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name"));
  }
View Full Code Here

    assertEquals("test1", binder.getBindingResult().getFieldValue("array[0].nestedIndexedBean.list[0].name"));
    assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name"));
  }

  public void testInnerSpecificEditorForNestedIndexedField() {
    IndexedTestBean tb = new IndexedTestBean();
    tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
    tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(String.class, "array.nestedIndexedBean.list[0].name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list" + text);
      }
      public String getAsText() {
        return ((String) getValue()).substring(4);
      }
    });
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("array[0].nestedIndexedBean.list[0].name", "test1");
    pvs.addPropertyValue("array[1].nestedIndexedBean.list[1].name", "test2");
    binder.bind(pvs);
    assertEquals("listtest1", ((TestBean) tb.getArray()[0].getNestedIndexedBean().getList().get(0)).getName());
    assertEquals("test2", ((TestBean) tb.getArray()[1].getNestedIndexedBean().getList().get(1)).getName());
    assertEquals("test1", binder.getBindingResult().getFieldValue("array[0].nestedIndexedBean.list[0].name"));
    assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name"));
  }
View Full Code Here

    assertEquals("test1", binder.getBindingResult().getFieldValue("array[0].nestedIndexedBean.list[0].name"));
    assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name"));
  }

  public void testDirectBindingToIndexedField() {
    IndexedTestBean tb = new IndexedTestBean();
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        DerivedTestBean tb = new DerivedTestBean();
        tb.setName("array" + text);
        setValue(tb);
      }
      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
View Full Code Here

    assertEquals("NOT_NULL.map", errors.getFieldError("map[key0]").getCodes()[3]);
    assertEquals("NOT_NULL", errors.getFieldError("map[key0]").getCodes()[4]);
  }

  public void testDirectBindingToEmptyIndexedFieldWithRegisteredSpecificEditor() {
    IndexedTestBean tb = new IndexedTestBean();
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(TestBean.class, "map[key0]", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        DerivedTestBean tb = new DerivedTestBean();
        tb.setName("array" + text);
        setValue(tb);
      }
      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
View Full Code Here

    assertEquals("NOT_NULL.org.springframework.beans.TestBean", errors.getFieldError("map[key0]").getCodes()[4]);
    assertEquals("NOT_NULL", errors.getFieldError("map[key0]").getCodes()[5]);
  }

  public void testDirectBindingToEmptyIndexedFieldWithRegisteredGenericEditor() {
    IndexedTestBean tb = new IndexedTestBean();
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        DerivedTestBean tb = new DerivedTestBean();
        tb.setName("array" + text);
        setValue(tb);
      }
      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
View Full Code Here

    assertEquals("NOT_NULL.org.springframework.beans.TestBean", errors.getFieldError("map[key0]").getCodes()[4]);
    assertEquals("NOT_NULL", errors.getFieldError("map[key0]").getCodes()[5]);
  }

  public void testCustomEditorWithSubclass() {
    IndexedTestBean tb = new IndexedTestBean();
    DataBinder binder = new DataBinder(tb, "tb");
    binder.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        DerivedTestBean tb = new DerivedTestBean();
        tb.setName("array" + text);
        setValue(tb);
      }
      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
View Full Code Here

TOP

Related Classes of org.springframework.beans.IndexedTestBean

Copyright © 2018 www.massapicom. 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.