Package org.springframework.beans

Examples of org.springframework.beans.TestBean


    assertTrue("spouse name is Kerry and age is 34",
        tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34);
  }

  public void testComplexObjectWithOldValueAccess() {
    TestBean tb = new TestBean();
    String newName = "Rod";
    String tbString = "Kerry_34";

    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.setExtractOldValueForEditor(true);
    bw.registerCustomEditor(ITestBean.class, new OldValueAccessingTestBeanEditor());
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue(new PropertyValue("age", new Integer(55)));
    pvs.addPropertyValue(new PropertyValue("name", newName));
    pvs.addPropertyValue(new PropertyValue("touchy", "valid"));
    pvs.addPropertyValue(new PropertyValue("spouse", tbString));

    bw.setPropertyValues(pvs);
    assertTrue("spouse is non-null", tb.getSpouse() != null);
    assertTrue("spouse name is Kerry and age is 34",
        tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34);
    ITestBean spouse = tb.getSpouse();

    bw.setPropertyValues(pvs);
    assertSame("Should have remained same object", spouse, tb.getSpouse());
  }
View Full Code Here


    bw.setPropertyValues(pvs);
    assertSame("Should have remained same object", spouse, tb.getSpouse());
  }

  public void testCustomEditorForSingleProperty() {
    TestBean tb = new TestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(String.class, "name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("prefix" + text);
      }
    });
    bw.setPropertyValue("name", "value");
    bw.setPropertyValue("touchy", "value");
    assertEquals("prefixvalue", bw.getPropertyValue("name"));
    assertEquals("prefixvalue", tb.getName());
    assertEquals("value", bw.getPropertyValue("touchy"));
    assertEquals("value", tb.getTouchy());
  }
View Full Code Here

    assertEquals("value", bw.getPropertyValue("touchy"));
    assertEquals("value", tb.getTouchy());
  }

  public void testCustomEditorForAllStringProperties() {
    TestBean tb = new TestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("prefix" + text);
      }
    });
    bw.setPropertyValue("name", "value");
    bw.setPropertyValue("touchy", "value");
    assertEquals("prefixvalue", bw.getPropertyValue("name"));
    assertEquals("prefixvalue", tb.getName());
    assertEquals("prefixvalue", bw.getPropertyValue("touchy"));
    assertEquals("prefixvalue", tb.getTouchy());
  }
View Full Code Here

    assertEquals("prefixvalue", bw.getPropertyValue("touchy"));
    assertEquals("prefixvalue", tb.getTouchy());
  }

  public void testCustomEditorForSingleNestedProperty() {
    TestBean tb = new TestBean();
    tb.setSpouse(new TestBean());
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(String.class, "spouse.name", new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("prefix" + text);
      }
    });
    bw.setPropertyValue("spouse.name", "value");
    bw.setPropertyValue("touchy", "value");
    assertEquals("prefixvalue", bw.getPropertyValue("spouse.name"));
    assertEquals("prefixvalue", tb.getSpouse().getName());
    assertEquals("value", bw.getPropertyValue("touchy"));
    assertEquals("value", tb.getTouchy());
  }
View Full Code Here

    assertEquals("value", bw.getPropertyValue("touchy"));
    assertEquals("value", tb.getTouchy());
  }

  public void testCustomEditorForAllNestedStringProperties() {
    TestBean tb = new TestBean();
    tb.setSpouse(new TestBean());
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
      public void setAsText(String text) throws IllegalArgumentException {
        setValue("prefix" + text);
      }
    });
    bw.setPropertyValue("spouse.name", "value");
    bw.setPropertyValue("touchy", "value");
    assertEquals("prefixvalue", bw.getPropertyValue("spouse.name"));
    assertEquals("prefixvalue", tb.getSpouse().getName());
    assertEquals("prefixvalue", bw.getPropertyValue("touchy"));
    assertEquals("prefixvalue", tb.getTouchy());
  }
View Full Code Here

  }

  public void testRefSubelement() throws Exception {
    XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
    //assertTrue("5 beans in reftypes, not " + xbf.getBeanDefinitionCount(), xbf.getBeanDefinitionCount() == 5);
    TestBean jen = (TestBean) xbf.getBean("jenny");
    TestBean dave = (TestBean) xbf.getBean("david");
    assertTrue(jen.getSpouse() == dave);
  }
View Full Code Here

    assertTrue(jen.getSpouse() == dave);
  }

  public void testPropertyWithLiteralValueSubelement() throws Exception {
    XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
    TestBean verbose = (TestBean) xbf.getBean("verbose");
    assertTrue(verbose.getName().equals("verbose"));
  }
View Full Code Here

    assertTrue(verbose.getName().equals("verbose"));
  }

  public void testPropertyWithIdRefLocalAttrSubelement() throws Exception {
    XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
    TestBean verbose = (TestBean) xbf.getBean("verbose2");
    assertTrue(verbose.getName().equals("verbose"));
  }
View Full Code Here

    assertTrue(verbose.getName().equals("verbose"));
  }

  public void testPropertyWithIdRefBeanAttrSubelement() throws Exception {
    XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
    TestBean verbose = (TestBean) xbf.getBean("verbose3");
    assertTrue(verbose.getName().equals("verbose"));
  }
View Full Code Here

    assertTrue(verbose.getName().equals("verbose"));
  }

  public void testRefSubelementsBuildCollection() throws Exception {
    XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
    TestBean jen = (TestBean) xbf.getBean("jenny");
    TestBean dave = (TestBean) xbf.getBean("david");
    TestBean rod = (TestBean) xbf.getBean("rod");

    // Must be a list to support ordering
    // Our bean doesn't modify the collection:
    // of course it could be a different copy in a real object.
    Object[] friends = rod.getFriends().toArray();
    assertTrue(friends.length == 2);

    assertTrue("First friend must be jen, not " + friends[0], friends[0] == jen);
    assertTrue(friends[1] == dave);
    // Should be ordered
View Full Code Here

TOP

Related Classes of org.springframework.beans.TestBean

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.