|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2010 the original author or authors. |
|
|
|
|
* Copyright 2002-2011 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. |
|
|
|
|
@ -23,6 +23,8 @@ import org.aopalliance.intercept.MethodInterceptor;
@@ -23,6 +23,8 @@ import org.aopalliance.intercept.MethodInterceptor;
|
|
|
|
|
import org.aopalliance.intercept.MethodInvocation; |
|
|
|
|
|
|
|
|
|
import org.springframework.aop.support.AopUtils; |
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
|
|
|
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
|
|
|
|
import org.springframework.transaction.CallCountingTransactionManager; |
|
|
|
|
import org.springframework.transaction.support.TransactionSynchronizationManager; |
|
|
|
|
@ -36,26 +38,18 @@ public class AnnotationDrivenTests extends TestCase {
@@ -36,26 +38,18 @@ public class AnnotationDrivenTests extends TestCase {
|
|
|
|
|
|
|
|
|
|
public void testWithProxyTargetClass() throws Exception { |
|
|
|
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass()); |
|
|
|
|
CallCountingTransactionManager tm1 = context.getBean("transactionManager1", CallCountingTransactionManager.class); |
|
|
|
|
CallCountingTransactionManager tm2 = context.getBean("transactionManager2", CallCountingTransactionManager.class); |
|
|
|
|
TransactionalService service = context.getBean("service", TransactionalService.class); |
|
|
|
|
assertTrue(AopUtils.isCglibProxy(service)); |
|
|
|
|
service.setSomething("someName"); |
|
|
|
|
assertEquals(1, tm1.commits); |
|
|
|
|
assertEquals(0, tm2.commits); |
|
|
|
|
service.doSomething(); |
|
|
|
|
assertEquals(1, tm1.commits); |
|
|
|
|
assertEquals(1, tm2.commits); |
|
|
|
|
service.setSomething("someName"); |
|
|
|
|
assertEquals(2, tm1.commits); |
|
|
|
|
assertEquals(1, tm2.commits); |
|
|
|
|
service.doSomething(); |
|
|
|
|
assertEquals(2, tm1.commits); |
|
|
|
|
assertEquals(2, tm2.commits); |
|
|
|
|
doTestWithMultipleTransactionManagers(context); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void testWithConfigurationClass() throws Exception { |
|
|
|
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenConfigurationClassTests.xml", getClass()); |
|
|
|
|
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(); |
|
|
|
|
parent.register(TransactionManagerConfiguration.class); |
|
|
|
|
parent.refresh(); |
|
|
|
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"annotationDrivenConfigurationClassTests.xml"}, getClass(), parent); |
|
|
|
|
doTestWithMultipleTransactionManagers(context); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doTestWithMultipleTransactionManagers(ApplicationContext context) { |
|
|
|
|
CallCountingTransactionManager tm1 = context.getBean("transactionManager1", CallCountingTransactionManager.class); |
|
|
|
|
CallCountingTransactionManager tm2 = context.getBean("transactionManager2", CallCountingTransactionManager.class); |
|
|
|
|
TransactionalService service = context.getBean("service", TransactionalService.class); |
|
|
|
|
|