From 37d0b1a64d7d21c5f210ff7cfda86ed8c00508ba Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 13 Nov 2014 14:28:20 -0800 Subject: [PATCH] Fix @IntegrationTest context caching Add an additional "IntegrationTest" property to @IntegrationTests to ensure that they get a different MergedContextConfiguration which is used as a context cache key. Fixes gh-1909 --- .../test/IntegrationTestPropertiesListener.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java b/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java index 54582ef501..24139510ce 100644 --- a/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java @@ -62,16 +62,24 @@ class IntegrationTestPropertiesListener extends AbstractTestExecutionListener { private void addPropertySourcePropertiesUsingReflection(TestContext testContext, String[] properties) throws Exception { - if (properties.length == 0) { - return; - } MergedContextConfiguration configuration = (MergedContextConfiguration) ReflectionTestUtils .getField(testContext, "mergedContextConfiguration"); Set merged = new LinkedHashSet((Arrays.asList(configuration .getPropertySourceProperties()))); merged.addAll(Arrays.asList(properties)); + addIntegrationTestProperty(merged); ReflectionTestUtils.setField(configuration, "propertySourceProperties", merged.toArray(new String[merged.size()])); } + /** + * Add an "IntegrationTest" property to ensure that there is something to + * differentiate regular tests and {@code @IntegrationTest} tests. Without this + * property a cached context could be returned that hadn't started the embedded + * servlet container. + * @param propertySourceProperties the property source properties + */ + private void addIntegrationTestProperty(Set propertySourceProperties) { + propertySourceProperties.add(IntegrationTest.class.getName() + "=true"); + } }