Browse Source

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
pull/263/merge
Sam Brannen 13 years ago
parent
commit
2685818e91
  1. 43
      spring-test/src/main/java/org/springframework/test/annotation/ExpectedException.java
  2. 43
      spring-test/src/main/java/org/springframework/test/annotation/NotTransactional.java
  3. 23
      spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java
  4. 29
      spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java
  5. 7
      spring-test/src/test/java/org/springframework/test/context/junit4/AbstractTransactionalSpringRunnerTests.java
  6. 9
      spring-test/src/test/java/org/springframework/test/context/junit4/ClassLevelTransactionalSpringRunnerTests.java
  7. 17
      spring-test/src/test/java/org/springframework/test/context/junit4/ConcreteTransactionalJUnit4SpringContextTests.java
  8. 24
      spring-test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java
  9. 14
      spring-test/src/test/java/org/springframework/test/context/junit4/TimedTransactionalSpringRunnerTests.java
  10. 5
      spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java
  11. 17
      spring-test/src/test/java/org/springframework/test/context/testng/ConcreteTransactionalTestNGSpringContextTests.java
  12. 63
      src/reference/docbook/testing.xml

43
spring-test/src/main/java/org/springframework/test/annotation/ExpectedException.java

@ -1,43 +0,0 @@ @@ -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();
}

43
spring-test/src/main/java/org/springframework/test/annotation/NotTransactional.java

@ -1,43 +0,0 @@ @@ -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 <i>not transactional</i>.
*
* @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
* &#64;BeforeTransaction} or
* {@link org.springframework.test.context.transaction.AfterTransaction
* &#64;AfterTransaction} method.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Deprecated
public @interface NotTransactional {
}

23
spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java

@ -1,5 +1,5 @@ @@ -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; @@ -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; @@ -64,7 +63,6 @@ import org.springframework.util.ReflectionUtils;
* </p>
* <ul>
* <li>{@link Test#expected() &#064;Test(expected=...)}</li>
* <li>{@link ExpectedException &#064;ExpectedException}</li>
* <li>{@link Test#timeout() &#064;Test(timeout=...)}</li>
* <li>{@link Timed &#064;Timed}</li>
* <li>{@link Repeat &#064;Repeat}</li>
@ -349,9 +347,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { @@ -349,9 +347,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
/**
* Get the {@code exception} that the supplied {@link FrameworkMethod
* test method} is expected to throw.
* <p>Supports both Spring's {@link ExpectedException @ExpectedException(...)}
* and JUnit's {@link Test#expected() @Test(expected=...)} annotations, but
* not both simultaneously.
* <p>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 { @@ -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;
}
/**

29
spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java

@ -1,5 +1,5 @@ @@ -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; @@ -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; @@ -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 &#064;Transactional}
* and {@link NotTransactional &#064;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.
*
* <p>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
* <em>rolled back</em> after completion of the test; whereas, changes to the
* database during a test that is run with {@code @NotTransactional} will
* <strong>not</strong> be run within a transaction. Test methods that are not
* <em>rolled back</em> 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; @@ -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 @@ -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 @@ -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 @@ -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);

7
spring-test/src/test/java/org/springframework/test/context/junit4/AbstractTransactionalSpringRunnerTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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
* &#64;Transactional} and {@link NotTransactional &#64;NotTransactional}
* annotations.
* &#64;Transactional} annotation.
*
* @author Sam Brannen
* @since 2.5
* @see ClassLevelTransactionalSpringRunnerTests
* @see MethodLevelTransactionalSpringRunnerTests
* @see Transactional
* @see NotTransactional
*/
@SuppressWarnings("deprecation")
@ContextConfiguration("transactionalTests-context.xml")

9
spring-test/src/test/java/org/springframework/test/context/junit4/ClassLevelTransactionalSpringRunnerTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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;
/**
* <p>
* JUnit 4 based integration test which verifies support of Spring's
* {@link Transactional &#64;Transactional}, {@link NotTransactional
* &#64;NotTransactional}, {@link TestExecutionListeners
* {@link Transactional &#64;Transactional}, {@link TestExecutionListeners
* &#64;TestExecutionListeners}, and {@link ContextConfiguration
* &#64;ContextConfiguration} annotations in conjunction with the
* {@link SpringJUnit4ClassRunner} and the following
@ -94,7 +93,7 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio @@ -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));

17
spring-test/src/test/java/org/springframework/test/context/junit4/ConcreteTransactionalJUnit4SpringContextTests.java

@ -36,11 +36,12 @@ import org.springframework.beans.factory.InitializingBean; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);

24
spring-test/src/test/java/org/springframework/test/context/junit4/ExpectedExceptionSpringRunnerTests.java

@ -1,5 +1,5 @@ @@ -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; @@ -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; @@ -33,7 +32,6 @@ import org.springframework.test.context.TestExecutionListeners;
* {@link SpringJUnit4ClassRunner}:
* <ul>
* <li>JUnit's {@link Test#expected() &#064;Test(expected=...)}</li>
* <li>Spring's {@link ExpectedException &#064;ExpectedException}</li>
* </ul>
*
* @author Sam Brannen
@ -51,11 +49,11 @@ public class ExpectedExceptionSpringRunnerTests { @@ -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 { @@ -71,20 +69,6 @@ public class ExpectedExceptionSpringRunnerTests {
new ArrayList<Object>().get(1);
}
// Should Pass.
@Test
@ExpectedException(IndexOutOfBoundsException.class)
public void verifySpringExpectedException() {
new ArrayList<Object>().get(1);
}
// Should Fail due to duplicate configuration.
@Test(expected = IllegalStateException.class)
@ExpectedException(IllegalStateException.class)
public void verifyJUnitAndSpringExpectedException() {
new ArrayList<Object>().get(1);
}
}
}

14
spring-test/src/test/java/org/springframework/test/context/junit4/TimedTransactionalSpringRunnerTests.java

@ -1,5 +1,5 @@ @@ -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.
@ -20,17 +20,17 @@ import static org.springframework.test.transaction.TransactionTestUtils.assertIn @@ -20,17 +20,17 @@ import static org.springframework.test.transaction.TransactionTestUtils.assertIn
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.NotTransactional;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Timed;
import org.springframework.test.context.ContextConfiguration;
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 &#64;Transactional} and {@link NotTransactional
* &#64;NotTransactional} annotations in conjunction with {@link Timed
* &#64;Timed} and JUnit 4's {@link Test#timeout() timeout} attribute.
* {@link Transactional &#64;Transactional} annotation in conjunction
* with {@link Timed &#64;Timed} and JUnit 4's {@link Test#timeout()
* timeout} attribute.
*
* @author Sam Brannen
* @since 2.5
@ -55,7 +55,7 @@ public class TimedTransactionalSpringRunnerTests { @@ -55,7 +55,7 @@ public class TimedTransactionalSpringRunnerTests {
}
@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Timed(millis = 10000)
@Repeat(5)
public void notTransactionalWithSpringTimeout() {
@ -63,7 +63,7 @@ public class TimedTransactionalSpringRunnerTests { @@ -63,7 +63,7 @@ public class TimedTransactionalSpringRunnerTests {
}
@Test(timeout = 10000)
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Repeat(5)
public void notTransactionalWithJUnitTimeout() {
assertInTransaction(false);

5
spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java

@ -30,11 +30,12 @@ import org.springframework.context.annotation.Bean; @@ -30,11 +30,12 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
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.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
@ -111,7 +112,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends @@ -111,7 +112,7 @@ public class AnnotationConfigTransactionalTestNGSpringContextTests extends
}
@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void autowiringFromConfigClass() {
assertNotNull(employee, "The employee should have been autowired.");
assertEquals(employee.getName(), "John Smith");

17
spring-test/src/test/java/org/springframework/test/context/testng/ConcreteTransactionalTestNGSpringContextTests.java

@ -30,10 +30,11 @@ import org.springframework.tests.sample.beans.Pet; @@ -30,10 +30,11 @@ import org.springframework.tests.sample.beans.Pet;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
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.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
@ -136,7 +137,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans @@ -136,7 +137,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyApplicationContextSet() {
assertInTransaction(false);
assertNotNull(super.applicationContext,
@ -146,7 +147,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans @@ -146,7 +147,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyBeanInitialized() {
assertInTransaction(false);
assertTrue(beanInitialized,
@ -154,7 +155,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans @@ -154,7 +155,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyBeanNameSet() {
assertInTransaction(false);
assertEquals(beanName, getClass().getName(),
@ -162,7 +163,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans @@ -162,7 +163,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyAnnotationAutowiredFields() {
assertInTransaction(false);
assertNull(nonrequiredLong, "The nonrequiredLong field should NOT have been autowired.");
@ -171,7 +172,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans @@ -171,7 +172,7 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyAnnotationAutowiredMethods() {
assertInTransaction(false);
assertNotNull(employee, "The setEmployee() method should have been autowired.");
@ -179,14 +180,14 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans @@ -179,14 +180,14 @@ public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTrans
}
@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyResourceAnnotationInjectedFields() {
assertInTransaction(false);
assertEquals(foo, "Foo", "The foo field should have been injected via @Resource.");
}
@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyResourceAnnotationInjectedMethods() {
assertInTransaction(false);
assertEquals(bar, "Bar", "The setBar() method should have been injected via @Resource.");

63
src/reference/docbook/testing.xml

@ -198,30 +198,6 @@ @@ -198,30 +198,6 @@
thus allowing instrumentation of tests in various environments including
JUnit, TestNG, and so on.</para>
<warning>
<title>JUnit 3.8 support is deprecated</title>
<para>As of Spring 3.0, the legacy JUnit 3.8 base class hierarchy (i.e.,
<classname>AbstractDependencyInjectionSpringContextTests</classname>,
<classname>AbstractTransactionalDataSourceSpringContextTests</classname>,
etc.) is officially deprecated and will be removed in a later release.
Any test classes based on this code should be migrated to the <link
linkend="testcontext-framework">Spring TestContext
Framework</link>.</para>
<para>As of Spring 3.1, the JUnit 3.8 base classes in the Spring
TestContext Framework (i.e.,
<classname>AbstractJUnit38SpringContextTests</classname> and
<classname>AbstractTransactionalJUnit38SpringContextTests</classname>)
and <interfacename>@ExpectedException</interfacename> have been
officially deprecated and will be removed in a later release. Any test
classes based on this code should be migrated to the JUnit 4 or TestNG
support provided by the <link linkend="testcontext-framework">Spring
TestContext Framework</link>. Similarly, any test methods annotated with
<interfacename>@ExpectedException</interfacename> should be modified to
use the built-in support for expected exceptions in JUnit and
TestNG.</para>
</warning>
</section>
<section xml:id="integration-testing-goals">
@ -852,39 +828,6 @@ public void testProcessWithoutRollback() { @@ -852,39 +828,6 @@ public void testProcessWithoutRollback() {
<lineannotation>// logic to be executed after a transaction has ended</lineannotation>
}</programlisting>
</listitem>
<listitem>
<para><emphasis role="bold">
<interfacename>@NotTransactional</interfacename> </emphasis></para>
<para>The presence of this annotation indicates that the annotated
test method must <emphasis>not</emphasis> execute in a transactional
context.</para>
<programlisting language="java"><emphasis role="bold">@NotTransactional</emphasis>
@Test
public void testProcessWithoutTransaction() {
<lineannotation>// ...</lineannotation>
}</programlisting>
<warning>
<title>@NotTransactional is deprecated</title>
<para>As of Spring 3.0,
<interfacename>@NotTransactional</interfacename> is deprecated in
favor of moving the <emphasis>non-transactional</emphasis> test
method to a separate (non-transactional) test class or to a
<interfacename>@BeforeTransaction</interfacename> or
<interfacename>@AfterTransaction</interfacename> method. As an
alternative to annotating an entire class with
<interfacename>@Transactional</interfacename>, consider annotating
individual methods with
<interfacename>@Transactional</interfacename>; doing so allows a
mix of transactional and non-transactional methods in the same
test class without the need for using
<interfacename>@NotTransactional</interfacename>.</para>
</warning>
</listitem>
</itemizedlist>
</section>
@ -2788,10 +2731,8 @@ public class SessionScopedBeanTests { @@ -2788,10 +2731,8 @@ public class SessionScopedBeanTests {
role="bold">within</emphasis> a transaction. In addition, methods
annotated with <interfacename>@BeforeTransaction</interfacename> or
<interfacename>@AfterTransaction</interfacename> are naturally not
executed for tests annotated with
<interfacename>@NotTransactional</interfacename>. However,
<interfacename>@NotTransactional</interfacename> is deprecated as of
Spring 3.0.</para>
executed for test methods that are not configured to run within a
transaction.</para>
</tip>
<para>The following JUnit-based example displays a fictitious

Loading…
Cancel
Save