Search in sources :

Example 1 with PathPatternParser

use of cn.taketoday.web.util.pattern.PathPatternParser in project today-infrastructure by TAKETODAY.

the class RequestMappingInfoTests method mutate.

@Test
void mutate() {
    RequestMappingInfo.BuilderConfiguration options = new RequestMappingInfo.BuilderConfiguration();
    options.setPatternParser(new PathPatternParser());
    RequestMappingInfo info1 = RequestMappingInfo.paths("/foo").methods(GET).headers("h1=hv1").params("q1=qv1").consumes("application/json").produces("application/json").mappingName("testMapping").options(options).build();
    RequestMappingInfo info2 = info1.mutate().produces("application/hal+json").build();
    assertThat(info2.getName()).isEqualTo(info1.getName());
    assertThat(info2.getPathPatternsCondition()).isEqualTo(info1.getPathPatternsCondition());
    assertThat(info2.getHeadersCondition()).isEqualTo(info1.getHeadersCondition());
    assertThat(info2.getParamsCondition()).isEqualTo(info1.getParamsCondition());
    assertThat(info2.getConsumesCondition()).isEqualTo(info1.getConsumesCondition());
    assertThat(info2.getProducesCondition().getProducibleMediaTypes()).containsOnly(MediaType.parseMediaType("application/hal+json"));
}
Also used : PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) Test(org.junit.jupiter.api.Test) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 2 with PathPatternParser

use of cn.taketoday.web.util.pattern.PathPatternParser in project today-infrastructure by TAKETODAY.

the class PathPatternsRequestConditionTests method matchTrailingSlash.

@Test
void matchTrailingSlash() {
    MockHttpServletRequest request = createRequest("/foo/");
    PathPatternsRequestCondition condition = createCondition("/foo");
    PathPatternsRequestCondition match = condition.getMatchingCondition(new ServletRequestContext(null, request, null));
    assertThat(match).isNotNull();
    assertThat(match.getPatternValues().iterator().next()).as("Should match by default").isEqualTo("/foo");
    PathPatternParser strictParser = new PathPatternParser();
    strictParser.setMatchOptionalTrailingSeparator(false);
    condition = new PathPatternsRequestCondition(strictParser, "/foo");
    match = condition.getMatchingCondition(new ServletRequestContext(null, request, null));
    assertThat(match).isNull();
}
Also used : MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test)

Example 3 with PathPatternParser

use of cn.taketoday.web.util.pattern.PathPatternParser in project today-framework by TAKETODAY.

the class RequestMappingInfoTests method mutate.

@Test
void mutate() {
    RequestMappingInfo.BuilderConfiguration options = new RequestMappingInfo.BuilderConfiguration();
    options.setPatternParser(new PathPatternParser());
    RequestMappingInfo info1 = RequestMappingInfo.paths("/foo").methods(GET).headers("h1=hv1").params("q1=qv1").consumes("application/json").produces("application/json").mappingName("testMapping").options(options).build();
    RequestMappingInfo info2 = info1.mutate().produces("application/hal+json").build();
    assertThat(info2.getName()).isEqualTo(info1.getName());
    assertThat(info2.getPathPatternsCondition()).isEqualTo(info1.getPathPatternsCondition());
    assertThat(info2.getHeadersCondition()).isEqualTo(info1.getHeadersCondition());
    assertThat(info2.getParamsCondition()).isEqualTo(info1.getParamsCondition());
    assertThat(info2.getConsumesCondition()).isEqualTo(info1.getConsumesCondition());
    assertThat(info2.getProducesCondition().getProducibleMediaTypes()).containsOnly(MediaType.parseMediaType("application/hal+json"));
}
Also used : PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) Test(org.junit.jupiter.api.Test) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 4 with PathPatternParser

use of cn.taketoday.web.util.pattern.PathPatternParser in project today-framework by TAKETODAY.

the class PathPatternsRequestConditionTests method matchTrailingSlash.

@Test
void matchTrailingSlash() {
    MockHttpServletRequest request = createRequest("/foo/");
    PathPatternsRequestCondition condition = createCondition("/foo");
    PathPatternsRequestCondition match = condition.getMatchingCondition(new ServletRequestContext(null, request, null));
    assertThat(match).isNotNull();
    assertThat(match.getPatternValues().iterator().next()).as("Should match by default").isEqualTo("/foo");
    PathPatternParser strictParser = new PathPatternParser();
    strictParser.setMatchOptionalTrailingSeparator(false);
    condition = new PathPatternsRequestCondition(strictParser, "/foo");
    match = condition.getMatchingCondition(new ServletRequestContext(null, request, null));
    assertThat(match).isNull();
}
Also used : MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test)

Example 5 with PathPatternParser

use of cn.taketoday.web.util.pattern.PathPatternParser in project today-framework by TAKETODAY.

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());
}
Also used : PathPatternParser(cn.taketoday.web.util.pattern.PathPatternParser)

Aggregations

PathPatternParser (cn.taketoday.web.util.pattern.PathPatternParser)7 Test (org.junit.jupiter.api.Test)4 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)2 PathPatternsParameterizedTest (cn.taketoday.web.view.PathPatternsParameterizedTest)2 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)1 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)1