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");
}
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;
}
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();
}
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);
}
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);
}
Aggregations