Search in sources :

Example 11 with ITestBean

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"));
    }
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) BigInteger(java.math.BigInteger) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) BooleanTestBean(org.springframework.tests.sample.beans.BooleanTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NumberTestBean(org.springframework.tests.sample.beans.NumberTestBean) Test(org.junit.Test)

Example 12 with ITestBean

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()));
    }
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) BooleanTestBean(org.springframework.tests.sample.beans.BooleanTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NumberTestBean(org.springframework.tests.sample.beans.NumberTestBean) Test(org.junit.Test)

Example 13 with ITestBean

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);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) BigInteger(java.math.BigInteger) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) BooleanTestBean(org.springframework.tests.sample.beans.BooleanTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NumberTestBean(org.springframework.tests.sample.beans.NumberTestBean) Test(org.junit.Test)

Example 14 with ITestBean

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);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 15 with ITestBean

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);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

ITestBean (org.springframework.tests.sample.beans.ITestBean)221 Test (org.junit.Test)205 TestBean (org.springframework.tests.sample.beans.TestBean)127 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)37 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 SerializableNopInterceptor (org.springframework.tests.aop.interceptor.SerializableNopInterceptor)24 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)21 IOException (java.io.IOException)15 Advisor (org.springframework.aop.Advisor)15 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)15 Method (java.lang.reflect.Method)14 ProxyFactory (org.springframework.aop.framework.ProxyFactory)14 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)14 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)13 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)13 MethodInvocation (org.aopalliance.intercept.MethodInvocation)12 Advised (org.springframework.aop.framework.Advised)12 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)11 LockedException (test.mixin.LockedException)11 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)10