Added an integration-tests for RestController
authorKai Moritz <kai@juplo.de>
Tue, 14 Jan 2020 18:43:15 +0000 (19:43 +0100)
committerKai Moritz <kai@juplo.de>
Thu, 16 Jan 2020 10:18:03 +0000 (11:18 +0100)
src/test/java/de/juplo/demo/RestControllerIT.java [new file with mode: 0644]

diff --git a/src/test/java/de/juplo/demo/RestControllerIT.java b/src/test/java/de/juplo/demo/RestControllerIT.java
new file mode 100644 (file)
index 0000000..68ad229
--- /dev/null
@@ -0,0 +1,46 @@
+package de.juplo.demo;
+
+
+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.http.MediaType;
+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 RestController}.
+ * @author Kai Moritz
+ */
+@ExtendWith(SpringExtension.class)
+@WebFluxTest()
+public class RestControllerIT
+{
+  @Autowired
+  WebTestClient webClient;
+  @MockBean
+  RemoteContentService service;
+
+
+  @Test
+  @DisplayName("Valid mapping for RestController: /?path=foo")
+  void testUriWithParameter()
+  {
+    when(service.getRemoteText("foo")).thenReturn(Mono.just("bar"));
+    webClient
+        .get()
+        .uri("/?path=foo")
+        .header("Accept", MediaType.TEXT_PLAIN_VALUE)
+        .exchange()
+        .expectStatus().isOk()
+        .expectBody(String.class).isEqualTo("bar");
+    verify(service).getRemoteText("foo");
+  }
+}