Search in sources :

Example 56 with ProxyFactory

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

Example 57 with ProxyFactory

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

Example 58 with ProxyFactory

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());
}
Also used : TransactionAttribute(org.springframework.transaction.interceptor.TransactionAttribute) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) RollbackRuleAttribute(org.springframework.transaction.interceptor.RollbackRuleAttribute) NoRollbackRuleAttribute(org.springframework.transaction.interceptor.NoRollbackRuleAttribute) ProxyFactory(org.springframework.aop.framework.ProxyFactory) RuleBasedTransactionAttribute(org.springframework.transaction.interceptor.RuleBasedTransactionAttribute) GroovyObject(groovy.lang.GroovyObject) Method(java.lang.reflect.Method) IOException(java.io.IOException) Test(org.junit.Test)

Example 59 with ProxyFactory

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

Example 60 with ProxyFactory

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);
}
Also used : 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