|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
|
* 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. |
|
|
|
@ -30,6 +30,7 @@ import org.springframework.http.HttpStatus;
@@ -30,6 +30,7 @@ import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
import static org.springframework.web.reactive.function.server.RequestPredicates.HEAD; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author Arjen Poutsma |
|
|
|
@ -41,16 +42,16 @@ public class RouterFunctionBuilderTests {
@@ -41,16 +42,16 @@ public class RouterFunctionBuilderTests {
|
|
|
|
|
RouterFunction<ServerResponse> route = RouterFunctions.route() |
|
|
|
|
.GET("/foo", request -> ServerResponse.ok().build()) |
|
|
|
|
.POST("/", RequestPredicates.contentType(MediaType.TEXT_PLAIN), request -> ServerResponse.noContent().build()) |
|
|
|
|
.route(HEAD("/foo"), request -> ServerResponse.accepted().build()) |
|
|
|
|
.build(); |
|
|
|
|
System.out.println(route); |
|
|
|
|
|
|
|
|
|
MockServerRequest fooRequest = MockServerRequest.builder(). |
|
|
|
|
MockServerRequest getFooRequest = MockServerRequest.builder(). |
|
|
|
|
method(HttpMethod.GET). |
|
|
|
|
uri(URI.create("http://localhost/foo")) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
Mono<Integer> responseMono = route.route(fooRequest) |
|
|
|
|
.flatMap(handlerFunction -> handlerFunction.handle(fooRequest)) |
|
|
|
|
Mono<Integer> responseMono = route.route(getFooRequest) |
|
|
|
|
.flatMap(handlerFunction -> handlerFunction.handle(getFooRequest)) |
|
|
|
|
.map(ServerResponse::statusCode) |
|
|
|
|
.map(HttpStatus::value); |
|
|
|
|
|
|
|
|
@ -58,6 +59,20 @@ public class RouterFunctionBuilderTests {
@@ -58,6 +59,20 @@ public class RouterFunctionBuilderTests {
|
|
|
|
|
.expectNext(200) |
|
|
|
|
.verifyComplete(); |
|
|
|
|
|
|
|
|
|
MockServerRequest headFooRequest = MockServerRequest.builder(). |
|
|
|
|
method(HttpMethod.HEAD). |
|
|
|
|
uri(URI.create("http://localhost/foo")) |
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
responseMono = route.route(headFooRequest) |
|
|
|
|
.flatMap(handlerFunction -> handlerFunction.handle(getFooRequest)) |
|
|
|
|
.map(ServerResponse::statusCode) |
|
|
|
|
.map(HttpStatus::value); |
|
|
|
|
|
|
|
|
|
StepVerifier.create(responseMono) |
|
|
|
|
.expectNext(202) |
|
|
|
|
.verifyComplete(); |
|
|
|
|
|
|
|
|
|
MockServerRequest barRequest = MockServerRequest.builder(). |
|
|
|
|
method(HttpMethod.POST). |
|
|
|
|
uri(URI.create("http://localhost/")) |
|
|
|
|