Search in sources :

Example 61 with ProxyFactory

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);
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 62 with ProxyFactory

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);
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 63 with ProxyFactory

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);
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 64 with ProxyFactory

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();
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Advised(org.springframework.aop.framework.Advised) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) Test(org.junit.Test)

Example 65 with ProxyFactory

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);
}
Also used : TimeStamped(org.springframework.tests.TimeStamped) INestedTestBean(org.springframework.tests.sample.beans.INestedTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Aggregations

ProxyFactory (org.springframework.aop.framework.ProxyFactory)81 Test (org.junit.Test)49 ITestBean (org.springframework.tests.sample.beans.ITestBean)20 TestBean (org.springframework.tests.sample.beans.TestBean)20 TimeStamped (org.springframework.tests.TimeStamped)8 INestedTestBean (org.springframework.tests.sample.beans.INestedTestBean)8 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)8 Method (java.lang.reflect.Method)6 HashMap (java.util.HashMap)5 MethodBeforeAdvice (org.springframework.aop.MethodBeforeAdvice)4 Context (javax.naming.Context)3 TargetSource (org.springframework.aop.TargetSource)3 Advised (org.springframework.aop.framework.Advised)3 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)3 Factory (org.springframework.cglib.proxy.Factory)3 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)3 IOException (java.io.IOException)2 EJBLocalObject (javax.ejb.EJBLocalObject)2 Message (javax.jms.Message)2 TextMessage (javax.jms.TextMessage)2