use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class ControlFlowPointcutTests method testMatches.
@Test
public void testMatches() {
TestBean target = new TestBean();
target.setAge(27);
NopInterceptor nop = new NopInterceptor();
ControlFlowPointcut cflow = new ControlFlowPointcut(One.class, "getAge");
ProxyFactory pf = new ProxyFactory(target);
ITestBean proxied = (ITestBean) pf.getProxy();
pf.addAdvisor(new DefaultPointcutAdvisor(cflow, nop));
// Not advised, not under One
assertThat(proxied.getAge()).isEqualTo(target.getAge());
assertThat(nop.getCount()).isEqualTo(0);
// Will be advised
assertThat(new One().getAge(proxied)).isEqualTo(target.getAge());
assertThat(nop.getCount()).isEqualTo(1);
// Won't be advised
assertThat(new One().nomatch(proxied)).isEqualTo(target.getAge());
assertThat(nop.getCount()).isEqualTo(1);
assertThat(cflow.getEvaluations()).isEqualTo(3);
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class ControlFlowPointcutTests method testSelectiveApplication.
/**
* Check that we can use a cflow pointcut only in conjunction with
* a static pointcut: e.g. all setter methods that are invoked under
* a particular class. This greatly reduces the number of calls
* to the cflow pointcut, meaning that it's not so prohibitively
* expensive.
*/
@Test
public void testSelectiveApplication() {
TestBean target = new TestBean();
target.setAge(27);
NopInterceptor nop = new NopInterceptor();
ControlFlowPointcut cflow = new ControlFlowPointcut(One.class);
Pointcut settersUnderOne = Pointcuts.intersection(Pointcuts.SETTERS, cflow);
ProxyFactory pf = new ProxyFactory(target);
ITestBean proxied = (ITestBean) pf.getProxy();
pf.addAdvisor(new DefaultPointcutAdvisor(settersUnderOne, nop));
// Not advised, not under One
target.setAge(16);
assertThat(nop.getCount()).isEqualTo(0);
// Not advised; under One but not a setter
assertThat(new One().getAge(proxied)).isEqualTo(16);
assertThat(nop.getCount()).isEqualTo(0);
// Won't be advised
new One().set(proxied);
assertThat(nop.getCount()).isEqualTo(1);
// We saved most evaluations
assertThat(cflow.getEvaluations()).isEqualTo(1);
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class RegexpMethodPointcutAdvisorIntegrationTests method testSinglePattern.
@Test
public void testSinglePattern() throws Throwable {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
// Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
assertThat(nop.getCount()).isEqualTo(0);
int newAge = 12;
// Not advised
advised.exceptional(null);
assertThat(nop.getCount()).isEqualTo(0);
advised.setAge(newAge);
assertThat(advised.getAge()).isEqualTo(newAge);
// Only setter fired
assertThat(nop.getCount()).isEqualTo(1);
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method testErrorMessageOfNestedProperty.
@Test
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) {
assertThat(ex.getMessage().contains(TestBean.class.getName())).isTrue();
}
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method getAnotherNestedDeepProperty.
@Test
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");
assertThat(KA == 35).as("kerry is 35").isTrue();
Integer RA = (Integer) accessor.getPropertyValue("spouse.spouse.age");
assertThat(RA == 31).as("rod is 31, not" + RA).isTrue();
ITestBean spousesSpouse = (ITestBean) accessor.getPropertyValue("spouse.spouse");
assertThat(target == spousesSpouse).as("spousesSpouse = initial point").isTrue();
}
Aggregations