Remove deprecated @TransactionConfiguration & TxCfgAttributes
Issue: SPR-14430
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.context.transaction;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* {@code TransactionConfiguration} defines class-level metadata for configuring
|
||||
* transactional tests.
|
||||
*
|
||||
* <p>As of Spring Framework 4.0, this annotation may be used as a
|
||||
* <em>meta-annotation</em> to create custom <em>composed annotations</em>.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see TransactionalTestExecutionListener
|
||||
* @see org.springframework.transaction.annotation.Transactional
|
||||
* @see org.springframework.test.annotation.Commit
|
||||
* @see org.springframework.test.annotation.Rollback
|
||||
* @see org.springframework.test.context.jdbc.Sql
|
||||
* @see org.springframework.test.context.jdbc.SqlConfig
|
||||
* @see org.springframework.test.context.jdbc.SqlConfig#transactionManager
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @deprecated As of Spring Framework 4.2, use {@code @Rollback} or
|
||||
* {@code @Commit} at the class level and the {@code transactionManager}
|
||||
* qualifier in {@code @Transactional}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Documented
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface TransactionConfiguration {
|
||||
|
||||
/**
|
||||
* The bean name of the {@link org.springframework.transaction.PlatformTransactionManager
|
||||
* PlatformTransactionManager} that should be used to drive <em>test-managed transactions</em>.
|
||||
*
|
||||
* <p>The name is only used if there is more than one bean of type
|
||||
* {@code PlatformTransactionManager} in the test's {@code ApplicationContext}.
|
||||
* If there is only one such bean, it is not necessary to specify a bean name.
|
||||
*
|
||||
* <p>Defaults to an empty string, requiring that one of the following is
|
||||
* true:
|
||||
* <ol>
|
||||
* <li>There is only one bean of type {@code PlatformTransactionManager} in
|
||||
* the test's {@code ApplicationContext}.</li>
|
||||
* <li>{@link org.springframework.transaction.annotation.TransactionManagementConfigurer
|
||||
* TransactionManagementConfigurer} has been implemented to specify which
|
||||
* {@code PlatformTransactionManager} bean should be used for annotation-driven
|
||||
* transaction management.</li>
|
||||
* <li>The {@code PlatformTransactionManager} to use is named
|
||||
* {@code "transactionManager"}.</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p><b>NOTE:</b> The XML {@code <tx:annotation-driven>} element also refers
|
||||
* to a bean named {@code "transactionManager"} by default. If you are using both
|
||||
* features in combination, make sure to point to the same transaction manager
|
||||
* bean — here in {@code @TransactionConfiguration} and also in
|
||||
* {@code <tx:annotation-driven transaction-manager="...">}.
|
||||
*/
|
||||
String transactionManager() default "";
|
||||
|
||||
/**
|
||||
* Whether <em>test-managed transactions</em> should be rolled back by default.
|
||||
*/
|
||||
boolean defaultRollback() default true;
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.context.transaction;
|
||||
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Configuration attributes for configuring transactional tests.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5
|
||||
* @see TransactionConfiguration
|
||||
* @deprecated As of Spring Framework 4.2, this class is officially deprecated
|
||||
* and will be removed when {@code @TransactionConfiguration} is removed.
|
||||
*/
|
||||
@Deprecated
|
||||
public class TransactionConfigurationAttributes {
|
||||
|
||||
private final String transactionManagerName;
|
||||
|
||||
private final boolean defaultRollback;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new {@code TransactionConfigurationAttributes} instance
|
||||
* using an empty string for the bean name of the
|
||||
* {@link PlatformTransactionManager} and {@code true} for the default
|
||||
* rollback flag.
|
||||
* @see #TransactionConfigurationAttributes(String, boolean)
|
||||
*/
|
||||
public TransactionConfigurationAttributes() {
|
||||
this("", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@code TransactionConfigurationAttributes} instance
|
||||
* from the supplied arguments.
|
||||
* @param transactionManagerName the bean name of the
|
||||
* {@link PlatformTransactionManager} that is to be used to drive
|
||||
* <em>test-managed transactions</em>
|
||||
* @param defaultRollback whether or not <em>test-managed transactions</em>
|
||||
* should be rolled back by default
|
||||
*/
|
||||
public TransactionConfigurationAttributes(String transactionManagerName, boolean defaultRollback) {
|
||||
Assert.notNull(transactionManagerName, "transactionManagerName must not be null");
|
||||
this.transactionManagerName = transactionManagerName;
|
||||
this.defaultRollback = defaultRollback;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the bean name of the {@link PlatformTransactionManager} that is to
|
||||
* be used to drive <em>test-managed transactions</em>.
|
||||
*/
|
||||
public final String getTransactionManagerName() {
|
||||
return this.transactionManagerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether <em>test-managed transactions</em> should be rolled back by default.
|
||||
* @return the <em>default rollback</em> flag
|
||||
*/
|
||||
public final boolean isDefaultRollback() {
|
||||
return this.defaultRollback;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this)
|
||||
.append("transactionManagerName", this.transactionManagerName)
|
||||
.append("defaultRollback", this.defaultRollback)
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -132,16 +132,9 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TransactionalTestExecutionListener.class);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static final TransactionConfigurationAttributes defaultTxConfigAttributes = new TransactionConfigurationAttributes();
|
||||
|
||||
// Do not require @Transactional test methods to be public.
|
||||
protected final TransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource(false);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private TransactionConfigurationAttributes configurationAttributes;
|
||||
|
||||
|
||||
/**
|
||||
* Returns {@code 4000}.
|
||||
*/
|
||||
@@ -356,33 +349,23 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
||||
* @see #getTransactionManager(TestContext, String)
|
||||
*/
|
||||
protected PlatformTransactionManager getTransactionManager(TestContext testContext) {
|
||||
@SuppressWarnings("deprecation")
|
||||
String tmName = retrieveConfigurationAttributes(testContext).getTransactionManagerName();
|
||||
return TestContextTransactionUtils.retrieveTransactionManager(testContext, tmName);
|
||||
return TestContextTransactionUtils.retrieveTransactionManager(testContext, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not to rollback transactions by default for the
|
||||
* supplied {@linkplain TestContext test context}.
|
||||
* <p>Supports {@link Rollback @Rollback}, {@link Commit @Commit}, or
|
||||
* {@link TransactionConfiguration @TransactionConfiguration} at the
|
||||
* <p>Supports {@link Rollback @Rollback} or {@link Commit @Commit} at the
|
||||
* class-level.
|
||||
* @param testContext the test context for which the default rollback flag
|
||||
* should be retrieved
|
||||
* @return the <em>default rollback</em> flag for the supplied test context
|
||||
* @throws Exception if an error occurs while determining the default rollback flag
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
protected final boolean isDefaultRollback(TestContext testContext) throws Exception {
|
||||
Class<?> testClass = testContext.getTestClass();
|
||||
Rollback rollback = AnnotatedElementUtils.findMergedAnnotation(testClass, Rollback.class);
|
||||
boolean rollbackPresent = (rollback != null);
|
||||
TransactionConfigurationAttributes txConfigAttributes = retrieveConfigurationAttributes(testContext);
|
||||
|
||||
if (rollbackPresent && txConfigAttributes != defaultTxConfigAttributes) {
|
||||
throw new IllegalStateException(String.format("Test class [%s] is annotated with both @Rollback "
|
||||
+ "and @TransactionConfiguration, but only one is permitted.", testClass.getName()));
|
||||
}
|
||||
|
||||
if (rollbackPresent) {
|
||||
boolean defaultRollback = rollback.value();
|
||||
@@ -394,7 +377,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
||||
}
|
||||
|
||||
// else
|
||||
return txConfigAttributes.isDefaultRollback();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,41 +430,4 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the {@link TransactionConfigurationAttributes} for the
|
||||
* supplied {@link TestContext} whose {@linkplain Class test class}
|
||||
* may optionally declare or inherit
|
||||
* {@link TransactionConfiguration @TransactionConfiguration}.
|
||||
* <p>If {@code @TransactionConfiguration} is not present for the
|
||||
* supplied {@code TestContext}, a default instance of
|
||||
* {@code TransactionConfigurationAttributes} will be used instead.
|
||||
* @param testContext the test context for which the configuration
|
||||
* attributes should be retrieved
|
||||
* @return the TransactionConfigurationAttributes instance for this listener,
|
||||
* potentially cached
|
||||
* @see TransactionConfigurationAttributes#TransactionConfigurationAttributes()
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
TransactionConfigurationAttributes retrieveConfigurationAttributes(TestContext testContext) {
|
||||
if (this.configurationAttributes == null) {
|
||||
Class<?> clazz = testContext.getTestClass();
|
||||
|
||||
TransactionConfiguration txConfig =
|
||||
AnnotatedElementUtils.findMergedAnnotation(clazz, TransactionConfiguration.class);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Retrieved @TransactionConfiguration [%s] for test class [%s].",
|
||||
txConfig, clazz.getName()));
|
||||
}
|
||||
|
||||
TransactionConfigurationAttributes configAttributes = (txConfig == null ? defaultTxConfigAttributes :
|
||||
new TransactionConfigurationAttributes(txConfig.transactionManager(), txConfig.defaultRollback()));
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Using TransactionConfigurationAttributes %s for test class [%s].",
|
||||
configAttributes, clazz.getName()));
|
||||
}
|
||||
this.configurationAttributes = configAttributes;
|
||||
}
|
||||
return this.configurationAttributes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user