From: Kai Moritz Date: Tue, 14 Jan 2020 17:06:41 +0000 (+0100) Subject: Missing path-parameter renders a page without remote-data (no 400) X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=3eeb808a70301a9bf98dd6a3b6141e33cf863156;p=demos%2Ftesting Missing path-parameter renders a page without remote-data (no 400) * Added a test to MappingIT, that defines the expected behavior * Fixed the behavior in HtmlController accordingly --- diff --git a/src/main/java/de/juplo/demo/HtmlController.java b/src/main/java/de/juplo/demo/HtmlController.java index d26c8c5..0c5f276 100644 --- a/src/main/java/de/juplo/demo/HtmlController.java +++ b/src/main/java/de/juplo/demo/HtmlController.java @@ -25,13 +25,15 @@ public class HtmlController @GetMapping("/") - public String fetch(Model model, @RequestParam String path) + public String fetch(Model model, @RequestParam(required = false) String path) { model.addAttribute( "text", - service - .getRemoteText(path) - .onErrorResume(t -> Mono.just(t.getMessage()))); + path == null + ? "" + : service + .getRemoteText(path) + .onErrorResume(t -> Mono.just(t.getMessage()))); return "home"; } } diff --git a/src/test/java/de/juplo/demo/HtmlControllerIT.java b/src/test/java/de/juplo/demo/HtmlControllerIT.java index bcf037c..b6bd98f 100644 --- a/src/test/java/de/juplo/demo/HtmlControllerIT.java +++ b/src/test/java/de/juplo/demo/HtmlControllerIT.java @@ -50,4 +50,29 @@ public class HtmlControllerIT }); verify(service).getRemoteText("foo"); } + + @Test + @DisplayName("Mapping for HtmlController: /") + void testUriWithoutParameter() + { + webClient + .get() + .uri("/") + .exchange() + .expectStatus().isOk() + .expectBody(String.class).value(rendered -> + { + Document doc = Jsoup.parse(rendered); + assertThat( + doc + .select("html > body > main > div > div > div > pre") + .isEmpty()) + .isFalse(); + assertThat( + doc + .select("html > body > main > div > div > div > pre") + .text()) + .isEmpty(); + }); + } }