Skip to content

Commit

Permalink
Delete deprecated code in the TestContext framework
Browse files Browse the repository at this point in the history
This commit deletes the deprecated @ExpectedException and
@NotTransactional annotations, supporting code, and related Javadoc and
reference documentation.

Issue: SPR-10499
  • Loading branch information
sbrannen committed Apr 28, 2013
1 parent eb65b2b commit 2685818
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 239 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -34,7 +34,6 @@
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;
Expand Down Expand Up @@ -64,7 +63,6 @@
* </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>
Expand Down Expand Up @@ -349,30 +347,15 @@ protected Statement possiblyExpectingExceptions(FrameworkMethod frameworkMethod,
/**
* 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) {
Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -35,7 +35,6 @@
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;
Expand All @@ -56,15 +55,12 @@
* {@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.
*
Expand Down Expand Up @@ -93,7 +89,6 @@
* @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
Expand Down Expand Up @@ -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")
Expand All @@ -142,10 +136,6 @@ public void beforeTestMethod(TestContext testContext) throws Exception {
+ "Invoke endTransaction() before startNewTransaction().");
}

if (testMethod.isAnnotationPresent(NotTransactional.class)) {
return;
}

PlatformTransactionManager tm = null;
TransactionAttribute transactionAttribute = this.attributeSource.getTransactionAttribute(testMethod,
testContext.getTestClass());
Expand All @@ -162,10 +152,15 @@ public String getName() {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,21 +18,18 @@

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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -27,20 +27,19 @@
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
Expand Down Expand Up @@ -94,7 +93,7 @@ public void modifyTestDataWithinTransaction() {
}

@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void modifyTestDataWithoutTransaction() {
assertInTransaction(false);
assertEquals("Adding luke", 1, addPerson(simpleJdbcTemplate, LUKE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
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
Expand Down Expand Up @@ -131,31 +132,31 @@ public final void afterPropertiesSet() throws Exception {
}

@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.",
super.applicationContext);
}

@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.",
this.beanInitialized);
}

@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 "
+ "due to BeanNameAware semantics.", getClass().getName(), this.beanName);
}

@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public final void verifyAnnotationAutowiredFields() {
assertInTransaction(false);
assertNull("The nonrequiredLong property should NOT have been autowired.", this.nonrequiredLong);
Expand All @@ -164,22 +165,22 @@ public final void verifyAnnotationAutowiredFields() {
}

@Test
@NotTransactional
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public final void verifyAnnotationAutowiredMethods() {
assertInTransaction(false);
assertNotNull("The employee setter method should have been autowired.", this.employee);
assertEquals("John Smith", this.employee.getName());
}

@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);
Expand Down
Loading

0 comments on commit 2685818

Please sign in to comment.