From bf0121fe5fe3b60563e9deec9b35aca8e5da1993 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 14 Jan 2020 10:16:06 +0100 Subject: [PATCH] Added an integration-test for HtmlController * The test verifies the mapping from URL's to controllers --- pom.xml | 11 ++++ .../java/de/juplo/demo/HtmlControllerIT.java | 53 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/test/java/de/juplo/demo/HtmlControllerIT.java diff --git a/pom.xml b/pom.xml index 8da5bd0..4c97fe5 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ 1.8 + 1.12.1 @@ -44,6 +45,12 @@ reactor-test test + + org.jsoup + jsoup + ${jsoup.version} + test + org.springframework.boot @@ -58,6 +65,10 @@ org.springframework.boot spring-boot-maven-plugin + + org.apache.maven.plugins + maven-failsafe-plugin + diff --git a/src/test/java/de/juplo/demo/HtmlControllerIT.java b/src/test/java/de/juplo/demo/HtmlControllerIT.java new file mode 100644 index 0000000..bcf037c --- /dev/null +++ b/src/test/java/de/juplo/demo/HtmlControllerIT.java @@ -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"); + } +} -- 2.20.1