Test status quo in 5.3.x for PathMatchingResourcePatternResolver
See gh-29333
This commit is contained in:
parent
8e25e32eb8
commit
652781c4a1
|
|
@ -100,13 +100,94 @@ class PathMatchingResourcePatternResolverTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void usingFileProtocol() {
|
||||
void usingClasspathStarProtocolWithWildcardInPatternAndNotEndingInSlash() throws Exception {
|
||||
String pattern = "classpath*:org/springframework/core/io/sup*";
|
||||
String pathPrefix = ".+org/springframework/core/io/";
|
||||
|
||||
List<String> actualSubPaths = getSubPathsIgnoringClassFiles(pattern, pathPrefix);
|
||||
|
||||
// We DO find "support" if the pattern does NOT end with a slash.
|
||||
assertThat(actualSubPaths).containsExactly("support");
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingFileProtocolWithWildcardInPatternAndNotEndingInSlash() throws Exception {
|
||||
Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath();
|
||||
String pattern = String.format("file:%s/org/springframework/core/io/sup*", testResourcesDir);
|
||||
String pathPrefix = ".+org/springframework/core/io/";
|
||||
|
||||
List<String> actualSubPaths = getSubPathsIgnoringClassFiles(pattern, pathPrefix);
|
||||
|
||||
// We DO find "support" if the pattern does NOT end with a slash.
|
||||
assertThat(actualSubPaths).containsExactly("support");
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingClasspathStarProtocolWithWildcardInPatternAndEndingInSlash() throws Exception {
|
||||
String pattern = "classpath*:org/springframework/core/io/sup*/";
|
||||
String pathPrefix = ".+org/springframework/core/io/";
|
||||
|
||||
List<String> actualSubPaths = getSubPathsIgnoringClassFiles(pattern, pathPrefix);
|
||||
|
||||
// We do NOT find "support" if the pattern ENDS with a slash.
|
||||
assertThat(actualSubPaths).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingFileProtocolWithWildcardInPatternAndEndingInSlash() throws Exception {
|
||||
Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath();
|
||||
String pattern = String.format("file:%s/org/springframework/core/io/sup*/", testResourcesDir);
|
||||
String pathPrefix = ".+org/springframework/core/io/";
|
||||
|
||||
List<String> actualSubPaths = getSubPathsIgnoringClassFiles(pattern, pathPrefix);
|
||||
|
||||
// We do NOT find "support" if the pattern ENDS with a slash.
|
||||
assertThat(actualSubPaths).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingClasspathStarProtocolWithWildcardInPatternAndEndingWithSlashStarStar() throws Exception {
|
||||
String pattern = "classpath*:org/springframework/core/io/sup*/**";
|
||||
String pathPrefix = ".+org/springframework/core/io/";
|
||||
|
||||
List<String> actualSubPaths = getSubPathsIgnoringClassFiles(pattern, pathPrefix);
|
||||
|
||||
// We DO find "support" if the pattern ENDS with "/**".
|
||||
assertThat(actualSubPaths)
|
||||
.containsExactlyInAnyOrder("support", "support/resource#test1.txt", "support/resource#test2.txt");
|
||||
}
|
||||
|
||||
private List<String> getSubPathsIgnoringClassFiles(String pattern, String pathPrefix) throws IOException {
|
||||
return Arrays.stream(resolver.getResources(pattern))
|
||||
.map(resource -> getPath(resource).replaceFirst(pathPrefix, ""))
|
||||
.filter(name -> !name.endsWith(".class"))
|
||||
.distinct()
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingFileProtocolWithoutWildcardInPatternAndEndingInSlashStarStar() throws Exception {
|
||||
Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath();
|
||||
String pattern = String.format("file:%s/scanned-resources/**", testResourcesDir);
|
||||
String pathPrefix = ".+scanned-resources/";
|
||||
String pathPrefix = ".+?resources/";
|
||||
|
||||
// We do NOT find "scanned-resources" if the pattern ENDS with "/**" AND does NOT otherwise contain a wildcard.
|
||||
assertExactFilenames(pattern, "resource#test1.txt", "resource#test2.txt");
|
||||
assertExactSubPaths(pattern, pathPrefix, "resource#test1.txt", "resource#test2.txt");
|
||||
assertExactSubPaths(pattern, pathPrefix, "scanned-resources/resource#test1.txt",
|
||||
"scanned-resources/resource#test2.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
void usingFileProtocolWithWildcardInPatternAndEndingInSlashStarStar() throws Exception {
|
||||
Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath();
|
||||
String pattern = String.format("file:%s/scanned*resources/**", testResourcesDir);
|
||||
String pathPrefix = ".+?resources/";
|
||||
|
||||
// We DO find "scanned-resources" if the pattern ENDS with "/**" AND DOES otherwise contain a wildcard.
|
||||
assertExactFilenames(pattern, "scanned-resources", "resource#test1.txt", "resource#test2.txt");
|
||||
assertExactSubPaths(pattern, pathPrefix, "scanned-resources", "scanned-resources/resource#test1.txt",
|
||||
"scanned-resources/resource#test2.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue