Preserve placeholders in @TestPropertySource locations

Prior to this commit, it was impossible to include a placeholder (i.e.,
${placeholder.name}) in a Properties file location configured via
@TestPropertySource if the placeholder was immediately followed by a
relative path (i.e., "../"). This was due to the fact that the location
was always cleaned using StringUtils.cleanPath(), which removed the
placeholder and the relative path syntax.

This commit fixes this by preserving all placeholders in
@TestPropertySource locations by simply not cleaning the locations if
they contain placeholders.

Closes gh-23544
This commit is contained in:
Sam Brannen
2019-08-30 18:57:20 +02:00
parent 9fa9a09007
commit ab779eb431
3 changed files with 30 additions and 7 deletions

View File

@@ -18,7 +18,6 @@ package org.springframework.test.context.env;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
@@ -135,9 +134,8 @@ class ExplicitPropertiesFileTestPropertySourceTests {
}
@Nested
@TestPropertySource("file:${user.dir}/../spring-test/src/test/resources/org/springframework/test/context/env/explicit.properties")
@Disabled("Currently not supported (see https://github.com/spring-projects/spring-framework/issues/23544)")
@DisplayName("with placeholders followed immediately by relative paths")
@TestPropertySource("file:${user.dir}/../spring-test/src/test/resources/${current.test.package}/../env/explicit.properties")
class PlaceholdersFollowedByRelativePathsTests extends AbstractExplicitPropertiesFileTests {
}