public void testGetNestedProperty() {
   ITestBean rod = new TestBean("rod", 31);
   ITestBean kerry = new TestBean("kerry", 35);
   rod.setSpouse(kerry);
   kerry.setSpouse(rod);
   BeanWrapper bw = new BeanWrapperImpl(rod);
   Integer KA = (Integer) bw.getPropertyValue("spouse.age");
   assertTrue("kerry is 35", KA.intValue() == 35);
   Integer RA = (Integer) bw.getPropertyValue("spouse.spouse.age");
   assertTrue("rod is 31, not" + RA, RA.intValue() == 31);
   ITestBean spousesSpouse = (ITestBean) bw.getPropertyValue("spouse.spouse");
   assertTrue("spousesSpouse = initial point", rod == spousesSpouse);
 }
  public void testGetNestedPropertyNullValue() throws Exception {
    ITestBean rod = new TestBean("rod", 31);
    ITestBean kerry = new TestBean("kerry", 35);
    rod.setSpouse(kerry);

    BeanWrapper bw = new BeanWrapperImpl(rod);
    try {
      bw.getPropertyValue("spouse.spouse.age");
      fail("Shouldn't have succeded with null path");
    } catch (NullValueInNestedPathException ex) {
      // ok
      assertTrue(
          "it was the spouse property that was null, not " + ex.getPropertyName(),
          ex.getPropertyName().equals("spouse"));
    }
  }
 public void testSetPropertyValuesIgnoresInvalidNestedOnRequest() {
   ITestBean rod = new TestBean();
   MutablePropertyValues pvs = new MutablePropertyValues();
   pvs.addPropertyValue(new PropertyValue("name", "rod"));
   pvs.addPropertyValue(new PropertyValue("graceful.rubbish", "tony"));
   pvs.addPropertyValue(new PropertyValue("more.garbage", new Object()));
   BeanWrapper bw = new BeanWrapperImpl(rod);
   bw.setPropertyValues(pvs, true);
   assertTrue("Set valid and ignored invalid", rod.getName().equals("rod"));
   try {
     // Don't ignore: should fail
     bw.setPropertyValues(pvs, false);
     fail("Shouldn't have ignored invalid updates");
   } catch (NotWritablePropertyException ex) {
     // OK: but which exception??
   }
 }
  public void testSetNestedProperty() throws Exception {
    ITestBean rod = new TestBean("rod", 31);
    ITestBean kerry = new TestBean("kerry", 0);

    BeanWrapper bw = new BeanWrapperImpl(rod);
    bw.setPropertyValue("spouse", kerry);

    assertTrue("nested set worked", rod.getSpouse() == kerry);
    assertTrue("no back relation", kerry.getSpouse() == null);
    bw.setPropertyValue(new PropertyValue("spouse.spouse", rod));
    assertTrue("nested set worked", kerry.getSpouse() == rod);
    assertTrue("kerry age not set", kerry.getAge() == 0);
    bw.setPropertyValue(new PropertyValue("spouse.age", new Integer(35)));
    assertTrue("Set primitive on spouse", kerry.getAge() == 35);
  }
  public void testSetNestedPropertyPolymorphic() throws Exception {
    ITestBean rod = new TestBean("rod", 31);
    ITestBean kerry = new Employee();

    BeanWrapper bw = new BeanWrapperImpl(rod);
    bw.setPropertyValue("spouse", kerry);
    bw.setPropertyValue("spouse.age", new Integer(35));
    bw.setPropertyValue("spouse.name", "Kerry");
    bw.setPropertyValue("spouse.company", "Lewisham");
    assertTrue("kerry name is Kerry", kerry.getName().equals("Kerry"));

    assertTrue("nested set worked", rod.getSpouse() == kerry);
    assertTrue("no back relation", kerry.getSpouse() == null);
    bw.setPropertyValue(new PropertyValue("spouse.spouse", rod));
    assertTrue("nested set worked", kerry.getSpouse() == rod);

    BeanWrapper kbw = new BeanWrapperImpl(kerry);
    assertTrue(
        "spouse.spouse.spouse.spouse.company=Lewisham",
        "Lewisham".equals(kbw.getPropertyValue("spouse.spouse.spouse.spouse.company")));
  }