Search in sources :

Example 11 with ProxyFactory

use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.

the class ReactiveTransactionInterceptorTests method advised.

@Override
protected Object advised(Object target, ReactiveTransactionManager ptm, TransactionAttributeSource[] tas) {
    TransactionInterceptor ti = new TransactionInterceptor();
    ti.setTransactionManager(ptm);
    ti.setTransactionAttributeSources(tas);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(0, ti);
    return pf.getProxy();
}
Also used : ProxyFactory(cn.taketoday.aop.framework.ProxyFactory)

Example 12 with ProxyFactory

use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.

the class AnnotationTransactionInterceptorTests method withMultiMethodOverride.

@Test
public void withMultiMethodOverride() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestWithMultiMethodOverride());
    proxyFactory.addAdvice(this.ti);
    TestWithMultiMethodOverride proxy = (TestWithMultiMethodOverride) proxyFactory.getProxy();
    proxy.doSomething();
    assertGetTransactionAndCommitCount(1);
    proxy.doSomethingElse();
    assertGetTransactionAndCommitCount(2);
    proxy.doSomethingCompletelyElse();
    assertGetTransactionAndCommitCount(3);
    proxy.doSomething();
    assertGetTransactionAndCommitCount(4);
}
Also used : ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) Test(org.junit.jupiter.api.Test)

Example 13 with ProxyFactory

use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.

the class AnnotationTransactionInterceptorTests method withSingleMethodOverride.

@Test
public void withSingleMethodOverride() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestWithSingleMethodOverride());
    proxyFactory.addAdvice(this.ti);
    TestWithSingleMethodOverride proxy = (TestWithSingleMethodOverride) proxyFactory.getProxy();
    proxy.doSomething();
    assertGetTransactionAndCommitCount(1);
    proxy.doSomethingElse();
    assertGetTransactionAndCommitCount(2);
    proxy.doSomethingCompletelyElse();
    assertGetTransactionAndCommitCount(3);
    proxy.doSomething();
    assertGetTransactionAndCommitCount(4);
}
Also used : ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) Test(org.junit.jupiter.api.Test)

Example 14 with ProxyFactory

use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.

the class AnnotationTransactionInterceptorTests method classLevelOnly.

@Test
public void classLevelOnly() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestClassLevelOnly());
    proxyFactory.addAdvice(this.ti);
    TestClassLevelOnly proxy = (TestClassLevelOnly) proxyFactory.getProxy();
    proxy.doSomething();
    assertGetTransactionAndCommitCount(1);
    proxy.doSomethingElse();
    assertGetTransactionAndCommitCount(2);
    proxy.doSomething();
    assertGetTransactionAndCommitCount(3);
    proxy.doSomethingElse();
    assertGetTransactionAndCommitCount(4);
}
Also used : ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) Test(org.junit.jupiter.api.Test)

Example 15 with ProxyFactory

use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.

the class AnnotationTransactionInterceptorTests method withCommitOnCheckedException.

@Test
public void withCommitOnCheckedException() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestWithExceptions());
    proxyFactory.addAdvice(this.ti);
    TestWithExceptions proxy = (TestWithExceptions) proxyFactory.getProxy();
    assertThatExceptionOfType(Exception.class).isThrownBy(proxy::doSomethingElseWithCheckedException).satisfies(ex -> assertGetTransactionAndCommitCount(1));
}
Also used : ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)206 Test (org.junit.jupiter.api.Test)171 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)91 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)86 NopInterceptor (cn.taketoday.aop.NopInterceptor)39 SerializableNopInterceptor (cn.taketoday.aop.SerializableNopInterceptor)29 DefaultPointcutAdvisor (cn.taketoday.aop.support.DefaultPointcutAdvisor)21 Advised (cn.taketoday.aop.framework.Advised)19 DefaultIntroductionAdvisor (cn.taketoday.aop.support.DefaultIntroductionAdvisor)17 INestedTestBean (cn.taketoday.beans.testfixture.beans.INestedTestBean)16 NestedTestBean (cn.taketoday.beans.testfixture.beans.NestedTestBean)16 TimeStamped (cn.taketoday.core.testfixture.TimeStamped)16 IOException (java.io.IOException)16 TransactionInterceptor (cn.taketoday.transaction.interceptor.TransactionInterceptor)14 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)13 Method (java.lang.reflect.Method)12 Advisor (cn.taketoday.aop.Advisor)10 MethodBeforeAdvice (cn.taketoday.aop.MethodBeforeAdvice)10 AopUtils (cn.taketoday.aop.support.AopUtils)10 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)10