TransactionAttributeSourcePointcut pointcut skips target classes with TransactionalProxy marker (e.g. Spring Data proxies)
This 4.2 commit also makes TransactionProxyFactoryBean expose the TransactionalProxy marker and refines SpringProxy marker handling. Issue: SPR-13109
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,9 +20,10 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.support.StaticMethodMatcherPointcut;
|
||||
@@ -40,44 +41,56 @@ import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
|
||||
/**
|
||||
* Test cases for AOP transaction management.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @since 23.04.2003
|
||||
*/
|
||||
public class BeanFactoryTransactionTests extends TestCase {
|
||||
public class BeanFactoryTransactionTests {
|
||||
|
||||
private DefaultListableBeanFactory factory;
|
||||
|
||||
@Override
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.factory = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(
|
||||
new ClassPathResource("transactionalBeanFactory.xml", getClass()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetsAreNotTransactionalWithProxyFactory1() throws NoSuchMethodException {
|
||||
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory1");
|
||||
assertTrue("testBean is a dynamic proxy", Proxy.isProxyClass(testBean.getClass()));
|
||||
assertFalse(testBean instanceof TransactionalProxy);
|
||||
doTestGetsAreNotTransactional(testBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetsAreNotTransactionalWithProxyFactory2DynamicProxy() throws NoSuchMethodException {
|
||||
this.factory.preInstantiateSingletons();
|
||||
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2DynamicProxy");
|
||||
assertTrue("testBean is a dynamic proxy", Proxy.isProxyClass(testBean.getClass()));
|
||||
assertTrue(testBean instanceof TransactionalProxy);
|
||||
doTestGetsAreNotTransactional(testBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetsAreNotTransactionalWithProxyFactory2Cglib() throws NoSuchMethodException {
|
||||
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Cglib");
|
||||
assertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(testBean));
|
||||
assertTrue(testBean instanceof TransactionalProxy);
|
||||
doTestGetsAreNotTransactional(testBean);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProxyFactory2Lazy() throws NoSuchMethodException {
|
||||
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory2Lazy");
|
||||
assertFalse(factory.containsSingleton("target"));
|
||||
@@ -85,9 +98,11 @@ public class BeanFactoryTransactionTests extends TestCase {
|
||||
assertTrue(factory.containsSingleton("target"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCglibTransactionProxyImplementsNoInterfaces() throws NoSuchMethodException {
|
||||
ImplementsNoInterfaces ini = (ImplementsNoInterfaces) factory.getBean("cglibNoInterfaces");
|
||||
assertTrue("testBean is CGLIB advised", AopUtils.isCglibProxy(ini));
|
||||
assertTrue(ini instanceof TransactionalProxy);
|
||||
String newName = "Gordon";
|
||||
|
||||
// Install facade
|
||||
@@ -99,9 +114,11 @@ public class BeanFactoryTransactionTests extends TestCase {
|
||||
assertEquals(2, ptm.commits);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetsAreNotTransactionalWithProxyFactory3() throws NoSuchMethodException {
|
||||
ITestBean testBean = (ITestBean) factory.getBean("proxyFactory3");
|
||||
assertTrue("testBean is a full proxy", testBean instanceof DerivedTestBean);
|
||||
assertTrue(testBean instanceof TransactionalProxy);
|
||||
InvocationCounterPointcut txnCounter = (InvocationCounterPointcut) factory.getBean("txnInvocationCounterPointcut");
|
||||
InvocationCounterInterceptor preCounter = (InvocationCounterInterceptor) factory.getBean("preInvocationCounterInterceptor");
|
||||
InvocationCounterInterceptor postCounter = (InvocationCounterInterceptor) factory.getBean("postInvocationCounterInterceptor");
|
||||
@@ -158,6 +175,7 @@ public class BeanFactoryTransactionTests extends TestCase {
|
||||
assertTrue(testBean.getAge() == age);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBeansOfTypeWithAbstract() {
|
||||
Map<String, ITestBean> beansOfType = factory.getBeansOfType(ITestBean.class, true, true);
|
||||
assertNotNull(beansOfType);
|
||||
@@ -166,6 +184,7 @@ public class BeanFactoryTransactionTests extends TestCase {
|
||||
/**
|
||||
* Check that we fail gracefully if the user doesn't set any transaction attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testNoTransactionAttributeSource() {
|
||||
try {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
@@ -181,6 +200,7 @@ public class BeanFactoryTransactionTests extends TestCase {
|
||||
/**
|
||||
* Test that we can set the target to a dynamic TargetSource.
|
||||
*/
|
||||
@Test
|
||||
public void testDynamicTargetSource() throws NoSuchMethodException {
|
||||
// Install facade
|
||||
CallCountingTransactionManager txMan = new CallCountingTransactionManager();
|
||||
|
||||
Reference in New Issue
Block a user