The parameter "path" is added to the model
authorKai Moritz <kai@juplo.de>
Tue, 14 Jan 2020 17:56:15 +0000 (18:56 +0100)
committerKai Moritz <kai@juplo.de>
Thu, 16 Jan 2020 10:18:03 +0000 (11:18 +0100)
* Modified HtmlControllerTest to verify the new behavior
* Fixed the behavior of the HtmlController accordingly
* Added a form to the example-layout

src/main/java/de/juplo/demo/HtmlController.java
src/main/resources/templates/home.html
src/test/java/de/juplo/demo/HtmlControllerTest.java

index ec5919c..92ed7ff 100644 (file)
@@ -27,6 +27,7 @@ public class HtmlController
   @GetMapping({ "", "/" })
   public String fetch(Model model, @RequestParam(required = false) String path)
   {
+    model.addAttribute("path", path);
     model.addAttribute(
         "text",
         path == null
index 6076f98..c36c5ef 100644 (file)
@@ -9,5 +9,14 @@
     <div class="card-text">
       <pre th:text="${text}">TEXT</pre>
     </div>
+    <div class="card-text">
+      <form action="#" th:action="@{/}" method="get">
+        <div class="form-group">
+          <label for="path">Remote-Path to fetch:</label>
+          <input type="text" name="path" value="FOO" th:value="${path}" class="form-control" />
+        </div>
+        <button type="submit" class="btn btn-primary">Submit</button>
+      </form>
+    </div>
   </body>
 </html>
index 0aa7f13..96ac20a 100644 (file)
@@ -53,6 +53,7 @@ public class HtmlControllerTest
 
     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())
@@ -72,6 +73,7 @@ public class HtmlControllerTest
 
     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())