+
+ @Test
+ @DisplayName("Data not found on remote-server")
+ void testNotFoud()
+ {
+ Mono<String> mono = Mono.error(WebClientResponseException.create(404, "", null, null, null));
+ when(service.getRemoteText("foo")).thenReturn(mono);
+
+ String result = controller.fetch(model, "foo");
+
+ assertThat(result).isEqualTo("home");
+ ArgumentCaptor<Mono<String>> captor = ArgumentCaptor.forClass(Mono.class);
+ verify(model).addAttribute("path", "foo");
+ verify(model).addAttribute(eq("text"), captor.capture());
+ StepVerifier
+ .create(captor.getValue())
+ .expectNext("404 ")
+ .expectComplete()
+ .verify();
+ }
+
+ /**
+ * Only the behavior on the common errors, as defined in {@link
+ * WebClientResponseException#create(int, String, org.springframework.http.HttpHeaders, byte[], java.nio.charset.Charset, org.springframework.http.HttpRequest)
+ * WebClientResponseException.create()} is tested.
+ */
+ @DisplayName("Other error while fetching data from remote-server")
+ @ParameterizedTest(name = "{arguments} ==> HTTP-status={0}")
+ @EnumSource(value = HttpStatus.class, names = {
+ "BAD_REQUEST",
+ "UNAUTHORIZED",
+ "FORBIDDEN",
+ "METHOD_NOT_ALLOWED",
+ "NOT_ACCEPTABLE",
+ "CONFLICT",
+ "GONE",
+ "UNSUPPORTED_MEDIA_TYPE",
+ "TOO_MANY_REQUESTS",
+ "UNPROCESSABLE_ENTITY",
+ "INTERNAL_SERVER_ERROR",
+ "NOT_IMPLEMENTED",
+ "BAD_GATEWAY",
+ "SERVICE_UNAVAILABLE",
+ "GATEWAY_TIMEOUT"
+ })
+ void testOtherError(HttpStatus status)
+ {
+ Mono<String> mono = Mono.error(WebClientResponseException.create(status.value(), "", null, null, null));
+ when(service.getRemoteText("foo")).thenReturn(mono);
+
+ String result = controller.fetch(model, "foo");
+
+ assertThat(result).isEqualTo("home");
+ ArgumentCaptor<Mono<String>> captor = ArgumentCaptor.forClass(Mono.class);
+ verify(model).addAttribute(eq("text"), captor.capture());
+ StepVerifier
+ .create(captor.getValue())
+ .expectNextMatches(message -> message.startsWith(Integer.toString(status.value())))
+ .expectComplete()
+ .verify();
+ }