Skip to content

Commit 207b76c

Browse files
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
1 parent fdf4e14 commit 207b76c

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,8 @@ void handlerMappingsCreated() {
178178
void resourceHandlerMapping() {
179179
this.contextRunner.run((context) -> {
180180
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
181-
assertThat(locations.get("/**")).hasSize(5);
182-
assertThat(locations.get("/webjars/**")).hasSize(1);
183-
assertThat(locations.get("/webjars/**").get(0))
184-
.isEqualTo(new ClassPathResource("/META-INF/resources/webjars/"));
181+
assertThat(locations.get("/**")).hasSize(2);
182+
assertThat(locations.get("/webjars/**")).hasSize(0);
185183
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(1);
186184
assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(0);
187185
assertThat(getResourceResolvers(context, "/**")).hasSize(1);
@@ -193,17 +191,17 @@ void resourceHandlerMapping() {
193191
void customResourceHandlerMapping() {
194192
this.contextRunner.withPropertyValues("spring.mvc.static-path-pattern:/static/**").run((context) -> {
195193
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
196-
assertThat(locations.get("/static/**")).hasSize(5);
194+
assertThat(locations.get("/static/**")).hasSize(2);
197195
assertThat(getResourceResolvers(context, "/static/**")).hasSize(1);
198196
});
199197
}
200198

201199
@Test
202200
void resourceHandlerMappingOverrideWebjars() {
203-
this.contextRunner.withUserConfiguration(WebJars.class).run((context) -> {
201+
this.contextRunner.withUserConfiguration(WebJarsResources.class).run((context) -> {
204202
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
205203
assertThat(locations.get("/webjars/**")).hasSize(1);
206-
assertThat(locations.get("/webjars/**").get(0)).isEqualTo(new ClassPathResource("/foo/"));
204+
assertThat(locations.get("/webjars/**").get(0).getFilename()).isEqualTo("test");
207205
});
208206
}
209207

@@ -212,7 +210,7 @@ void resourceHandlerMappingOverrideAll() {
212210
this.contextRunner.withUserConfiguration(AllResources.class).run((context) -> {
213211
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
214212
assertThat(locations.get("/**")).hasSize(1);
215-
assertThat(locations.get("/**").get(0)).isEqualTo(new ClassPathResource("/foo/"));
213+
assertThat(locations.get("/**").get(0).getFilename()).isEqualTo("test");
216214
});
217215
}
218216

@@ -1097,11 +1095,11 @@ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletReq
10971095
}
10981096

10991097
@Configuration(proxyBeanMethods = false)
1100-
static class WebJars implements WebMvcConfigurer {
1098+
static class WebJarsResources implements WebMvcConfigurer {
11011099

11021100
@Override
11031101
public void addResourceHandlers(ResourceHandlerRegistry registry) {
1104-
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/foo/");
1102+
registry.addResourceHandler("/webjars/**").addResourceLocations(new ClassPathResource("/test", getClass()));
11051103
}
11061104

11071105
}
@@ -1111,7 +1109,7 @@ static class AllResources implements WebMvcConfigurer {
11111109

11121110
@Override
11131111
public void addResourceHandlers(ResourceHandlerRegistry registry) {
1114-
registry.addResourceHandler("/**").addResourceLocations("classpath:/foo/");
1112+
registry.addResourceHandler("/**").addResourceLocations(new ClassPathResource("/test", getClass()));
11151113
}
11161114

11171115
}
@@ -1519,7 +1517,7 @@ ServletRegistrationBean<?> additionalDispatcherServlet(DispatcherServlet extraDi
15191517
}
15201518

15211519
@Bean
1522-
private DispatcherServlet extraDispatcherServlet() throws ServletException {
1520+
private DispatcherServlet extraDispatcherServlet() {
15231521
DispatcherServlet dispatcherServlet = new DispatcherServlet();
15241522
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
15251523
applicationContext.register(ResourceHandlersWithChildAndParentContextChildConfiguration.class);

0 commit comments

Comments
 (0)