diff --git a/spring-5-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java b/spring-5-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java index f52a20b149..5f42610c3d 100644 --- a/spring-5-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java +++ b/spring-5-reactive-modules/spring-reactive/src/test/java/com/baeldung/reactive/webclient/WebClientIntegrationTest.java @@ -82,6 +82,16 @@ class WebClientIntegrationTest { .verify(); } + @Test + void givenWebClientCreationWithoutUri_whenUsed_thenObtainExpectedResponse() { + WebClient client = WebClient.create(); + + StepVerifier.create(retrieveResponse(client)) + .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() + .contains("Connection refused")) + .verify(); + } + @Test void givenDifferentMethodSpecifications_whenUsed_thenObtainExpectedResponse() { // request specification @@ -111,12 +121,6 @@ class WebClientIntegrationTest { .build()); RequestBodySpec bodySpecusingURI = createDefaultPostRequest().uri( URI.create("http://localhost:" + port + "/resource")); - RequestBodySpec bodySpecOverridenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); - RequestBodySpec bodySpecOverridenBaseUri2 = WebClient.builder() - .baseUrl("http://localhost:" + port) - .build() - .post() - .uri(URI.create("/resource")); // response assertions StepVerifier.create(retrieveResponse(bodySpecUsingString)) @@ -128,12 +132,22 @@ class WebClientIntegrationTest { StepVerifier.create(retrieveResponse(bodySpecusingURI)) .expectNext("processed-bodyValue") .verifyComplete(); - // assert sending request overriding base URI - StepVerifier.create(retrieveResponse(bodySpecOverridenBaseUri)) + } + + @Test + void givenOverriddenUriSpecifications_whenUsed_thenObtainExpectedResponse() { + RequestBodySpec bodySpecOverriddenBaseUri = createDefaultPostRequest().uri(URI.create("/resource")); + StepVerifier.create(retrieveResponse(bodySpecOverriddenBaseUri)) .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() .contains("Connection refused")) .verify(); - StepVerifier.create(retrieveResponse(bodySpecOverridenBaseUri2)) + + RequestBodySpec bodySpecOverriddenBaseUri2 = WebClient.builder() + .baseUrl("http://localhost:" + port) + .build() + .post() + .uri(URI.create("/resource")); + StepVerifier.create(retrieveResponse(bodySpecOverriddenBaseUri2)) .expectErrorMatches(ex -> WebClientRequestException.class.isAssignableFrom(ex.getClass()) && ex.getMessage() .contains("Connection refused")) .verify(); @@ -301,30 +315,35 @@ class WebClientIntegrationTest { .uri("/resource") .bodyValue(BODY_VALUE) .retrieve() - .bodyToMono(String.class); + .bodyToMono(String.class) + .log(); } private Mono retrieveResponse(RequestBodyUriSpec spec) { return spec.uri("/resource") .bodyValue(BODY_VALUE) .retrieve() - .bodyToMono(String.class); + .bodyToMono(String.class) + .log(); } private Mono> retrieveGetResponse(RequestHeadersUriSpec spec) { return spec.uri("/resource") .retrieve() - .bodyToMono(MAP_RESPONSE_REF); + .bodyToMono(MAP_RESPONSE_REF) + .log(); } private Mono retrieveResponse(RequestBodySpec spec) { return spec.bodyValue(BODY_VALUE) .retrieve() - .bodyToMono(String.class); + .bodyToMono(String.class) + .log(); } private Mono retrieveResponse(RequestHeadersSpec spec) { return spec.retrieve() - .bodyToMono(String.class); + .bodyToMono(String.class) + .log(); } }