diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionConfiguration.java deleted file mode 100644 index e35e862e3e..0000000000 --- a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionConfiguration.java +++ /dev/null @@ -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. - * - *
As of Spring Framework 4.0, this annotation may be used as a - * meta-annotation to create custom composed annotations. - * - * @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 test-managed transactions. - * - *
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. - * - *
Defaults to an empty string, requiring that one of the following is - * true: - *
NOTE: The XML {@code Supports {@link Rollback @Rollback}, {@link Commit @Commit}, or
- * {@link TransactionConfiguration @TransactionConfiguration} at the
+ * 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 default rollback 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}.
- * 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;
- }
-
}
diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/DefaultRollbackFalseTransactionalTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/DefaultRollbackFalseTransactionalTests.java
deleted file mode 100644
index 49726735f1..0000000000
--- a/spring-test/src/test/java/org/springframework/test/context/junit4/DefaultRollbackFalseTransactionalTests.java
+++ /dev/null
@@ -1,85 +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.junit4;
-
-import javax.sql.DataSource;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.test.context.transaction.TransactionConfiguration;
-import org.springframework.transaction.annotation.Transactional;
-
-import static org.junit.Assert.*;
-import static org.springframework.test.transaction.TransactionTestUtils.*;
-
-/**
- * JUnit 4 based integration test which verifies proper transactional behavior when the
- * {@link TransactionConfiguration#defaultRollback() defaultRollback} attribute
- * of the {@link TransactionConfiguration} annotation is set to {@code false}.
- *
- * Also tests configuration of the
- * {@link TransactionConfiguration#transactionManager() transaction manager name}.
- *
- * @author Sam Brannen
- * @since 2.5
- * @see TransactionConfiguration
- * @see DefaultRollbackFalseRollbackAnnotationTransactionalTests
- */
-@TransactionConfiguration(transactionManager = "transactionManager2", defaultRollback = false)
-@Transactional
-@SuppressWarnings("deprecation")
-public class DefaultRollbackFalseTransactionalTests extends AbstractTransactionalSpringRunnerTests {
-
- private static JdbcTemplate jdbcTemplate;
-
-
- @Autowired
- @Qualifier("dataSource2")
- public void setDataSource(DataSource dataSource) {
- jdbcTemplate = new JdbcTemplate(dataSource);
- }
-
- @Before
- public void verifyInitialTestData() {
- clearPersonTable(jdbcTemplate);
- assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
- assertEquals("Verifying the initial number of rows in the person table.", 1,
- countRowsInPersonTable(jdbcTemplate));
- }
-
- @Test
- public void modifyTestDataWithinTransaction() {
- assertInTransaction(true);
- assertEquals("Deleting bob", 1, deletePerson(jdbcTemplate, BOB));
- assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
- assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
- assertEquals("Verifying the number of rows in the person table within a transaction.", 2,
- countRowsInPersonTable(jdbcTemplate));
- }
-
- @AfterClass
- public static void verifyFinalTestData() {
- assertEquals("Verifying the final number of rows in the person table after all tests.", 2,
- countRowsInPersonTable(jdbcTemplate));
- }
-
-}
diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/DefaultRollbackTrueTransactionalTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/DefaultRollbackTrueTransactionalTests.java
deleted file mode 100644
index aa2e736e5b..0000000000
--- a/spring-test/src/test/java/org/springframework/test/context/junit4/DefaultRollbackTrueTransactionalTests.java
+++ /dev/null
@@ -1,80 +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.junit4;
-
-import javax.sql.DataSource;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.test.context.transaction.TransactionConfiguration;
-import org.springframework.transaction.annotation.Transactional;
-
-import static org.junit.Assert.*;
-import static org.springframework.test.transaction.TransactionTestUtils.*;
-
-/**
- * JUnit 4 based integration test which verifies proper transactional behavior when the
- * {@link TransactionConfiguration#defaultRollback() defaultRollback} attribute
- * of the {@link TransactionConfiguration} annotation is set to {@code true}.
- *
- * @author Sam Brannen
- * @since 2.5
- * @see TransactionConfiguration
- */
-@Transactional
-@TransactionConfiguration(defaultRollback = true)
-@SuppressWarnings("deprecation")
-public class DefaultRollbackTrueTransactionalTests extends AbstractTransactionalSpringRunnerTests {
-
- private static int originalNumRows;
-
- private static JdbcTemplate jdbcTemplate;
-
-
- @Autowired
- public void setDataSource(DataSource dataSource) {
- jdbcTemplate = new JdbcTemplate(dataSource);
- }
-
- @Before
- public void verifyInitialTestData() {
- originalNumRows = clearPersonTable(jdbcTemplate);
- assertEquals("Adding bob", 1, addPerson(jdbcTemplate, BOB));
- assertEquals("Verifying the initial number of rows in the person table.", 1,
- countRowsInPersonTable(jdbcTemplate));
- }
-
- @Test(timeout = 1000)
- public void modifyTestDataWithinTransaction() {
- assertInTransaction(true);
- assertEquals("Adding jane", 1, addPerson(jdbcTemplate, JANE));
- assertEquals("Adding sue", 1, addPerson(jdbcTemplate, SUE));
- assertEquals("Verifying the number of rows in the person table within a transaction.", 3,
- countRowsInPersonTable(jdbcTemplate));
- }
-
- @AfterClass
- public static void verifyFinalTestData() {
- assertEquals("Verifying the final number of rows in the person table after all tests.", originalNumRows,
- countRowsInPersonTable(jdbcTemplate));
- }
-
-}
diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/RollbackOverrideDefaultRollbackFalseTransactionalTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/RollbackOverrideDefaultRollbackFalseTransactionalTests.java
index 2af35812d5..e71c7782c5 100644
--- a/spring-test/src/test/java/org/springframework/test/context/junit4/RollbackOverrideDefaultRollbackFalseTransactionalTests.java
+++ b/spring-test/src/test/java/org/springframework/test/context/junit4/RollbackOverrideDefaultRollbackFalseTransactionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * 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.
@@ -23,7 +23,6 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.annotation.Rollback;
@@ -31,15 +30,16 @@ import static org.junit.Assert.*;
import static org.springframework.test.transaction.TransactionTestUtils.*;
/**
- * Extension of {@link DefaultRollbackFalseTransactionalTests} which
- * tests method-level rollback override behavior via the
+ * Extension of {@link DefaultRollbackFalseRollbackAnnotationTransactionalTests}
+ * which tests method-level rollback override behavior via the
* {@link Rollback @Rollback} annotation.
*
* @author Sam Brannen
* @since 2.5
* @see Rollback
*/
-public class RollbackOverrideDefaultRollbackFalseTransactionalTests extends DefaultRollbackFalseTransactionalTests {
+public class RollbackOverrideDefaultRollbackFalseTransactionalTests
+ extends DefaultRollbackFalseRollbackAnnotationTransactionalTests {
private static int originalNumRows;
@@ -47,7 +47,6 @@ public class RollbackOverrideDefaultRollbackFalseTransactionalTests extends Defa
@Autowired
- @Qualifier("dataSource2")
@Override
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/RollbackOverrideDefaultRollbackTrueTransactionalTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/RollbackOverrideDefaultRollbackTrueTransactionalTests.java
index 6a568eaa3f..86abee8b0a 100644
--- a/spring-test/src/test/java/org/springframework/test/context/junit4/RollbackOverrideDefaultRollbackTrueTransactionalTests.java
+++ b/spring-test/src/test/java/org/springframework/test/context/junit4/RollbackOverrideDefaultRollbackTrueTransactionalTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * 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.
@@ -30,15 +30,16 @@ import static org.junit.Assert.*;
import static org.springframework.test.transaction.TransactionTestUtils.*;
/**
- * Extension of {@link DefaultRollbackTrueTransactionalTests} which
- * tests method-level rollback override behavior via the
+ * Extension of {@link DefaultRollbackTrueRollbackAnnotationTransactionalTests}
+ * which tests method-level rollback override behavior via the
* {@link Rollback @Rollback} annotation.
*
* @author Sam Brannen
* @since 2.5
* @see Rollback
*/
-public class RollbackOverrideDefaultRollbackTrueTransactionalTests extends DefaultRollbackTrueTransactionalTests {
+public class RollbackOverrideDefaultRollbackTrueTransactionalTests
+ extends DefaultRollbackTrueRollbackAnnotationTransactionalTests {
private static JdbcTemplate jdbcTemplate;
diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java b/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java
index 020bda60de..18ec53257e 100644
--- a/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java
+++ b/spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java
@@ -104,8 +104,8 @@ StandardJUnit4FeaturesTests.class,//
ConcreteTransactionalJUnit4SpringContextTests.class,//
ClassLevelTransactionalSpringRunnerTests.class,//
MethodLevelTransactionalSpringRunnerTests.class,//
- DefaultRollbackTrueTransactionalTests.class,//
- DefaultRollbackFalseTransactionalTests.class,//
+ DefaultRollbackTrueRollbackAnnotationTransactionalTests.class,//
+ DefaultRollbackFalseRollbackAnnotationTransactionalTests.class,//
RollbackOverrideDefaultRollbackTrueTransactionalTests.class,//
RollbackOverrideDefaultRollbackFalseTransactionalTests.class,//
BeforeAndAfterTransactionAnnotationTests.class,//
diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java
index 82cb00816e..bc408ef73d 100644
--- a/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java
+++ b/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java
@@ -36,7 +36,6 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.SimpleTransactionStatus;
-import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.springframework.transaction.annotation.Propagation.*;
@@ -47,7 +46,6 @@ import static org.springframework.transaction.annotation.Propagation.*;
* @author Sam Brannen
* @since 4.0
*/
-@SuppressWarnings("deprecation")
public class TransactionalTestExecutionListenerTests {
private final PlatformTransactionManager tm = mock(PlatformTransactionManager.class);
@@ -135,16 +133,6 @@ public class TransactionalTestExecutionListenerTests {
assertFalse("callback should not have been invoked", instance.invoked());
}
- private void assertTransactionConfigurationAttributes(Class> clazz, String transactionManagerName,
- boolean defaultRollback) {
- BDDMockito.