From 571c50e43f9db092fb7fc5aa0be368a935e24dab Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 4 Jun 2018 17:27:34 -0700 Subject: [PATCH] Switch to functional web code to use static imports Update the samples and tests to use the more idiomatic static import style. --- .../MappingsEndpointReactiveDocumentationTests.java | 7 +++---- .../reactive/HttpTraceWebFilterIntegrationTests.java | 11 +++++------ .../actuate/web/mappings/MappingsEndpointTests.java | 12 +++++------- .../error/DefaultErrorWebExceptionHandler.java | 9 +++++---- .../reactive/HttpHandlerAutoConfigurationTests.java | 7 +++---- .../webflux/SampleSecureWebFluxApplication.java | 7 ++++--- .../sample/webflux/SampleWebFluxApplication.java | 7 ++++--- 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java index 26b32e4e95..003a171297 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java @@ -45,9 +45,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import static org.springframework.restdocs.payload.PayloadDocumentation.beneathPath; @@ -55,6 +53,8 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWit import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document; import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.documentationConfiguration; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; /** * Tests for generating documentation describing {@link MappingsEndpoint}. @@ -191,8 +191,7 @@ public class MappingsEndpointReactiveDocumentationTests @Bean public RouterFunction exampleRouter() { - return RouterFunctions.route(RequestPredicates.GET("/foo"), - (request) -> ServerResponse.ok().build()); + return route(GET("/foo"), (request) -> ServerResponse.ok().build()); } @Bean diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterIntegrationTests.java index 40606c747e..8e5f9efdf0 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterIntegrationTests.java @@ -36,13 +36,13 @@ import org.springframework.http.server.reactive.HttpHandler; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.function.server.HandlerFunction; -import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; /** * Integration tests for {@link HttpTraceWebFilter}. @@ -115,10 +115,9 @@ public class HttpTraceWebFilterIntegrationTests { @Bean public RouterFunction router() { - return RouterFunctions - .route(RequestPredicates.GET("/mono-error"), - (request) -> Mono.error(new RuntimeException())) - .andRoute(RequestPredicates.GET("/thrown"), + return route(GET("/mono-error"), + (request) -> Mono.error(new RuntimeException())).andRoute( + GET("/thrown"), (HandlerFunction) (request) -> { throw new RuntimeException(); }); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java index 59496fdfed..7a92d9ebcd 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java @@ -51,9 +51,7 @@ import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.reactive.config.EnableWebFlux; -import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -61,6 +59,9 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RequestPredicates.POST; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; /** * Tests for {@link MappingsEndpoint}. @@ -166,11 +167,8 @@ public class MappingsEndpointTests { @Bean public RouterFunction routerFunction() { - return RouterFunctions - .route(RequestPredicates.GET("/one"), - (request) -> ServerResponse.ok().build()) - .andRoute(RequestPredicates.POST("/two"), - (request) -> ServerResponse.ok().build()); + return route(GET("/one"), (request) -> ServerResponse.ok().build()) + .andRoute(POST("/two"), (request) -> ServerResponse.ok().build()); } @RequestMapping("/three") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java index c1b217e10e..8a59cb0e4c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java @@ -35,13 +35,14 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.server.RequestPredicate; -import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; import org.springframework.web.server.ResponseStatusException; +import static org.springframework.web.reactive.function.server.RequestPredicates.all; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; + /** * Basic global {@link org.springframework.web.server.WebExceptionHandler}, rendering * {@link ErrorAttributes}. @@ -106,8 +107,8 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa @Override protected RouterFunction getRoutingFunction( ErrorAttributes errorAttributes) { - return RouterFunctions.route(acceptsTextHtml(), this::renderErrorView) - .andRoute(RequestPredicates.all(), this::renderErrorResponse); + return route(acceptsTextHtml(), this::renderErrorView).andRoute(all(), + this::renderErrorResponse); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java index 3453241d8c..bbd370f89f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java @@ -23,12 +23,12 @@ import org.springframework.boot.test.context.runner.ReactiveWebApplicationContex import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; /** * Tests for {@link HttpHandlerAutoConfiguration}. @@ -69,8 +69,7 @@ public class HttpHandlerAutoConfigurationTests { @Bean public RouterFunction routerFunction() { - return RouterFunctions.route(RequestPredicates.GET("/test"), - (serverRequest) -> null); + return route(GET("/test"), (serverRequest) -> null); } } diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/SampleSecureWebFluxApplication.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/SampleSecureWebFluxApplication.java index dfd07c1bc8..dfb0c01d0d 100644 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/SampleSecureWebFluxApplication.java +++ b/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/SampleSecureWebFluxApplication.java @@ -19,11 +19,12 @@ package sample.secure.webflux; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; +import static org.springframework.web.reactive.function.server.RequestPredicates.POST; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; + @SpringBootApplication public class SampleSecureWebFluxApplication { @@ -33,7 +34,7 @@ public class SampleSecureWebFluxApplication { @Bean public RouterFunction monoRouterFunction(EchoHandler echoHandler) { - return RouterFunctions.route(RequestPredicates.POST("/echo"), echoHandler::echo); + return route(POST("/echo"), echoHandler::echo); } } diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java index 701bdfeaed..05085b0758 100644 --- a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java +++ b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java @@ -19,11 +19,12 @@ package sample.webflux; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; +import static org.springframework.web.reactive.function.server.RequestPredicates.POST; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; + @SpringBootApplication public class SampleWebFluxApplication { @@ -33,7 +34,7 @@ public class SampleWebFluxApplication { @Bean public RouterFunction monoRouterFunction(EchoHandler echoHandler) { - return RouterFunctions.route(RequestPredicates.POST("/echo"), echoHandler::echo); + return route(POST("/echo"), echoHandler::echo); } }