@ -27,6 +27,7 @@ import org.springframework.test.context.BootstrapTestUtils;
@@ -27,6 +27,7 @@ import org.springframework.test.context.BootstrapTestUtils;
import org.springframework.test.context.ContextConfiguration ;
import org.springframework.test.context.ContextLoader ;
import org.springframework.test.context.MergedContextConfiguration ;
import org.springframework.test.context.TestPropertySource ;
import org.springframework.test.context.web.WebDelegatingSmartContextLoader ;
import org.springframework.test.context.web.WebMergedContextConfiguration ;
@ -194,6 +195,29 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
@@ -194,6 +195,29 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
AnnotationConfigContextLoader . class ) ;
}
@Test
void buildMergedConfigAndVerifyLocationPathsAreCleanedEquivalently ( ) {
assertMergedConfigForLocationPaths ( AbsoluteFooXmlLocationWithoutClasspathPrefix . class ) ;
assertMergedConfigForLocationPaths ( AbsoluteFooXmlLocationWithInnerRelativePathWithoutClasspathPrefix . class ) ;
assertMergedConfigForLocationPaths ( AbsoluteFooXmlLocationWithClasspathPrefix . class ) ;
assertMergedConfigForLocationPaths ( RelativeFooXmlLocation . class ) ;
}
private void assertMergedConfigForLocationPaths ( Class < ? > testClass ) {
MergedContextConfiguration mergedConfig = buildMergedContextConfiguration ( testClass ) ;
assertThat ( mergedConfig ) . isNotNull ( ) ;
assertThat ( mergedConfig . getTestClass ( ) ) . isEqualTo ( testClass ) ;
assertThat ( mergedConfig . getContextLoader ( ) ) . isInstanceOf ( DelegatingSmartContextLoader . class ) ;
assertThat ( mergedConfig . getLocations ( ) ) . containsExactly ( "classpath:/example/foo.xml" ) ;
assertThat ( mergedConfig . getPropertySourceLocations ( ) ) . containsExactly ( "classpath:/example/foo.properties" ) ;
assertThat ( mergedConfig . getClasses ( ) ) . isEmpty ( ) ;
assertThat ( mergedConfig . getActiveProfiles ( ) ) . isEmpty ( ) ;
assertThat ( mergedConfig . getContextInitializerClasses ( ) ) . isEmpty ( ) ;
assertThat ( mergedConfig . getPropertySourceProperties ( ) ) . isEmpty ( ) ;
}
@ContextConfiguration
@Retention ( RetentionPolicy . RUNTIME )
@ -217,4 +241,25 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
@@ -217,4 +241,25 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
static class MissingContextAttributesTestCase {
}
@ContextConfiguration ( locations = "/example/foo.xml" )
@TestPropertySource ( "/example/foo.properties" )
static class AbsoluteFooXmlLocationWithoutClasspathPrefix {
}
@ContextConfiguration ( locations = "/example/../org/../example/foo.xml" )
@TestPropertySource ( "/example/../org/../example/foo.properties" )
static class AbsoluteFooXmlLocationWithInnerRelativePathWithoutClasspathPrefix {
}
@ContextConfiguration ( locations = "classpath:/example/foo.xml" )
@TestPropertySource ( "classpath:/example/foo.properties" )
static class AbsoluteFooXmlLocationWithClasspathPrefix {
}
// org.springframework.test.context.support --> 5 levels up to the root of the classpath
@ContextConfiguration ( locations = "../../../../../example/foo.xml" )
@TestPropertySource ( "../../../../../example/foo.properties" )
static class RelativeFooXmlLocation {
}
}