use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.
the class AbstractAopProxyTests method testCannotAddAdvisorWhenFrozenUsingCast.
/**
* Check that casting to Advised can't get around advice freeze.
*/
@Test
public void testCannotAddAdvisorWhenFrozenUsingCast() throws Throwable {
TestBean target = new TestBean();
target.setAge(21);
ProxyFactory pc = new ProxyFactory(target);
assertThat(pc.isFrozen()).isFalse();
pc.addAdvice(new NopInterceptor());
ITestBean proxied = (ITestBean) createProxy(pc);
pc.setFrozen(true);
Advised advised = (Advised) proxied;
assertThat(pc.isFrozen()).isTrue();
assertThatExceptionOfType(AopConfigException.class).as("Shouldn't be able to add Advisor when frozen").isThrownBy(() -> advised.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()))).withMessageContaining("frozen");
// Check it still works: proxy factory state shouldn't have been corrupted
assertThat(proxied.getAge()).isEqualTo(target.getAge());
assertThat(advised.getAdvisors().length).isEqualTo(1);
}
use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.
the class AspectJPrecedenceComparatorTests method createSpringAOPAfterAdvice.
private Advisor createSpringAOPAfterAdvice(int order) {
AfterReturningAdvice advice = (returnValue, method) -> {
};
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(this.anyOldPointcut, advice);
advisor.setOrder(order);
return advisor;
}
use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.
the class AspectJPrecedenceComparatorTests method createSpringAOPBeforeAdvice.
private Advisor createSpringAOPBeforeAdvice(int order) {
BeforeAdvice advice = new BeforeAdvice() {
};
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(this.anyOldPointcut, advice);
advisor.setOrder(order);
return advisor;
}
use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.
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();
}
use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.
the class TrickyAspectJPointcutExpressionTests method testManualProxyJavaWithStaticPointcutAndTwoClassLoaders.
@Test
public void testManualProxyJavaWithStaticPointcutAndTwoClassLoaders() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("execution(* %s.TestService.*(..))", getClass().getName()));
// Test with default class loader first...
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, new TestServiceImpl(), "TestServiceImpl");
// Then try again with a different class loader on the target...
SimpleThrowawayClassLoader loader = new SimpleThrowawayClassLoader(TestServiceImpl.class.getClassLoader());
// Make sure the interface is loaded from the parent class loader
loader.excludeClass(TestService.class.getName());
loader.excludeClass(TestException.class.getName());
TestService other = (TestService) loader.loadClass(TestServiceImpl.class.getName()).getDeclaredConstructor().newInstance();
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, other, "TestServiceImpl");
}
Aggregations