Added an integration-test for HtmlController
authorKai Moritz <kai@juplo.de>
Tue, 14 Jan 2020 09:16:06 +0000 (10:16 +0100)
committerKai Moritz <kai@juplo.de>
Thu, 16 Jan 2020 10:03:03 +0000 (11:03 +0100)
* The test verifies the mapping from URL's to controllers

pom.xml
src/test/java/de/juplo/demo/HtmlControllerIT.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 8da5bd0..4c97fe5 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -16,6 +16,7 @@
 
        <properties>
                <java.version>1.8</java.version>
+               <jsoup.version>1.12.1</jsoup.version>
        </properties>
 
        <dependencies>
                        <artifactId>reactor-test</artifactId>
                        <scope>test</scope>
                </dependency>
+               <dependency>
+                       <groupId>org.jsoup</groupId>
+                       <artifactId>jsoup</artifactId>
+                       <version>${jsoup.version}</version>
+                       <scope>test</scope>
+               </dependency>
 
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                                <groupId>org.springframework.boot</groupId>
                                <artifactId>spring-boot-maven-plugin</artifactId>
                        </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-failsafe-plugin</artifactId>
+                       </plugin>
                </plugins>
        </build>
 
diff --git a/src/test/java/de/juplo/demo/HtmlControllerIT.java b/src/test/java/de/juplo/demo/HtmlControllerIT.java
new file mode 100644 (file)
index 0000000..bcf037c
--- /dev/null
@@ -0,0 +1,53 @@
+package de.juplo.demo;
+
+
+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 static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import reactor.core.publisher.Mono;
+
+
+/**
+ * Narrow Integration-Test for the {@link HtmlController}.
+ * @author Kai Moritz
+ */
+@ExtendWith(SpringExtension.class)
+@WebFluxTest()
+public class HtmlControllerIT
+{
+  @Autowired
+  WebTestClient webClient;
+  @MockBean
+  RemoteContentService service;
+
+
+  @Test
+  @DisplayName("Mapping for HtmlController: /?path=foo")
+  void testUriWithParameter()
+  {
+    when(service.getRemoteText("foo")).thenReturn(Mono.just("bar"));
+    webClient
+        .get()
+        .uri("/?path=foo")
+        .exchange()
+        .expectStatus().isOk()
+        .expectBody(String.class).value(rendered ->
+        {
+          Document doc = Jsoup.parse(rendered);
+          assertThat(
+              doc.select("html > body > main > div > div > div > pre").text())
+              .isEqualTo("bar");
+        });
+    verify(service).getRemoteText("foo");
+  }
+}