use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class ReflectionTestUtilsTests method setFieldAndGetFieldViaJdkDynamicProxy.
@Test
public void setFieldAndGetFieldViaJdkDynamicProxy() throws Exception {
ProxyFactory pf = new ProxyFactory(this.person);
pf.addInterface(Person.class);
Person proxy = (Person) pf.getProxy();
assertTrue("Proxy is a JDK dynamic proxy", AopUtils.isJdkDynamicProxy(proxy));
assertSetFieldAndGetFieldBehaviorForProxy(proxy, this.person);
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class TransactionInterceptorTests method advised.
@Override
protected Object advised(Object target, PlatformTransactionManager ptm, TransactionAttributeSource[] tas) throws Exception {
TransactionInterceptor ti = new TransactionInterceptor();
ti.setTransactionManager(ptm);
ti.setTransactionAttributeSources(tas);
ProxyFactory pf = new ProxyFactory(target);
pf.addAdvice(0, ti);
return pf.getProxy();
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class AnnotationTransactionAttributeSourceTests method transactionAttributeDeclaredOnCglibClassMethod.
/**
* Test the important case where the invocation is on a proxied interface method
* but the attribute is defined on the target class.
*/
@Test
public void transactionAttributeDeclaredOnCglibClassMethod() throws Exception {
Method classMethod = ITestBean.class.getMethod("getAge");
TestBean1 tb = new TestBean1();
ProxyFactory pf = new ProxyFactory(tb);
pf.setProxyTargetClass(true);
Object proxy = pf.getProxy();
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
TransactionAttribute actual = atas.getTransactionAttribute(classMethod, proxy.getClass());
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class AnnotationTransactionInterceptorTests method withSingleMethodOverrideInverted.
@Test
public void withSingleMethodOverrideInverted() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithSingleMethodOverrideInverted());
proxyFactory.addAdvice(this.ti);
TestWithSingleMethodOverrideInverted proxy = (TestWithSingleMethodOverrideInverted) proxyFactory.getProxy();
proxy.doSomething();
assertGetTransactionAndCommitCount(1);
proxy.doSomethingElse();
assertGetTransactionAndCommitCount(2);
proxy.doSomethingCompletelyElse();
assertGetTransactionAndCommitCount(3);
proxy.doSomething();
assertGetTransactionAndCommitCount(4);
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class AnnotationTransactionInterceptorTests method withInterface.
@Test
public void withInterface() {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new TestWithInterfaceImpl());
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);
}
Aggregations