Package org.springframework.tests.sample.beans

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


  }

  @SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
  @Test
  public void testCollectionsWithStringValues() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    List<String> set = new LinkedList<String>();
    set.add("set1");
    bw.setPropertyValue("set", "set1");
    List<String> sortedSet = new ArrayList<String>();
    sortedSet.add("sortedSet1");
    bw.setPropertyValue("sortedSet", "sortedSet1");
    Set<String> list = new HashSet<String>();
    list.add("list1");
    bw.setPropertyValue("list", "list1");
    assertEquals(1, tb.getSet().size());
    assertTrue(tb.getSet().containsAll(set));
    assertEquals(1, tb.getSortedSet().size());
    assertTrue(tb.getSortedSet().containsAll(sortedSet));
    assertEquals(1, tb.getList().size());
    assertTrue(tb.getList().containsAll(list));
  }
View Full Code Here


    assertTrue(tb.getList().containsAll(list));
  }

  @Test
  public void testCollectionsWithStringValuesAndCustomEditor() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(String.class, "set", new StringTrimmerEditor(false));
    bw.registerCustomEditor(String.class, "list", new StringTrimmerEditor(false));

    bw.setPropertyValue("set", "set1 ");
    bw.setPropertyValue("sortedSet", "sortedSet1");
    bw.setPropertyValue("list", "list1 ");
    assertEquals(1, tb.getSet().size());
    assertTrue(tb.getSet().contains("set1"));
    assertEquals(1, tb.getSortedSet().size());
    assertTrue(tb.getSortedSet().contains("sortedSet1"));
    assertEquals(1, tb.getList().size());
    assertTrue(tb.getList().contains("list1"));

    bw.setPropertyValue("list", Arrays.asList(new String[] {"list1 "}));
    assertTrue(tb.getList().contains("list1"));
  }
View Full Code Here

    assertTrue(tb.getList().contains("list1"));
  }

  @Test
  public void testMatchingMaps() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    Map<String, String> map = new HashMap<String, String>();
    map.put("key", "value");
    bw.setPropertyValue("map", map);
    SortedMap<?, ?> sortedMap = new TreeMap<Object, Object>();
    map.put("sortedKey", "sortedValue");
    bw.setPropertyValue("sortedMap", sortedMap);
    assertSame(map, tb.getMap());
    assertSame(sortedMap, tb.getSortedMap());
  }
View Full Code Here

    assertSame(sortedMap, tb.getSortedMap());
  }

  @Test
  public void testNonMatchingMaps() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    Map<String, String> map = new TreeMap<String, String>();
    map.put("key", "value");
    bw.setPropertyValue("map", map);
    Map<String, String> sortedMap = new TreeMap<String, String>();
    sortedMap.put("sortedKey", "sortedValue");
    bw.setPropertyValue("sortedMap", sortedMap);
    assertEquals(1, tb.getMap().size());
    assertEquals("value", tb.getMap().get("key"));
    assertEquals(1, tb.getSortedMap().size());
    assertEquals("sortedValue", tb.getSortedMap().get("sortedKey"));
  }
View Full Code Here

    assertEquals("", editor.getAsText());
  }

  @Test
  public void testIndexedPropertiesWithCustomEditorForType() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
      @Override
      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());
View Full Code Here

    assertEquals("prefixname0", bw.getPropertyValue("map['key2'].name"));
  }

  @Test
  public void testIndexedPropertiesWithCustomEditorForProperty() {
    IndexedTestBean bean = new IndexedTestBean(false);
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(String.class, "array.name", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array" + text);
      }
    });
    bw.registerCustomEditor(String.class, "list.name", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list" + text);
      }
    });
    bw.registerCustomEditor(String.class, "map.name", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("map" + text);
      }
    });
    bean.populate();

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

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

  @Test
  public void testIndexedPropertiesWithIndividualCustomEditorForProperty() {
    IndexedTestBean bean = new IndexedTestBean(false);
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(String.class, "array[0].name", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array0" + text);
      }
    });
    bw.registerCustomEditor(String.class, "array[1].name", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("array1" + text);
      }
    });
    bw.registerCustomEditor(String.class, "list[0].name", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list0" + text);
      }
    });
    bw.registerCustomEditor(String.class, "list[1].name", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("list1" + text);
      }
    });
    bw.registerCustomEditor(String.class, "map[key1].name", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("mapkey1" + text);
      }
    });
    bw.registerCustomEditor(String.class, "map[key2].name", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("mapkey2" + text);
      }
    });
    bean.populate();

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

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

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

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

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

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

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

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

      @Override
      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
    });
    bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean("map" + 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("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

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.