|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
56 | 56 | import org.springframework.web.reactive.function.server.ServerResponse;
|
57 | 57 | import org.springframework.web.servlet.DispatcherServlet;
|
58 | 58 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
| 59 | +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; |
| 60 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| 61 | +import org.springframework.web.util.pattern.PathPatternParser; |
59 | 62 |
|
60 | 63 | import static org.assertj.core.api.Assertions.assertThat;
|
61 | 64 | import static org.mockito.BDDMockito.given;
|
@@ -94,6 +97,28 @@ void servletWebMappings() {
|
94 | 97 | });
|
95 | 98 | }
|
96 | 99 |
|
| 100 | + @Test |
| 101 | + void servletWebMappingsWithPathPatternParser() { |
| 102 | + Supplier<ConfigurableWebApplicationContext> contextSupplier = prepareContextSupplier(); |
| 103 | + new WebApplicationContextRunner(contextSupplier).withUserConfiguration(EndpointConfiguration.class, |
| 104 | + ServletWebConfiguration.class, PathPatternParserConfiguration.class).run((context) -> { |
| 105 | + ContextMappings contextMappings = contextMappings(context); |
| 106 | + assertThat(contextMappings.getParentId()).isNull(); |
| 107 | + assertThat(contextMappings.getMappings()).containsOnlyKeys("dispatcherServlets", "servletFilters", |
| 108 | + "servlets"); |
| 109 | + Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings( |
| 110 | + contextMappings, "dispatcherServlets"); |
| 111 | + assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet"); |
| 112 | + List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets |
| 113 | + .get("dispatcherServlet"); |
| 114 | + assertThat(handlerMappings).hasSize(1); |
| 115 | + List<ServletRegistrationMappingDescription> servlets = mappings(contextMappings, "servlets"); |
| 116 | + assertThat(servlets).hasSize(1); |
| 117 | + List<FilterRegistrationMappingDescription> filters = mappings(contextMappings, "servletFilters"); |
| 118 | + assertThat(filters).hasSize(1); |
| 119 | + }); |
| 120 | + } |
| 121 | + |
97 | 122 | @Test
|
98 | 123 | void servletWebMappingsWithAdditionalDispatcherServlets() {
|
99 | 124 | Supplier<ConfigurableWebApplicationContext> contextSupplier = prepareContextSupplier();
|
@@ -260,4 +285,21 @@ private DispatcherServlet createTestDispatcherServlet(WebApplicationContext cont
|
260 | 285 |
|
261 | 286 | }
|
262 | 287 |
|
| 288 | + @Configuration |
| 289 | + static class PathPatternParserConfiguration { |
| 290 | + |
| 291 | + @Bean |
| 292 | + WebMvcConfigurer pathPatternParserConfigurer() { |
| 293 | + return new WebMvcConfigurer() { |
| 294 | + |
| 295 | + @Override |
| 296 | + public void configurePathMatch(PathMatchConfigurer configurer) { |
| 297 | + configurer.setPatternParser(new PathPatternParser()); |
| 298 | + } |
| 299 | + |
| 300 | + }; |
| 301 | + } |
| 302 | + |
| 303 | + } |
| 304 | + |
263 | 305 | }
|
0 commit comments