Added more tests for valid URI's (aka: with parameter)
[demos/testing] / src / test / java / de / juplo / demo / HtmlControllerIT.java
index bcf037c..6e33636 100644 (file)
@@ -5,8 +5,9 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 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 static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,14 +32,15 @@ public class HtmlControllerIT
   RemoteContentService service;
 
 
-  @Test
-  @DisplayName("Mapping for HtmlController: /?path=foo")
-  void testUriWithParameter()
+  @DisplayName("Valid mappings for HtmlController with a parameter")
+  @ParameterizedTest()
+  @ValueSource(strings = { "/?path=foo", "?path=foo" })
+  void testUriWithParameter(String uri)
   {
     when(service.getRemoteText("foo")).thenReturn(Mono.just("bar"));
     webClient
         .get()
-        .uri("/?path=foo")
+        .uri(uri)
         .exchange()
         .expectStatus().isOk()
         .expectBody(String.class).value(rendered ->
@@ -50,4 +52,30 @@ public class HtmlControllerIT
         });
     verify(service).getRemoteText("foo");
   }
+
+  @DisplayName("Mappings for HtmlController without a parameter")
+  @ParameterizedTest(name = "{arguments} ==> uri={0}")
+  @ValueSource(strings = { "/", "", "?foo=bar", "/?foo=bar"})
+  void testUriWithoutParameter(String uri)
+  {
+    webClient
+        .get()
+        .uri(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();
+        });
+  }
 }