use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.
the class RouterFunctionMappingTests method changeParser.
@Test
void changeParser() throws Exception {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route().GET("/foo", handlerFunction).POST("/bar", handlerFunction).build();
RouterFunctionMapping mapping = new RouterFunctionMapping(routerFunction);
mapping.setMessageConverters(this.messageConverters);
PathPatternParser patternParser = new PathPatternParser();
patternParser.setCaseSensitive(false);
mapping.setPatternParser(patternParser);
mapping.afterPropertiesSet();
MockHttpServletRequest request = createTestRequest("/FOO");
HandlerExecutionChain result = mapping.getHandler(request);
assertThat(result).isNotNull();
assertThat(result.getHandler()).isSameAs(handlerFunction);
}
use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.
the class DelegatingWebMvcConfigurationTests method configurePathPatternParser.
@Test
public void configurePathPatternParser() {
PathPatternParser patternParser = new PathPatternParser();
PathMatcher pathMatcher = mock(PathMatcher.class);
UrlPathHelper pathHelper = mock(UrlPathHelper.class);
WebMvcConfigurer configurer = new WebMvcConfigurer() {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setPatternParser(patternParser).setUrlPathHelper(pathHelper).setPathMatcher(pathMatcher);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("home");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/");
}
};
MockServletContext servletContext = new MockServletContext();
webMvcConfig.setConfigurers(Collections.singletonList(configurer));
webMvcConfig.setServletContext(servletContext);
webMvcConfig.setApplicationContext(new GenericWebApplicationContext(servletContext));
BiConsumer<UrlPathHelper, PathMatcher> configAssertion = (helper, matcher) -> {
assertThat(helper).isNotSameAs(pathHelper);
assertThat(matcher).isNotSameAs(pathMatcher);
};
RequestMappingHandlerMapping annotationsMapping = webMvcConfig.requestMappingHandlerMapping(webMvcConfig.mvcContentNegotiationManager(), webMvcConfig.mvcConversionService(), webMvcConfig.mvcResourceUrlProvider());
assertThat(annotationsMapping).isNotNull();
assertThat(annotationsMapping.getPatternParser()).isSameAs(patternParser).isSameAs(webMvcConfig.mvcPatternParser());
configAssertion.accept(annotationsMapping.getUrlPathHelper(), annotationsMapping.getPathMatcher());
SimpleUrlHandlerMapping mapping = (SimpleUrlHandlerMapping) webMvcConfig.viewControllerHandlerMapping(webMvcConfig.mvcConversionService(), webMvcConfig.mvcResourceUrlProvider());
assertThat(mapping).isNotNull();
assertThat(mapping.getPatternParser()).isSameAs(patternParser);
configAssertion.accept(mapping.getUrlPathHelper(), mapping.getPathMatcher());
mapping = (SimpleUrlHandlerMapping) webMvcConfig.resourceHandlerMapping(webMvcConfig.mvcContentNegotiationManager(), webMvcConfig.mvcConversionService(), webMvcConfig.mvcResourceUrlProvider());
assertThat(mapping).isNotNull();
assertThat(mapping.getPatternParser()).isSameAs(patternParser);
configAssertion.accept(mapping.getUrlPathHelper(), mapping.getPathMatcher());
BeanNameUrlHandlerMapping beanNameMapping = webMvcConfig.beanNameHandlerMapping(webMvcConfig.mvcConversionService(), webMvcConfig.mvcResourceUrlProvider());
assertThat(beanNameMapping).isNotNull();
assertThat(beanNameMapping.getPatternParser()).isSameAs(patternParser);
configAssertion.accept(beanNameMapping.getUrlPathHelper(), beanNameMapping.getPathMatcher());
assertThat(webMvcConfig.mvcResourceUrlProvider().getUrlPathHelper()).isSameAs(pathHelper);
assertThat(webMvcConfig.mvcResourceUrlProvider().getPathMatcher()).isSameAs(pathMatcher);
}
Aggregations