From 2685818e9130942684bba1afa37cab8b96df74f3 Mon Sep 17 00:00:00 2001
From: Sam Brannen
Date: Sun, 28 Apr 2013 17:25:46 +0200
Subject: [PATCH] Delete deprecated code in the TestContext framework
This commit deletes the deprecated @ExpectedException and
@NotTransactional annotations, supporting code, and related Javadoc and
reference documentation.
Issue: SPR-10499
---
.../test/annotation/ExpectedException.java | 43 -------------
.../test/annotation/NotTransactional.java | 43 -------------
.../junit4/SpringJUnit4ClassRunner.java | 23 +------
.../TransactionalTestExecutionListener.java | 29 ++++-----
...bstractTransactionalSpringRunnerTests.java | 7 +--
...ssLevelTransactionalSpringRunnerTests.java | 9 ++-
...TransactionalJUnit4SpringContextTests.java | 17 ++---
.../ExpectedExceptionSpringRunnerTests.java | 24 ++-----
.../TimedTransactionalSpringRunnerTests.java | 14 ++---
...TransactionalTestNGSpringContextTests.java | 5 +-
...TransactionalTestNGSpringContextTests.java | 17 ++---
src/reference/docbook/testing.xml | 63 +------------------
12 files changed, 55 insertions(+), 239 deletions(-)
delete mode 100644 spring-test/src/main/java/org/springframework/test/annotation/ExpectedException.java
delete mode 100644 spring-test/src/main/java/org/springframework/test/annotation/NotTransactional.java
diff --git a/spring-test/src/main/java/org/springframework/test/annotation/ExpectedException.java b/spring-test/src/main/java/org/springframework/test/annotation/ExpectedException.java
deleted file mode 100644
index 944f3aeaead..00000000000
--- a/spring-test/src/main/java/org/springframework/test/annotation/ExpectedException.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2002-2012 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.annotation;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Test annotation to indicate that a test method is required to throw the
- * specified exception.
- *
- * @author Rod Johnson
- * @author Sam Brannen
- * @since 2.0
- * @deprecated as of Spring 3.1 in favor of using built-in support for declaring
- * expected exceptions in the underlying testing framework (e.g., JUnit, TestNG, etc.)
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-@Deprecated
-public @interface ExpectedException {
-
- Class extends Throwable> value();
-
-}
diff --git a/spring-test/src/main/java/org/springframework/test/annotation/NotTransactional.java b/spring-test/src/main/java/org/springframework/test/annotation/NotTransactional.java
deleted file mode 100644
index c8539186644..00000000000
--- a/spring-test/src/main/java/org/springframework/test/annotation/NotTransactional.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2002-2012 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.annotation;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Test annotation to indicate that a method is not transactional.
- *
- * @author Rod Johnson
- * @author Sam Brannen
- * @since 2.0
- * @deprecated as of Spring 3.0, in favor of moving the non-transactional test
- * method to a separate (non-transactional) test class or to a
- * {@link org.springframework.test.context.transaction.BeforeTransaction
- * @BeforeTransaction} or
- * {@link org.springframework.test.context.transaction.AfterTransaction
- * @AfterTransaction} method.
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-@Deprecated
-public @interface NotTransactional {
-}
diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java b/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java
index 5496b4ee633..cb40a3273da 100644
--- a/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java
+++ b/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -34,7 +34,6 @@ import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
-import org.springframework.test.annotation.ExpectedException;
import org.springframework.test.annotation.ProfileValueUtils;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Timed;
@@ -64,7 +63,6 @@ import org.springframework.util.ReflectionUtils;
*
*
*
{@link Test#expected() @Test(expected=...)}
- *
{@link ExpectedException @ExpectedException}
*
{@link Test#timeout() @Test(timeout=...)}
*
{@link Timed @Timed}
*
{@link Repeat @Repeat}
@@ -349,9 +347,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
/**
* Get the {@code exception} that the supplied {@link FrameworkMethod
* test method} is expected to throw.
- *
Supports both Spring's {@link ExpectedException @ExpectedException(...)}
- * and JUnit's {@link Test#expected() @Test(expected=...)} annotations, but
- * not both simultaneously.
+ *
Supports JUnit's {@link Test#expected() @Test(expected=...)} annotation.
* @return the expected exception, or {@code null} if none was specified
*/
protected Class extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
@@ -359,20 +355,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
Class extends Throwable> junitExpectedException = (testAnnotation != null
&& testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null);
- ExpectedException expectedExAnn = frameworkMethod.getAnnotation(ExpectedException.class);
- Class extends Throwable> springExpectedException = (expectedExAnn != null ? expectedExAnn.value() : null);
-
- if (springExpectedException != null && junitExpectedException != null) {
- String msg = "Test method [" + frameworkMethod.getMethod()
- + "] has been configured with Spring's @ExpectedException(" + springExpectedException.getName()
- + ".class) and JUnit's @Test(expected=" + junitExpectedException.getName()
- + ".class) annotations. "
- + "Only one declaration of an 'expected exception' is permitted per test method.";
- logger.error(msg);
- throw new IllegalStateException(msg);
- }
-
- return springExpectedException != null ? springExpectedException : junitExpectedException;
+ return junitExpectedException;
}
/**
diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
index 5535fa974f8..46c9b9fb524 100644
--- a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
+++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -35,7 +35,6 @@ import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
-import org.springframework.test.annotation.NotTransactional;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
@@ -56,15 +55,12 @@ import org.springframework.util.StringUtils;
* {@code TestExecutionListener} that provides support for executing tests
* within transactions by honoring the
* {@link org.springframework.transaction.annotation.Transactional @Transactional}
- * and {@link NotTransactional @NotTransactional} annotations. Expects a
- * {@link PlatformTransactionManager} bean to be defined in the Spring
- * {@link ApplicationContext} for the test.
+ * annotation. Expects a {@link PlatformTransactionManager} bean to be defined in the
+ * Spring {@link ApplicationContext} for the test.
*
*
Changes to the database during a test that is run with {@code @Transactional}
* will be run within a transaction that will, by default, be automatically
- * rolled back after completion of the test; whereas, changes to the
- * database during a test that is run with {@code @NotTransactional} will
- * not be run within a transaction. Test methods that are not
+ * rolled back after completion of the test. Test methods that are not
* annotated with {@code @Transactional} (at the class or method level) will not
* be run within a transaction.
*
@@ -93,7 +89,6 @@ import org.springframework.util.StringUtils;
* @see TransactionConfiguration
* @see TransactionManagementConfigurer
* @see org.springframework.transaction.annotation.Transactional
- * @see org.springframework.test.annotation.NotTransactional
* @see org.springframework.test.annotation.Rollback
* @see BeforeTransaction
* @see AfterTransaction
@@ -128,7 +123,6 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
* {@code @BeforeTransaction} methods will not be invoked, and a transaction
* will not be started.
* @see org.springframework.transaction.annotation.Transactional
- * @see org.springframework.test.annotation.NotTransactional
* @see #getTransactionManager(TestContext, String)
*/
@SuppressWarnings("serial")
@@ -142,10 +136,6 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
+ "Invoke endTransaction() before startNewTransaction().");
}
- if (testMethod.isAnnotationPresent(NotTransactional.class)) {
- return;
- }
-
PlatformTransactionManager tm = null;
TransactionAttribute transactionAttribute = this.attributeSource.getTransactionAttribute(testMethod,
testContext.getTestClass());
@@ -162,10 +152,15 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
logger.debug("Explicit transaction definition [" + transactionAttribute + "] found for test context "
+ testContext);
}
- tm = getTransactionManager(testContext, transactionAttribute.getQualifier());
- }
- if (tm != null) {
+ if (transactionAttribute.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) {
+ return;
+ }
+
+ tm = getTransactionManager(testContext, transactionAttribute.getQualifier());
+ }
+
+ if (tm != null) {
TransactionContext txContext = new TransactionContext(tm, transactionAttribute);
runBeforeTransactionMethods(testContext);
startNewTransaction(testContext, txContext);
diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/AbstractTransactionalSpringRunnerTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/AbstractTransactionalSpringRunnerTests.java
index 5ada9b5c618..4924ac1694b 100644
--- a/spring-test/src/test/java/org/springframework/test/context/junit4/AbstractTransactionalSpringRunnerTests.java
+++ b/spring-test/src/test/java/org/springframework/test/context/junit4/AbstractTransactionalSpringRunnerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -18,21 +18,18 @@ package org.springframework.test.context.junit4;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-import org.springframework.test.annotation.NotTransactional;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;
/**
* Abstract base class for verifying support of Spring's {@link Transactional
- * @Transactional} and {@link NotTransactional @NotTransactional}
- * annotations.
+ * @Transactional} annotation.
*
* @author Sam Brannen
* @since 2.5
* @see ClassLevelTransactionalSpringRunnerTests
* @see MethodLevelTransactionalSpringRunnerTests
* @see Transactional
- * @see NotTransactional
*/
@SuppressWarnings("deprecation")
@ContextConfiguration("transactionalTests-context.xml")
diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/ClassLevelTransactionalSpringRunnerTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/ClassLevelTransactionalSpringRunnerTests.java
index 02c0dcf0fa5..1c5475873bc 100644
--- a/spring-test/src/test/java/org/springframework/test/context/junit4/ClassLevelTransactionalSpringRunnerTests.java
+++ b/spring-test/src/test/java/org/springframework/test/context/junit4/ClassLevelTransactionalSpringRunnerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -27,20 +27,19 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-import org.springframework.test.annotation.NotTransactional;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListener;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
+import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
*
* JUnit 4 based integration test which verifies support of Spring's
- * {@link Transactional @Transactional}, {@link NotTransactional
- * @NotTransactional}, {@link TestExecutionListeners
+ * {@link Transactional @Transactional}, {@link TestExecutionListeners
* @TestExecutionListeners}, and {@link ContextConfiguration
* @ContextConfiguration} annotations in conjunction with the
* {@link SpringJUnit4ClassRunner} and the following
@@ -94,7 +93,7 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
}
@Test
- @NotTransactional
+ @Transactional(propagation = Propagation.NOT_SUPPORTED)
public void modifyTestDataWithoutTransaction() {
assertInTransaction(false);
assertEquals("Adding luke", 1, addPerson(simpleJdbcTemplate, LUKE));
diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/ConcreteTransactionalJUnit4SpringContextTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/ConcreteTransactionalJUnit4SpringContextTests.java
index c88aed37d12..90fc7a6101d 100644
--- a/spring-test/src/test/java/org/springframework/test/context/junit4/ConcreteTransactionalJUnit4SpringContextTests.java
+++ b/spring-test/src/test/java/org/springframework/test/context/junit4/ConcreteTransactionalJUnit4SpringContextTests.java
@@ -36,11 +36,12 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-import org.springframework.test.annotation.NotTransactional;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
/**
* Combined integration test for {@link AbstractJUnit4SpringContextTests} and
@@ -131,7 +132,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
}
@Test
- @NotTransactional
+ @Transactional(propagation = Propagation.NOT_SUPPORTED)
public final void verifyApplicationContext() {
assertInTransaction(false);
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.",
@@ -139,7 +140,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
}
@Test
- @NotTransactional
+ @Transactional(propagation = Propagation.NOT_SUPPORTED)
public final void verifyBeanInitialized() {
assertInTransaction(false);
assertTrue("This test bean should have been initialized due to InitializingBean semantics.",
@@ -147,7 +148,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
}
@Test
- @NotTransactional
+ @Transactional(propagation = Propagation.NOT_SUPPORTED)
public final void verifyBeanNameSet() {
assertInTransaction(false);
assertEquals("The bean name of this test instance should have been set to the fully qualified class name "
@@ -155,7 +156,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
}
@Test
- @NotTransactional
+ @Transactional(propagation = Propagation.NOT_SUPPORTED)
public final void verifyAnnotationAutowiredFields() {
assertInTransaction(false);
assertNull("The nonrequiredLong property should NOT have been autowired.", this.nonrequiredLong);
@@ -164,7 +165,7 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
}
@Test
- @NotTransactional
+ @Transactional(propagation = Propagation.NOT_SUPPORTED)
public final void verifyAnnotationAutowiredMethods() {
assertInTransaction(false);
assertNotNull("The employee setter method should have been autowired.", this.employee);
@@ -172,14 +173,14 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
}
@Test
- @NotTransactional
+ @Transactional(propagation = Propagation.NOT_SUPPORTED)
public final void verifyResourceAnnotationWiredFields() {
assertInTransaction(false);
assertEquals("The foo field should have been wired via @Resource.", "Foo", this.foo);
}
@Test
- @NotTransactional
+ @Transactional(propagation = Propagation.NOT_SUPPORTED)
public final void verifyResourceAnnotationWiredMethods() {
assertInTransaction(false);
assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar);
diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java
index d94035194c9..daaa1d1631c 100644
--- a/spring-test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java
+++ b/spring-test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -25,7 +25,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.JUnit4;
-import org.springframework.test.annotation.ExpectedException;
import org.springframework.test.context.TestExecutionListeners;
/**
@@ -33,7 +32,6 @@ import org.springframework.test.context.TestExecutionListeners;
* {@link SpringJUnit4ClassRunner}:
*
*
* @author Sam Brannen
@@ -51,11 +49,11 @@ public class ExpectedExceptionSpringRunnerTests {
notifier.addListener(listener);
new SpringJUnit4ClassRunner(testClass).run(notifier);
- assertEquals("Verifying number of failures for test class [" + testClass + "].", 1,
+ assertEquals("Verifying number of failures for test class [" + testClass + "].", 0,
listener.getTestFailureCount());
- assertEquals("Verifying number of tests started for test class [" + testClass + "].", 3,
+ assertEquals("Verifying number of tests started for test class [" + testClass + "].", 1,
listener.getTestStartedCount());
- assertEquals("Verifying number of tests finished for test class [" + testClass + "].", 3,
+ assertEquals("Verifying number of tests finished for test class [" + testClass + "].", 1,
listener.getTestFinishedCount());
}
@@ -71,20 +69,6 @@ public class ExpectedExceptionSpringRunnerTests {
new ArrayList