mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Modify tests to expect filtering of static resource locations
Spring Framework will filter non-existent locations from any configured static resource handlers starting with 5.3.11. Tests that verify static resource locations should account for this change. See gh-28223
This commit is contained in:
parent
fdf4e14f54
commit
207b76c39e
@ -178,10 +178,8 @@ class WebMvcAutoConfigurationTests {
|
||||
void resourceHandlerMapping() {
|
||||
this.contextRunner.run((context) -> {
|
||||
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
|
||||
assertThat(locations.get("/**")).hasSize(5);
|
||||
assertThat(locations.get("/webjars/**")).hasSize(1);
|
||||
assertThat(locations.get("/webjars/**").get(0))
|
||||
.isEqualTo(new ClassPathResource("/META-INF/resources/webjars/"));
|
||||
assertThat(locations.get("/**")).hasSize(2);
|
||||
assertThat(locations.get("/webjars/**")).hasSize(0);
|
||||
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(1);
|
||||
assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(0);
|
||||
assertThat(getResourceResolvers(context, "/**")).hasSize(1);
|
||||
@ -193,17 +191,17 @@ class WebMvcAutoConfigurationTests {
|
||||
void customResourceHandlerMapping() {
|
||||
this.contextRunner.withPropertyValues("spring.mvc.static-path-pattern:/static/**").run((context) -> {
|
||||
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
|
||||
assertThat(locations.get("/static/**")).hasSize(5);
|
||||
assertThat(locations.get("/static/**")).hasSize(2);
|
||||
assertThat(getResourceResolvers(context, "/static/**")).hasSize(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceHandlerMappingOverrideWebjars() {
|
||||
this.contextRunner.withUserConfiguration(WebJars.class).run((context) -> {
|
||||
this.contextRunner.withUserConfiguration(WebJarsResources.class).run((context) -> {
|
||||
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
|
||||
assertThat(locations.get("/webjars/**")).hasSize(1);
|
||||
assertThat(locations.get("/webjars/**").get(0)).isEqualTo(new ClassPathResource("/foo/"));
|
||||
assertThat(locations.get("/webjars/**").get(0).getFilename()).isEqualTo("test");
|
||||
});
|
||||
}
|
||||
|
||||
@ -212,7 +210,7 @@ class WebMvcAutoConfigurationTests {
|
||||
this.contextRunner.withUserConfiguration(AllResources.class).run((context) -> {
|
||||
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
|
||||
assertThat(locations.get("/**")).hasSize(1);
|
||||
assertThat(locations.get("/**").get(0)).isEqualTo(new ClassPathResource("/foo/"));
|
||||
assertThat(locations.get("/**").get(0).getFilename()).isEqualTo("test");
|
||||
});
|
||||
}
|
||||
|
||||
@ -1097,11 +1095,11 @@ class WebMvcAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class WebJars implements WebMvcConfigurer {
|
||||
static class WebJarsResources implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/foo/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations(new ClassPathResource("/test", getClass()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1111,7 +1109,7 @@ class WebMvcAutoConfigurationTests {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/**").addResourceLocations("classpath:/foo/");
|
||||
registry.addResourceHandler("/**").addResourceLocations(new ClassPathResource("/test", getClass()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1519,7 +1517,7 @@ class WebMvcAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
private DispatcherServlet extraDispatcherServlet() throws ServletException {
|
||||
private DispatcherServlet extraDispatcherServlet() {
|
||||
DispatcherServlet dispatcherServlet = new DispatcherServlet();
|
||||
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
|
||||
applicationContext.register(ResourceHandlersWithChildAndParentContextChildConfiguration.class);
|
||||
|
Loading…
Reference in New Issue
Block a user