import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;
.jsonPath("message").isEqualTo("Required String parameter 'path' is not present")
.jsonPath("timestamp").exists();
}
+
+ @DisplayName("Remote-Server answers with 404: Not Found")
+ @Test()
+ void testResponseNotFound()
+ {
+ when(service.getRemoteText("foo")).thenReturn(Mono.error(exception(404)));
+ webClient
+ .get()
+ .uri("/?path=foo")
+ .header("Accept", MediaType.TEXT_PLAIN_VALUE)
+ .exchange()
+ .expectStatus().isNotFound()
+ .expectBody()
+ .jsonPath("status").isEqualTo(404)
+ .jsonPath("error").isEqualTo("Not Found")
+ .jsonPath("path").isEqualTo("/")
+ .jsonPath("timestamp").exists();
+ }
+
+
+ WebClientResponseException exception(int status)
+ {
+ return WebClientResponseException.create(status, "MESSAGE", null, null, null);
+ }
}