Package org.springframework.tests.sample.beans

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


    assertEquals("nameB", bw.getPropertyValue("map[key4][1].name"));
  }

  @Test
  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.add("array[0]", tb5);
    pvs.add("array[1]", tb4);
    pvs.add("list[0]", tb3);
    pvs.add("list[1]", tb2);
    pvs.add("list[2]", tb0);
    pvs.add("list[4]", tb1);
    pvs.add("map[key1]", tb1);
    pvs.add("map['key2']", tb0);
    pvs.add("map[key5]", tb4);
    pvs.add("map['key9']", tb5);
    bw.setPropertyValues(pvs);
    assertEquals(tb5, bean.getArray()[0]);
    assertEquals(tb4, bean.getArray()[1]);
    assertEquals(tb3, (bean.getList().get(0)));
    assertEquals(tb2, (bean.getList().get(1)));
    assertEquals(tb0, (bean.getList().get(2)));
    assertEquals(null, (bean.getList().get(3)));
    assertEquals(tb1, (bean.getList().get(4)));
    assertEquals(tb1, (bean.getMap().get("key1")));
    assertEquals(tb0, (bean.getMap().get("key2")));
    assertEquals(tb4, (bean.getMap().get("key5")));
    assertEquals(tb5, (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]"));
View Full Code Here


    assertEquals(tb5, bw.getPropertyValue("map['key9']"));
  }

  @Test
  public void testMapAccessWithTypeConversion() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        if (!StringUtils.hasLength(text)) {
          throw new IllegalArgumentException();
        }
        setValue(new TestBean(text));
      }
    });

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("map[key1]", "rod");
    pvs.add("map[key2]", "rob");
    bw.setPropertyValues(pvs);
    assertEquals("rod", ((TestBean) bean.getMap().get("key1")).getName());
    assertEquals("rob", ((TestBean) bean.getMap().get("key2")).getName());

    pvs = new MutablePropertyValues();
    pvs.add("map[key1]", "rod");
    pvs.add("map[key2]", "");
    try {
View Full Code Here

    }
  }

  @Test
  public void testMapAccessWithUnmodifiableMap() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        if (!StringUtils.hasLength(text)) {
          throw new IllegalArgumentException();
        }
        setValue(new TestBean(text));
      }
    });

    Map<Integer, String> inputMap = new HashMap<Integer, String>();
    inputMap.put(new Integer(1), "rod");
    inputMap.put(new Integer(2), "rob");
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("map", Collections.unmodifiableMap(inputMap));
    bw.setPropertyValues(pvs);
    assertEquals("rod", ((TestBean) bean.getMap().get(new Integer(1))).getName());
    assertEquals("rob", ((TestBean) bean.getMap().get(new Integer(2))).getName());
  }
View Full Code Here

    assertEquals("rob", ((TestBean) bean.getMap().get(new Integer(2))).getName());
  }

  @Test
  public void testMapAccessWithCustomUnmodifiableMap() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        if (!StringUtils.hasLength(text)) {
          throw new IllegalArgumentException();
        }
        setValue(new TestBean(text));
      }
    });

    Map<Object, Object> inputMap = new HashMap<Object, Object>();
    inputMap.put(new Integer(1), "rod");
    inputMap.put(new Integer(2), "rob");
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("map", new ReadOnlyMap(inputMap));
    bw.setPropertyValues(pvs);
    assertEquals("rod", ((TestBean) bean.getMap().get(new Integer(1))).getName());
    assertEquals("rob", ((TestBean) bean.getMap().get(new Integer(2))).getName());
  }
View Full Code Here

  }

  @SuppressWarnings("unchecked") // must work with raw map in this test
  @Test
  public void testRawMapAccessWithNoEditorRegistered() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    Map inputMap = new HashMap();
    inputMap.put(new Integer(1), "rod");
    inputMap.put(new Integer(2), "rob");
    ReadOnlyMap readOnlyMap = new ReadOnlyMap(inputMap);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("map", readOnlyMap);
    bw.setPropertyValues(pvs);
    assertSame(readOnlyMap, bean.getMap());
    assertFalse(readOnlyMap.isAccessed());
  }
View Full Code Here

    }
  }

  @Test
  public void testMatchingCollections() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    Collection<String> coll = new HashSet<String>();
    coll.add("coll1");
    bw.setPropertyValue("collection", coll);
    Set<String> set = new HashSet<String>();
    set.add("set1");
    bw.setPropertyValue("set", set);
    SortedSet<String> sortedSet = new TreeSet<String>();
    sortedSet.add("sortedSet1");
    bw.setPropertyValue("sortedSet", sortedSet);
    List<String> list = new LinkedList<String>();
    list.add("list1");
    bw.setPropertyValue("list", list);
    assertSame(coll, tb.getCollection());
    assertSame(set, tb.getSet());
    assertSame(sortedSet, tb.getSortedSet());
    assertSame(list, tb.getList());
  }
View Full Code Here

  }

  @SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
  @Test
  public void testNonMatchingCollections() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    Collection<String> coll = new ArrayList<String>();
    coll.add("coll1");
    bw.setPropertyValue("collection", coll);
    List<String> set = new LinkedList<String>();
    set.add("set1");
    bw.setPropertyValue("set", set);
    List<String> sortedSet = new ArrayList<String>();
    sortedSet.add("sortedSet1");
    bw.setPropertyValue("sortedSet", sortedSet);
    Set<String> list = new HashSet<String>();
    list.add("list1");
    bw.setPropertyValue("list", list);
    assertEquals(1, tb.getCollection().size());
    assertTrue(tb.getCollection().containsAll(coll));
    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

  }

  @SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
  @Test
  public void testCollectionsWithArrayValues() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    Collection<String> coll = new HashSet<String>();
    coll.add("coll1");
    bw.setPropertyValue("collection", coll.toArray());
    List<String> set = new LinkedList<String>();
    set.add("set1");
    bw.setPropertyValue("set", set.toArray());
    List<String> sortedSet = new ArrayList<String>();
    sortedSet.add("sortedSet1");
    bw.setPropertyValue("sortedSet", sortedSet.toArray());
    Set<String> list = new HashSet<String>();
    list.add("list1");
    bw.setPropertyValue("list", list.toArray());
    assertEquals(1, tb.getCollection().size());
    assertTrue(tb.getCollection().containsAll(coll));
    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

  }

  @SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
  @Test
  public void testCollectionsWithIntArrayValues() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    Collection<Integer> coll = new HashSet<Integer>();
    coll.add(new Integer(0));
    bw.setPropertyValue("collection", new int[] {0});
    List<Integer> set = new LinkedList<Integer>();
    set.add(new Integer(1));
    bw.setPropertyValue("set", new int[] {1});
    List<Integer> sortedSet = new ArrayList<Integer>();
    sortedSet.add(new Integer(2));
    bw.setPropertyValue("sortedSet", new int[] {2});
    Set<Integer> list = new HashSet<Integer>();
    list.add(new Integer(3));
    bw.setPropertyValue("list", new int[] {3});
    assertEquals(1, tb.getCollection().size());
    assertTrue(tb.getCollection().containsAll(coll));
    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

  }

  @SuppressWarnings("unchecked") // list cannot be properly parameterized as it breaks other tests
  @Test
  public void testCollectionsWithIntegerValues() {
    IndexedTestBean tb = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    Collection<Integer> coll = new HashSet<Integer>();
    coll.add(new Integer(0));
    bw.setPropertyValue("collection", new Integer(0));
    List<Integer> set = new LinkedList<Integer>();
    set.add(new Integer(1));
    bw.setPropertyValue("set", new Integer(1));
    List<Integer> sortedSet = new ArrayList<Integer>();
    sortedSet.add(new Integer(2));
    bw.setPropertyValue("sortedSet", new Integer(2));
    Set<Integer> list = new HashSet<Integer>();
    list.add(new Integer(3));
    bw.setPropertyValue("list", new Integer(3));
    assertEquals(1, tb.getCollection().size());
    assertTrue(tb.getCollection().containsAll(coll));
    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

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.