use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
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);
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
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);
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class AnnotationTransactionInterceptorTests method crossClassInterfaceOnJdkProxy.
@Test
public void crossClassInterfaceOnJdkProxy() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTarget(new OtherServiceImpl());
proxyFactory.addInterface(OtherService.class);
proxyFactory.addAdvice(this.ti);
OtherService otherService = (OtherService) proxyFactory.getProxy();
otherService.foo();
assertGetTransactionAndCommitCount(1);
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class ConcurrencyThrottleInterceptorTests method testSerializable.
@Test
public void testSerializable() throws Exception {
DerivedTestBean tb = new DerivedTestBean();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(new Class[] { ITestBean.class });
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
proxyFactory.addAdvice(cti);
proxyFactory.setTarget(tb);
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
proxy.getAge();
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
Advised advised = (Advised) serializedProxy;
ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
serializedProxy.getAge();
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class DelegatingIntroductionInterceptorTests method testIntroductionInterceptorWithDelegation.
@Test
public void testIntroductionInterceptorWithDelegation() throws Exception {
TestBean raw = new TestBean();
assertTrue(!(raw instanceof TimeStamped));
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock(TimeStamped.class);
long timestamp = 111L;
given(ts.getTimeStamp()).willReturn(timestamp);
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
TimeStamped tsp = (TimeStamped) factory.getProxy();
assertTrue(tsp.getTimeStamp() == timestamp);
}
Aggregations