Tests for annotation lookups in interfaces (currently ignored for CGLIB proxies)
Issue: SPR-15271 Issue: SPR-14949 Issue: SPR-14322
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
package org.springframework.transaction.annotation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
@@ -34,7 +36,6 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.tests.transaction.CallCountingTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.AnnotationTransactionNamespaceHandlerTests.TransactionalTestBean;
|
||||
import org.springframework.transaction.config.TransactionManagementConfigUtils;
|
||||
import org.springframework.transaction.event.TransactionalEventListenerFactory;
|
||||
|
||||
@@ -45,6 +46,7 @@ import static org.junit.Assert.*;
|
||||
* Tests demonstrating use of @EnableTransactionManagement @Configuration classes.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
@@ -132,7 +134,7 @@ public class EnableTransactionManagementTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr11915() {
|
||||
public void spr11915TransactionManagerAsManualSingleton() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr11915Config.class);
|
||||
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class);
|
||||
CallCountingTransactionManager txManager = ctx.getBean("qualifiedTransactionManager", CallCountingTransactionManager.class);
|
||||
@@ -150,6 +152,52 @@ public class EnableTransactionManagementTests {
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr14322FindsOnInterfaceWithInterfaceProxy() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigA.class);
|
||||
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class);
|
||||
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
||||
|
||||
bean.saveFoo();
|
||||
assertThat(txManager.begun, equalTo(1));
|
||||
assertThat(txManager.commits, equalTo(1));
|
||||
assertThat(txManager.rollbacks, equalTo(0));
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test @Ignore // TODO
|
||||
public void spr14322FindsOnInterfaceWithCglibProxy() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigB.class);
|
||||
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class);
|
||||
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
||||
|
||||
bean.saveFoo();
|
||||
assertThat(txManager.begun, equalTo(1));
|
||||
assertThat(txManager.commits, equalTo(1));
|
||||
assertThat(txManager.rollbacks, equalTo(0));
|
||||
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
@Service
|
||||
public static class TransactionalTestBean {
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Collection<?> findAllFoos() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Transactional("qualifiedTransactionManager")
|
||||
public void saveQualifiedFoo() {
|
||||
}
|
||||
|
||||
@Transactional(transactionManager = "qualifiedTransactionManager")
|
||||
public void saveQualifiedFooWithAttributeAlias() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@@ -204,23 +252,6 @@ public class EnableTransactionManagementTests {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
static class Spr11915Config {
|
||||
|
||||
@Autowired
|
||||
public void initializeApp(ConfigurableApplicationContext applicationContext) {
|
||||
applicationContext.getBeanFactory().registerSingleton(
|
||||
"qualifiedTransactionManager", new CallCountingTransactionManager());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TransactionalTestBean testBean() {
|
||||
return new TransactionalTestBean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class TxManagerConfig {
|
||||
|
||||
@@ -250,4 +281,69 @@ public class EnableTransactionManagementTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
static class Spr11915Config {
|
||||
|
||||
@Autowired
|
||||
public void initializeApp(ConfigurableApplicationContext applicationContext) {
|
||||
applicationContext.getBeanFactory().registerSingleton(
|
||||
"qualifiedTransactionManager", new CallCountingTransactionManager());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TransactionalTestBean testBean() {
|
||||
return new TransactionalTestBean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface TransactionalTestInterface {
|
||||
|
||||
@Transactional
|
||||
void saveFoo();
|
||||
}
|
||||
|
||||
|
||||
@Service
|
||||
public static class TransactionalTestService implements TransactionalTestInterface {
|
||||
|
||||
@Override
|
||||
public void saveFoo() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
static class Spr14322ConfigA {
|
||||
|
||||
@Bean
|
||||
public TransactionalTestInterface testBean() {
|
||||
return new TransactionalTestService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager txManager() {
|
||||
return new CallCountingTransactionManager();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement(proxyTargetClass = true)
|
||||
static class Spr14322ConfigB {
|
||||
|
||||
@Bean
|
||||
public TransactionalTestInterface testBean() {
|
||||
return new TransactionalTestService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager txManager() {
|
||||
return new CallCountingTransactionManager();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user