use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method setAnotherPropertyIntermediatePropertyIsNull.
@Test
public void setAnotherPropertyIntermediatePropertyIsNull() throws Exception {
ITestBean target = new TestBean("rod", 31);
AbstractPropertyAccessor accessor = createAccessor(target);
try {
accessor.setPropertyValue("spouse.age", new Integer(31));
fail("Shouldn't have succeeded with null path");
} catch (NullValueInNestedPathException ex) {
// expected
assertTrue("it was the spouse property that was null, not " + ex.getPropertyName(), ex.getPropertyName().equals("spouse"));
}
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method testErrorMessageOfNestedProperty.
@Test
public void testErrorMessageOfNestedProperty() {
ITestBean target = new TestBean();
ITestBean child = new DifferentTestBean();
child.setName("test");
target.setSpouse(child);
AbstractPropertyAccessor accessor = createAccessor(target);
try {
accessor.getPropertyValue("spouse.bla");
} catch (NotReadablePropertyException ex) {
assertTrue(ex.getMessage().contains(TestBean.class.getName()));
}
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method getAnotherNestedDeepProperty.
@Test
public void getAnotherNestedDeepProperty() {
ITestBean target = new TestBean("rod", 31);
ITestBean kerry = new TestBean("kerry", 35);
target.setSpouse(kerry);
kerry.setSpouse(target);
AbstractPropertyAccessor accessor = createAccessor(target);
Integer KA = (Integer) accessor.getPropertyValue("spouse.age");
assertTrue("kerry is 35", KA == 35);
Integer RA = (Integer) accessor.getPropertyValue("spouse.spouse.age");
assertTrue("rod is 31, not" + RA, RA == 31);
ITestBean spousesSpouse = (ITestBean) accessor.getPropertyValue("spouse.spouse");
assertTrue("spousesSpouse = initial point", target == spousesSpouse);
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class SimplePropertyNamespaceHandlerTests method innerBeanConfigured.
@Test
public void innerBeanConfigured() throws Exception {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
TestBean sally = (TestBean) beanFactory.getBean("sally2");
ITestBean rob = sally.getSpouse();
assertEquals("Rob Harrop", rob.getName());
assertEquals(24, rob.getAge());
assertEquals(rob.getSpouse(), sally);
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class SimplePropertyNamespaceHandlerTests method simpleBeanConfigured.
@Test
public void simpleBeanConfigured() throws Exception {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
ITestBean rob = (TestBean) beanFactory.getBean("rob");
ITestBean sally = (TestBean) beanFactory.getBean("sally");
assertEquals("Rob Harrop", rob.getName());
assertEquals(24, rob.getAge());
assertEquals(rob.getSpouse(), sally);
}
Aggregations