Package org.springframework.tests.sample.beans

Examples of org.springframework.tests.sample.beans.IndexedTestBean


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

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

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

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

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

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

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

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

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("array[0]", "a");
    pvs.add("array[1]", "b");
    pvs.add("list[0]", "c");
    pvs.add("list[1]", "d");
    pvs.add("map[key1]", "e");
    pvs.add("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


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

  @Test
  public void testIndexedPropertiesWithListPropertyEditor() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(List.class, "list", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        List<TestBean> result = new ArrayList<TestBean>();
        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

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

  @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<Object>());
    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

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

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

    props.setProperty("tb.array[0].age", "99");
    props.setProperty("tb.list[1].name", "test");
    poc.setProperties(props);
    poc.postProcessBeanFactory(factory);

    IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

    props.setProperty("my.tb_list[1].name", "test");
    poc.setProperties(props);
    poc.setBeanNameSeparator("_");
    poc.postProcessBeanFactory(factory);

    IndexedTestBean tb = (IndexedTestBean) factory.getBean("my.tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

    props.setProperty("tb.map[key1]", "99");
    props.setProperty("tb.map[key2.ext]", "test");
    poc.setProperties(props);
    poc.postProcessBeanFactory(factory);

    IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
    assertEquals("99", tb.getMap().get("key1"));
    assertEquals("test", tb.getMap().get("key2.ext"));
  }
View Full Code Here

    PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
    poc.setLocation(TEST_PROPS);
    poc.postProcessBeanFactory(factory);

    IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

    PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
    poc.setLocations(new Resource[] { TEST_PROPS, XTEST_PROPS });
    poc.setIgnoreResourceNotFound(true);
    poc.postProcessBeanFactory(factory);

    IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

    PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
    poc.setLocation(TEST_PROPS_XML);
    poc.postProcessBeanFactory(factory);

    IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
    assertEquals(99, tb.getArray()[0].getAge());
    assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
  }
View Full Code Here

TOP

Related Classes of org.springframework.tests.sample.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.