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
pull/1931/head
Phillip Webb 10 years ago
parent 0a6c635f5e
commit 37d0b1a64d

@ -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<String> merged = new LinkedHashSet<String>((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<String> propertySourceProperties) {
propertySourceProperties.add(IntegrationTest.class.getName() + "=true");
}
}

Loading…
Cancel
Save