Merge branch '2.1.x'
Closes gh-17220
This commit is contained in:
@@ -72,6 +72,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Andy Wilkinson
|
||||
* @author Brian Clozel
|
||||
* @author Madhura Bhave
|
||||
* @author Lorenzo Dee
|
||||
* @since 1.4.0
|
||||
* @see SpringBootTest
|
||||
* @see TestConfiguration
|
||||
@@ -154,10 +155,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
|
||||
WebApplicationType webApplicationType = getWebApplicationType(mergedConfig);
|
||||
if (webApplicationType == WebApplicationType.SERVLET
|
||||
&& (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
|
||||
String resourceBasePath = MergedAnnotations.from(mergedConfig.getTestClass(), SearchStrategy.EXHAUSTIVE)
|
||||
.get(WebAppConfiguration.class).getValue(MergedAnnotation.VALUE, String.class)
|
||||
.orElse("src/main/webapp");
|
||||
mergedConfig = new WebMergedContextConfiguration(mergedConfig, resourceBasePath);
|
||||
mergedConfig = new WebMergedContextConfiguration(mergedConfig, determineResourceBasePath(mergedConfig));
|
||||
}
|
||||
else if (webApplicationType == WebApplicationType.REACTIVE
|
||||
&& (webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
|
||||
@@ -189,6 +187,20 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
|
||||
return WebApplicationType.SERVLET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the resource base path for web applications using the value of
|
||||
* {@link WebAppConfiguration @WebAppConfiguration}, if any, on the test class of the
|
||||
* given {@code configuration}. Defaults to {@code src/main/webapp} in its absence.
|
||||
* @param configuration the configure to examine
|
||||
* @return the resource base path
|
||||
* @since 2.1.6
|
||||
*/
|
||||
protected String determineResourceBasePath(MergedContextConfiguration configuration) {
|
||||
return MergedAnnotations.from(configuration.getTestClass(), SearchStrategy.EXHAUSTIVE)
|
||||
.get(WebAppConfiguration.class).getValue(MergedAnnotation.VALUE, String.class)
|
||||
.orElse("src/main/webapp");
|
||||
}
|
||||
|
||||
private boolean isWebEnvironmentSupported(MergedContextConfiguration mergedConfig) {
|
||||
Class<?> testClass = mergedConfig.getTestClass();
|
||||
ContextHierarchy hierarchy = AnnotationUtils.getAnnotation(testClass, ContextHierarchy.class);
|
||||
|
||||
Reference in New Issue
Block a user