use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.
the class RequestPredicatesTests method pathPredicates.
@Test
public void pathPredicates() {
PathPatternParser parser = new PathPatternParser();
parser.setCaseSensitive(false);
Function<String, RequestPredicate> pathPredicates = RequestPredicates.pathPredicates(parser);
RequestPredicate predicate = pathPredicates.apply("/P*");
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com/path").build();
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
assertThat(predicate.test(request)).isTrue();
}
use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.
the class RequestMappingInfoTests method pathPatternsArguments.
@SuppressWarnings("unused")
static Stream<RequestMappingInfo.Builder> pathPatternsArguments() {
RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration();
config.setPatternParser(new PathPatternParser());
return Stream.of(RequestMappingInfo.paths().options(config), RequestMappingInfo.paths());
}
use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.
the class RequestPredicatesTests method pathPredicates.
@Test
void pathPredicates() {
PathPatternParser parser = new PathPatternParser();
parser.setCaseSensitive(false);
Function<String, RequestPredicate> pathPredicates = RequestPredicates.pathPredicates(parser);
RequestPredicate predicate = pathPredicates.apply("/P*");
assertThat(predicate.test(initRequest("GET", "/path"))).isTrue();
}
use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.
the class RequestMappingInfoTests method createEmpty.
// TODO: CORS pre-flight (see @Disabled)
@Test
public void createEmpty() {
RequestMappingInfo info = paths().build();
PathPattern emptyPattern = (new PathPatternParser()).parse("");
assertThat(info.getPatternsCondition().getPatterns()).isEqualTo(Collections.singleton(emptyPattern));
assertThat(info.getMethodsCondition().getMethods().size()).isEqualTo(0);
assertThat(info.getConsumesCondition().isEmpty()).isTrue();
assertThat(info.getProducesCondition().isEmpty()).isTrue();
assertThat(info.getParamsCondition()).isNotNull();
assertThat(info.getHeadersCondition()).isNotNull();
assertThat(info.getCustomCondition()).isNull();
RequestMappingInfo anotherInfo = paths().build();
assertThat(info.getPatternsCondition()).isSameAs(anotherInfo.getPatternsCondition());
assertThat(info.getMethodsCondition()).isSameAs(anotherInfo.getMethodsCondition());
assertThat(info.getParamsCondition()).isSameAs(anotherInfo.getParamsCondition());
assertThat(info.getHeadersCondition()).isSameAs(anotherInfo.getHeadersCondition());
assertThat(info.getConsumesCondition()).isSameAs(anotherInfo.getConsumesCondition());
assertThat(info.getProducesCondition()).isSameAs(anotherInfo.getProducesCondition());
assertThat(info.getCustomCondition()).isSameAs(anotherInfo.getCustomCondition());
RequestMappingInfo result = info.combine(anotherInfo);
assertThat(info.getPatternsCondition()).isSameAs(result.getPatternsCondition());
assertThat(info.getMethodsCondition()).isSameAs(result.getMethodsCondition());
assertThat(info.getParamsCondition()).isSameAs(result.getParamsCondition());
assertThat(info.getHeadersCondition()).isSameAs(result.getHeadersCondition());
assertThat(info.getConsumesCondition()).isSameAs(result.getConsumesCondition());
assertThat(info.getProducesCondition()).isSameAs(result.getProducesCondition());
assertThat(info.getCustomCondition()).isSameAs(result.getCustomCondition());
}
use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.
the class PatternsRequestConditionTests method matchTrailingSlash.
@Test
public void matchTrailingSlash() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/"));
PatternsRequestCondition condition = createPatternsCondition("/foo");
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
assertThat(match).isNotNull();
assertThat(match.getPatterns().iterator().next().getPatternString()).as("Should match by default").isEqualTo("/foo");
condition = createPatternsCondition("/foo");
match = condition.getMatchingCondition(exchange);
assertThat(match).isNotNull();
assertThat(match.getPatterns().iterator().next().getPatternString()).as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)").isEqualTo("/foo");
PathPatternParser parser = new PathPatternParser();
parser.setMatchOptionalTrailingSeparator(false);
condition = new PatternsRequestCondition(parser.parse("/foo"));
match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/")));
assertThat(match).isNull();
}
Aggregations