use of org.springframework.aop.Pointcut in project spring-framework by spring-projects.
the class PointcutsTests method testUnionOfSpecificGetters.
@Test
public void testUnionOfSpecificGetters() {
Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut);
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
// Union with all setters
union = Pointcuts.union(union, allClassSetterPointcut);
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
}
use of org.springframework.aop.Pointcut in project spring-framework by spring-projects.
the class PointcutsTests method testUnionOfAllSettersAndSubclassSetters.
/**
* Tests vertical composition. First pointcut matches all setters.
* Second one matches all getters in the MyTestBean class. TestBean getters shouldn't pass.
*/
@Test
public void testUnionOfAllSettersAndSubclassSetters() {
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6)));
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
Pointcut union = Pointcuts.union(myTestBeanSetterPointcut, allClassGetterPointcut);
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class));
// Still doesn't match superclass setter
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6)));
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
}
use of org.springframework.aop.Pointcut in project spring-framework by spring-projects.
the class AopUtilsTests method testPointcutAppliesToOneMethodOnObject.
@Test
public void testPointcutAppliesToOneMethodOnObject() {
class TestPointcut extends StaticMethodMatcherPointcut {
@Override
public boolean matches(Method method, Class<?> clazz) {
return method.getName().equals("hashCode");
}
}
Pointcut pc = new TestPointcut();
// will return true if we're not proxying interfaces
assertTrue(AopUtils.canApply(pc, Object.class));
}
use of org.springframework.aop.Pointcut in project spring-framework by spring-projects.
the class AbstractAspectJAdvice method buildSafePointcut.
/**
* Build a 'safe' pointcut that excludes the AspectJ advice method itself.
* @return a composable pointcut that builds on the original AspectJ expression pointcut
* @see #getPointcut()
*/
public final Pointcut buildSafePointcut() {
Pointcut pc = getPointcut();
MethodMatcher safeMethodMatcher = MethodMatchers.intersection(new AdviceExcludingMethodMatcher(this.aspectJAdviceMethod), pc.getMethodMatcher());
return new ComposablePointcut(pc.getClassFilter(), safeMethodMatcher);
}
use of org.springframework.aop.Pointcut in project spring-framework by spring-projects.
the class CallCountingInterceptor method getAdvisedProxy.
private TestBean getAdvisedProxy(String pointcutExpression, CallCountingInterceptor interceptor) {
TestBean target = new TestBean();
Pointcut pointcut = getPointcut(pointcutExpression);
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
advisor.setAdvice(interceptor);
advisor.setPointcut(pointcut);
ProxyFactory pf = new ProxyFactory();
pf.setTarget(target);
pf.addAdvisor(advisor);
return (TestBean) pf.getProxy();
}
Aggregations