From 2042cb68a55a1527d61dfc6c8a4a4c48f9342e75 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Wed, 2 Nov 2022 14:48:12 +0100 Subject: [PATCH] Merge two DispatcherHandlerIntegrationTests --- .../DispatcherHandlerIntegrationTests.java | 24 ++++- .../DispatcherHandlerIntegrationTests.java | 99 ------------------- 2 files changed, 23 insertions(+), 100 deletions(-) delete mode 100644 spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/DispatcherHandlerIntegrationTests.java diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java index e80053a0ea..2862324575 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.stereotype.Controller; @@ -44,6 +45,7 @@ import org.springframework.web.util.pattern.PathPattern; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.web.reactive.function.BodyInserters.fromPublisher; +import static org.springframework.web.reactive.function.server.RequestPredicates.accept; import static org.springframework.web.reactive.function.server.RouterFunctions.nest; import static org.springframework.web.reactive.function.server.RouterFunctions.route; @@ -122,6 +124,15 @@ class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); } + @ParameterizedHttpServerTest + void nested(HttpServer httpServer) throws Exception { + startServer(httpServer); + + ResponseEntity result = this.restTemplate + .getForEntity("http://localhost:" + this.port + "/foo/bar", String.class); + + assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); + } @EnableWebFlux @Configuration @@ -157,6 +168,17 @@ class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTe return nest(RequestPredicates.GET("/attributes"), route(RequestPredicates.GET("/{foo}"), attributesHandler::attributes)); } + + @Bean + public RouterFunction nested() { + return route() + .path("/foo", () -> route() + .nest(accept(MediaType.APPLICATION_JSON), builder -> builder + .GET("/bar", request -> ServerResponse.ok().build())) + .build()) + .build(); + } + } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/DispatcherHandlerIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/DispatcherHandlerIntegrationTests.java deleted file mode 100644 index 4b1ef6c241..0000000000 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/support/DispatcherHandlerIntegrationTests.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2002-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.reactive.function.server.support; - -import reactor.core.publisher.Mono; - -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.reactive.DispatcherHandler; -import org.springframework.web.reactive.config.EnableWebFlux; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.ServerRequest; -import org.springframework.web.reactive.function.server.ServerResponse; -import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import org.springframework.web.testfixture.http.server.reactive.bootstrap.AbstractHttpHandlerIntegrationTests; -import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.web.reactive.function.server.RequestPredicates.accept; -import static org.springframework.web.reactive.function.server.RouterFunctions.route; - -/** - * @author Arjen Poutsma - */ -class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { - - private final RestTemplate restTemplate = new RestTemplate(); - - - @Override - protected HttpHandler createHttpHandler() { - AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); - wac.register(TestConfiguration.class); - wac.refresh(); - - return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build(); - } - - - @ParameterizedHttpServerTest - void nested(HttpServer httpServer) throws Exception { - startServer(httpServer); - - ResponseEntity result = this.restTemplate - .getForEntity("http://localhost:" + this.port + "/foo/bar", String.class); - - assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - - @Configuration - @EnableWebFlux - static class TestConfiguration { - - @Bean - public RouterFunction router(Handler handler) { - return route() - .path("/foo", () -> route() - .nest(accept(MediaType.APPLICATION_JSON), builder -> builder - .GET("/bar", handler::handle)) - .build()) - .build(); - } - - @Bean - public Handler handler() { - return new Handler(); - } - } - - - static class Handler { - - public Mono handle(ServerRequest request) { - return ServerResponse.ok().build(); - } - } - -}