Search in sources :

Example 16 with PathPatternParser

use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.

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.getPatternsCondition()).isNull();
    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(org.springframework.web.util.pattern.PathPatternParser) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 17 with PathPatternParser

use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.

the class RequestMappingInfoHandlerMappingTests method pathPatternsArguments.

@SuppressWarnings("unused")
static Stream<?> pathPatternsArguments() {
    TestController controller = new TestController();
    TestRequestMappingInfoHandlerMapping mapping1 = new TestRequestMappingInfoHandlerMapping();
    mapping1.setPatternParser(new PathPatternParser());
    TestRequestMappingInfoHandlerMapping mapping2 = new TestRequestMappingInfoHandlerMapping();
    mapping2.setRemoveSemicolonContent(false);
    return Stream.of(mapping1, mapping2).peek(mapping -> {
        mapping.setApplicationContext(new StaticWebApplicationContext());
        mapping.registerHandler(controller);
        mapping.afterPropertiesSet();
    });
}
Also used : PathPatternParser(org.springframework.web.util.pattern.PathPatternParser) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext)

Example 18 with PathPatternParser

use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.

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.getPatternsCondition()).isEqualTo(info1.getPatternsCondition());
    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 : RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) PathPatternParser(org.springframework.web.util.pattern.PathPatternParser) Test(org.junit.jupiter.api.Test)

Example 19 with PathPatternParser

use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.

the class RouterFunctionMapping method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    if (this.routerFunction == null) {
        initRouterFunction();
    }
    if (CollectionUtils.isEmpty(this.messageConverters)) {
        initMessageConverters();
    }
    if (this.routerFunction != null) {
        PathPatternParser patternParser = getPatternParser();
        if (patternParser == null) {
            patternParser = new PathPatternParser();
            setPatternParser(patternParser);
        }
        RouterFunctions.changeParser(this.routerFunction, patternParser);
    }
}
Also used : PathPatternParser(org.springframework.web.util.pattern.PathPatternParser)

Example 20 with PathPatternParser

use of org.springframework.web.util.pattern.PathPatternParser in project spring-framework by spring-projects.

the class CrossOriginTests method pathPatternsArguments.

@SuppressWarnings("unused")
static Stream<TestRequestMappingInfoHandlerMapping> pathPatternsArguments() {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    Properties props = new Properties();
    props.setProperty("myOrigin", "https://example.com");
    props.setProperty("myDomainPattern", "http://*.example.com");
    wac.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("ps", props));
    wac.registerSingleton("ppc", PropertySourcesPlaceholderConfigurer.class);
    wac.refresh();
    TestRequestMappingInfoHandlerMapping mapping1 = new TestRequestMappingInfoHandlerMapping();
    mapping1.setPatternParser(new PathPatternParser());
    wac.getAutowireCapableBeanFactory().initializeBean(mapping1, "mapping1");
    TestRequestMappingInfoHandlerMapping mapping2 = new TestRequestMappingInfoHandlerMapping();
    wac.getAutowireCapableBeanFactory().initializeBean(mapping2, "mapping2");
    wac.close();
    return Stream.of(mapping1, mapping2);
}
Also used : PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) PathPatternParser(org.springframework.web.util.pattern.PathPatternParser) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) Properties(java.util.Properties)

Aggregations

PathPatternParser (org.springframework.web.util.pattern.PathPatternParser)22 Test (org.junit.jupiter.api.Test)13 RequestMappingInfo (org.springframework.web.reactive.result.method.RequestMappingInfo)4 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)3 Field (java.lang.reflect.Field)2 Collections (java.util.Collections)2 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ApplicationContext (org.springframework.context.ApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)2 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)2 PathPattern (org.springframework.web.util.pattern.PathPattern)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Tag (io.micrometer.core.instrument.Tag)1 Method (java.lang.reflect.Method)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 BiConsumer (java.util.function.BiConsumer)1