use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.
the class AnnotationTransactionInterceptorTests method withInterfaceOnTargetCglibProxy.
@Test
public void withInterfaceOnTargetCglibProxy() {
ProxyFactory targetFactory = new ProxyFactory();
targetFactory.setTarget(new TestWithInterfaceImpl());
targetFactory.setProxyTargetClass(true);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(targetFactory.getProxy());
proxyFactory.addInterface(TestWithInterface.class);
proxyFactory.addAdvice(this.ti);
TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();
proxy.doSomething();
assertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
assertGetTransactionAndCommitCount(2);
proxy.doSomethingElse();
assertGetTransactionAndCommitCount(3);
proxy.doSomething();
assertGetTransactionAndCommitCount(4);
proxy.doSomethingDefault();
assertGetTransactionAndCommitCount(5);
}
use of cn.taketoday.aop.framework.ProxyFactory 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.framework.ProxyFactory in project today-infrastructure by TAKETODAY.
the class MethodInvocationProceedingJoinPointTests method toShortAndLongStringFormedCorrectly.
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
pf.addAdvice((MethodBeforeAdvice) (method) -> {
StaticPart aspectJVersionJp = Factory.makeEncSJP(method.getMethod());
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
assertThat(jp.getSignature().toLongString()).isEqualTo(aspectJVersionJp.getSignature().toLongString());
assertThat(jp.getSignature().toShortString()).isEqualTo(aspectJVersionJp.getSignature().toShortString());
assertThat(jp.getSignature().toString()).isEqualTo(aspectJVersionJp.getSignature().toString());
assertThat(jp.toLongString()).isEqualTo(aspectJVersionJp.toLongString());
assertThat(jp.toShortString()).isEqualTo(aspectJVersionJp.toShortString());
assertThat(jp.toString()).isEqualTo(aspectJVersionJp.toString());
});
ITestBean itb = (ITestBean) pf.getProxy();
itb.getAge();
itb.setName("foo");
itb.getDoctor();
itb.getStringArray();
itb.getSpouse();
itb.setSpouse(new TestBean());
try {
itb.unreliableFileOperation();
} catch (IOException ex) {
// we don't really care...
}
}
use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.
the class MethodInvocationProceedingJoinPointTests method testCanGetStaticPartFromJoinPoint.
@Test
public void testCanGetStaticPartFromJoinPoint() {
final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
pf.addAdvice((MethodBeforeAdvice) (method) -> {
StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
assertThat(AbstractAspectJAdvice.currentJoinPoint().getStaticPart()).as("Same static part must be returned on subsequent requests").isEqualTo(staticPart);
assertThat(staticPart.getKind()).isEqualTo(ProceedingJoinPoint.METHOD_EXECUTION);
assertThat(staticPart.getSignature()).isSameAs(AbstractAspectJAdvice.currentJoinPoint().getSignature());
assertThat(staticPart.getSourceLocation()).isEqualTo(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation());
});
ITestBean itb = (ITestBean) pf.getProxy();
// Any call will do
itb.getAge();
}
use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.
the class MethodInvocationProceedingJoinPointTests method testCanGetSourceLocationFromJoinPoint.
@Test
public void testCanGetSourceLocationFromJoinPoint() {
final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
pf.addAdvice((MethodBeforeAdvice) (method) -> {
SourceLocation sloc = AbstractAspectJAdvice.currentJoinPoint().getSourceLocation();
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation()).as("Same source location must be returned on subsequent requests").isEqualTo(sloc);
assertThat(sloc.getWithinType()).isEqualTo(TestBean.class);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getLine);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getFileName);
});
ITestBean itb = (ITestBean) pf.getProxy();
// Any call will do
itb.getAge();
}
Aggregations