Search in sources :

Example 61 with ITestBean

use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.

the class AbstractPropertyAccessorTests method setPropertyValuesIgnoresInvalidNestedOnRequest.

@Test
void setPropertyValuesIgnoresInvalidNestedOnRequest() {
    ITestBean target = 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()));
    AbstractPropertyAccessor accessor = createAccessor(target);
    accessor.setPropertyValues(pvs, true);
    assertThat(target.getName().equals("rod")).as("Set valid and ignored invalid").isTrue();
    assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() -> accessor.setPropertyValues(pvs, false));
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) BooleanTestBean(org.springframework.beans.testfixture.beans.BooleanTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) NumberTestBean(org.springframework.beans.testfixture.beans.NumberTestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) Test(org.junit.jupiter.api.Test)

Example 62 with ITestBean

use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.

the class AbstractPropertyAccessorTests method setAnotherPropertyIntermediatePropertyIsNull.

@Test
void setAnotherPropertyIntermediatePropertyIsNull() throws Exception {
    ITestBean target = new TestBean("rod", 31);
    AbstractPropertyAccessor accessor = createAccessor(target);
    assertThatExceptionOfType(NullValueInNestedPathException.class).isThrownBy(() -> accessor.setPropertyValue("spouse.age", 31)).satisfies(ex -> assertThat(ex.getPropertyName()).isEqualTo("spouse"));
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) BooleanTestBean(org.springframework.beans.testfixture.beans.BooleanTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) NumberTestBean(org.springframework.beans.testfixture.beans.NumberTestBean) IndexedTestBean(org.springframework.beans.testfixture.beans.IndexedTestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) Test(org.junit.jupiter.api.Test)

Example 63 with ITestBean

use of org.springframework.beans.testfixture.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();
    assertThat(rob.getName()).isEqualTo("Rob Harrop");
    assertThat(rob.getAge()).isEqualTo(24);
    assertThat(sally).isEqualTo(rob.getSpouse());
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 64 with ITestBean

use of org.springframework.beans.testfixture.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");
    assertThat(rob.getName()).isEqualTo("Rob Harrop");
    assertThat(rob.getAge()).isEqualTo(24);
    assertThat(sally).isEqualTo(rob.getSpouse());
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 65 with ITestBean

use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.

the class CounterAspect method testProgrammaticProxyCreation.

@Test
public void testProgrammaticProxyCreation() {
    ITestBean testBean = new TestBean();
    AspectJProxyFactory factory = new AspectJProxyFactory();
    factory.setTarget(testBean);
    CounterAspect myCounterAspect = new CounterAspect();
    factory.addAspect(myCounterAspect);
    ITestBean proxyTestBean = factory.getProxy();
    boolean condition = proxyTestBean instanceof Advised;
    assertThat(condition).as("Expected a proxy").isTrue();
    proxyTestBean.setAge(20);
    assertThat(myCounterAspect.count).as("Programmatically created proxy shouldn't match bean()").isEqualTo(0);
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) AspectJProxyFactory(org.springframework.aop.aspectj.annotation.AspectJProxyFactory) Advised(org.springframework.aop.framework.Advised) Test(org.junit.jupiter.api.Test)

Aggregations

ITestBean (org.springframework.beans.testfixture.beans.ITestBean)210 Test (org.junit.jupiter.api.Test)199 TestBean (org.springframework.beans.testfixture.beans.TestBean)121 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)44 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)31 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)29 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)23 Advisor (org.springframework.aop.Advisor)22 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)21 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)20 CountingBeforeAdvice (org.springframework.aop.testfixture.advice.CountingBeforeAdvice)19 Method (java.lang.reflect.Method)16 TimeStamped (org.springframework.core.testfixture.TimeStamped)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 TimestampIntroductionInterceptor (org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor)15 IOException (java.io.IOException)14 ProxyFactory (org.springframework.aop.framework.ProxyFactory)14 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)14 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)13 Advised (org.springframework.aop.framework.Advised)13