BAEL-878 [2] (#2194)

* code snippets for the `Java 9 Stream API improvements` article

* code snippets for the `Java 9 Stream API improvements` article [2 attempt]

* removed the first attempt

* the Spring 5 WebClient

* delted stream features test

* HttpMediaTypeNotAcceptableExceptionExampleController [0]

* reactive web client service was removed

* new WebClient

* new WebClient [2]
This commit is contained in:
Andrew
2017-07-03 09:35:38 +03:00
committed by Grzegorz Piwowarek
parent ad5696a8b5
commit 806c17b41b
3 changed files with 149 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package com.baeldung.web.client;
import com.baeldung.Spring5Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
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.WebHandler;
import reactor.core.publisher.Mono;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WebTestClientTest {
@LocalServerPort
private int port;
private final RouterFunction ROUTER_FUNCTION = RouterFunctions.route(
RequestPredicates.GET("/resource"),
request -> ServerResponse.ok().build()
);
private final WebHandler WEB_HANDLER = exchange -> Mono.empty();
@Test
public void testWebTestClientWithServerWebHandler() {
WebTestClient.bindToWebHandler(WEB_HANDLER).build();
}
@Test
public void testWebTestClientWithRouterFunction() {
WebTestClient
.bindToRouterFunction(ROUTER_FUNCTION)
.build().get().uri("/resource")
.exchange()
.expectStatus().isOk()
.expectBody().isEmpty();
}
@Test
public void testWebTestClientWithServerURL() {
WebTestClient
.bindToServer()
.baseUrl("http://localhost:" + port)
.build()
.get()
.uri("/resource")
.exchange()
.expectStatus().is4xxClientError()
.expectBody();
}
}