Merge pull request #10381 from sampada07/JAVA-3527

JAVA-4166: Fix test in spring-5-reactive
This commit is contained in:
Loredana Crusoveanu 2021-01-04 10:25:35 +02:00 committed by GitHub
commit d2c45e04c6
2 changed files with 4 additions and 4 deletions

View File

@ -3,7 +3,7 @@ package com.baeldung.functional;
import static org.springframework.web.reactive.function.BodyInserters.fromObject; import static org.springframework.web.reactive.function.BodyInserters.fromObject;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET; 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.RequestPredicates.POST;
import static org.springframework.web.reactive.function.server.RequestPredicates.path; import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
import static org.springframework.web.reactive.function.server.RouterFunctions.route; import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler; import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler;
import static org.springframework.web.reactive.function.server.ServerResponse.ok; import static org.springframework.web.reactive.function.server.ServerResponse.ok;
@ -18,6 +18,7 @@ import org.apache.catalina.startup.Tomcat;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.WebServer;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ServletHttpHandlerAdapter; import org.springframework.http.server.reactive.ServletHttpHandlerAdapter;
import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunction;
@ -37,14 +38,14 @@ public class FunctionalWebApplication {
private RouterFunction<ServerResponse> routingFunction() { private RouterFunction<ServerResponse> routingFunction() {
FormHandler formHandler = new FormHandler(); FormHandler formHandler = new FormHandler();
RouterFunction<ServerResponse> restfulRouter = route(GET("/"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/"), serverRequest -> serverRequest.bodyToMono(Actor.class) RouterFunction<ServerResponse> restfulRouter = route(GET("/actor"), serverRequest -> ok().body(Flux.fromIterable(actors), Actor.class)).andRoute(POST("/actor"), serverRequest -> serverRequest.bodyToMono(Actor.class)
.doOnNext(actors::add) .doOnNext(actors::add)
.then(ok().build())); .then(ok().build()));
return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin) return route(GET("/test"), serverRequest -> ok().body(fromObject("helloworld"))).andRoute(POST("/login"), formHandler::handleLogin)
.andRoute(POST("/upload"), formHandler::handleUpload) .andRoute(POST("/upload"), formHandler::handleUpload)
.and(RouterFunctions.resources("/files/**", new ClassPathResource("files/"))) .and(RouterFunctions.resources("/files/**", new ClassPathResource("files/")))
.andNest(path("/actor"), restfulRouter) .andNest(accept(MediaType.APPLICATION_JSON), restfulRouter)
.filter((request, next) -> { .filter((request, next) -> {
System.out.println("Before handler invocation: " + request.path()); System.out.println("Before handler invocation: " + request.path());
return next.handle(request); return next.handle(request);

View File

@ -103,7 +103,6 @@ public class FunctionalWebApplicationIntegrationTest {
.isEqualTo(String.valueOf(resource.contentLength())); .isEqualTo(String.valueOf(resource.contentLength()));
} }
@Ignore("We get 404 after Spring Boot 2.4 upgrade. We need to solve it in a new task.")
@Test @Test
public void givenActors_whenAddActor_thenAdded() throws Exception { public void givenActors_whenAddActor_thenAdded() throws Exception {
client.get() client.get()