From c2908399141381de5b9f79f29d5b90c822a7b7e3 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 16 Jul 2014 21:34:43 +0200 Subject: [PATCH] Investigate claim on SO regarding ctx cache in TCF This commit introduces a test that investigates a claim made on Stack Overflow regarding context caching in the TestContext Framework (TCF). --- .../AbstractContextLoaderUtilsTests.java | 5 ++++ .../ContextLoaderUtilsMergedConfigTests.java | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextLoaderUtilsTests.java b/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextLoaderUtilsTests.java index eae38bc594..7224cdc0b1 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextLoaderUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/AbstractContextLoaderUtilsTests.java @@ -36,6 +36,7 @@ import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextLoader; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.TestContextBootstrapper; +import org.springframework.test.context.web.WebAppConfiguration; import static org.junit.Assert.*; @@ -170,6 +171,10 @@ abstract class AbstractContextLoaderUtilsTests { static class ClassesFoo { } + @WebAppConfiguration + static class WebClassesFoo extends ClassesFoo { + } + @ContextConfiguration(locations = "/bar.xml", inheritLocations = true, loader = AnnotationConfigContextLoader.class) @ActiveProfiles("bar") static class LocationsBar extends LocationsFoo { diff --git a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsMergedConfigTests.java b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsMergedConfigTests.java index 4c84359632..eb4fce5aba 100644 --- a/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsMergedConfigTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsMergedConfigTests.java @@ -25,6 +25,10 @@ import org.junit.Test; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextLoader; import org.springframework.test.context.MergedContextConfiguration; +import org.springframework.test.context.web.WebDelegatingSmartContextLoader; +import org.springframework.test.context.web.WebMergedContextConfiguration; + +import static org.junit.Assert.*; /** * Unit tests for {@link ContextLoaderUtils} involving {@link MergedContextConfiguration}. @@ -94,6 +98,28 @@ public class ContextLoaderUtilsMergedConfigTests extends AbstractContextLoaderUt DelegatingSmartContextLoader.class); } + /** + * Introduced to investigate claims made in a discussion on + * Stack Overflow. + */ + @Test + public void buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass() { + Class webTestClass = WebClassesFoo.class; + Class standardTestClass = ClassesFoo.class; + WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) buildMergedContextConfiguration(webTestClass); + MergedContextConfiguration standardMergedConfig = buildMergedContextConfiguration(standardTestClass); + + assertEquals(webMergedConfig, webMergedConfig); + assertEquals(standardMergedConfig, standardMergedConfig); + assertNotEquals(standardMergedConfig, webMergedConfig); + assertNotEquals(webMergedConfig, standardMergedConfig); + + assertMergedConfig(webMergedConfig, webTestClass, EMPTY_STRING_ARRAY, new Class[] { FooConfig.class }, + WebDelegatingSmartContextLoader.class); + assertMergedConfig(standardMergedConfig, standardTestClass, EMPTY_STRING_ARRAY, + new Class[] { FooConfig.class }, DelegatingSmartContextLoader.class); + } + @Test public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLocations() { Class testClass = PropertiesLocationsFoo.class;