Search in sources :

Example 26 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class JmsListenerContainerFactoryIntegrationTests method parameterAnnotationWithCglibProxy.

@Test
public void parameterAnnotationWithCglibProxy() throws JMSException {
    ProxyFactory pf = new ProxyFactory(sample);
    pf.setProxyTargetClass(true);
    listener = (JmsEndpointSampleBean) pf.getProxy();
    containerFactory.setMessageConverter(new UpperCaseMessageConverter());
    MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(JmsEndpointSampleBean.class, "handleIt", String.class, String.class);
    Message message = new StubTextMessage("foo-bar");
    message.setStringProperty("my-header", "my-value");
    invokeListener(endpoint, message);
    assertListenerMethodInvocation("handleIt");
}
Also used : TextMessage(javax.jms.TextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) Message(javax.jms.Message) ProxyFactory(org.springframework.aop.framework.ProxyFactory) StubTextMessage(org.springframework.jms.StubTextMessage) Test(org.junit.Test)

Example 27 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class AopTestUtilsTests method jdkProxy.

private Foo jdkProxy(Foo foo) {
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(foo);
    pf.addInterface(Foo.class);
    Foo proxy = (Foo) pf.getProxy();
    assertTrue("Proxy is a JDK dynamic proxy", AopUtils.isJdkDynamicProxy(proxy));
    assertThat(proxy, instanceOf(Foo.class));
    return proxy;
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory)

Example 28 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class TransactionInterceptorTests method advised.

/**
	 * Template method to create an advised object given the
	 * target object and transaction setup.
	 * Creates a TransactionInterceptor and applies it.
	 */
@Override
protected Object advised(Object target, PlatformTransactionManager ptm, TransactionAttributeSource tas) {
    TransactionInterceptor ti = new TransactionInterceptor();
    ti.setTransactionManager(ptm);
    assertEquals(ptm, ti.getTransactionManager());
    ti.setTransactionAttributeSource(tas);
    assertEquals(tas, ti.getTransactionAttributeSource());
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(0, ti);
    return pf.getProxy();
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory)

Example 29 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class AnnotationTransactionAttributeSourceTests method serializable.

@Test
public void serializable() throws Exception {
    TestBean1 tb = new TestBean1();
    CallCountingTransactionManager ptm = new CallCountingTransactionManager();
    AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
    TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(ITestBean.class);
    proxyFactory.addAdvice(ti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();
    assertEquals(1, ptm.commits);
    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    serializedProxy.getAge();
    Advised advised = (Advised) serializedProxy;
    TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
    CallCountingTransactionManager serializedPtm = (CallCountingTransactionManager) serializedTi.getTransactionManager();
    assertEquals(2, serializedPtm.commits);
}
Also used : TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Advised(org.springframework.aop.framework.Advised) CallCountingTransactionManager(org.springframework.tests.transaction.CallCountingTransactionManager) Test(org.junit.Test)

Example 30 with ProxyFactory

use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.

the class AnnotationTransactionInterceptorTests method crossClassInterfaceMethodLevelOnJdkProxy.

@Test
public void crossClassInterfaceMethodLevelOnJdkProxy() throws Exception {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new SomeServiceImpl());
    proxyFactory.addInterface(SomeService.class);
    proxyFactory.addAdvice(this.ti);
    SomeService someService = (SomeService) proxyFactory.getProxy();
    someService.bar();
    assertGetTransactionAndCommitCount(1);
    someService.foo();
    assertGetTransactionAndCommitCount(2);
    someService.fooBar();
    assertGetTransactionAndCommitCount(3);
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Aggregations

ProxyFactory (org.springframework.aop.framework.ProxyFactory)78 Test (org.junit.Test)48 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 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)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 IOException (java.io.IOException)2 EJBLocalObject (javax.ejb.EJBLocalObject)2 Message (javax.jms.Message)2 TextMessage (javax.jms.TextMessage)2 ObjectName (javax.management.ObjectName)2