From 8cb83aff1cb8d631a47f4707611889bc3355790b Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 13 Jan 2020 12:43:27 +0100 Subject: [PATCH] Added a rest-controller, that serves the fetched data --- .../juplo/demo/RemoteContentController.java | 31 +++++++++++++ .../demo/RemoteContentControllerTest.java | 44 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/main/java/de/juplo/demo/RemoteContentController.java create mode 100644 src/test/java/de/juplo/demo/RemoteContentControllerTest.java diff --git a/src/main/java/de/juplo/demo/RemoteContentController.java b/src/main/java/de/juplo/demo/RemoteContentController.java new file mode 100644 index 0000000..422f5a6 --- /dev/null +++ b/src/main/java/de/juplo/demo/RemoteContentController.java @@ -0,0 +1,31 @@ +package de.juplo.demo; + + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + + +/** + * Fetches and returns data from remote-webserver. + * @author Kai Moritz + */ +@RestController +public class RemoteContentController +{ + RemoteContentService service; + + + public RemoteContentController(RemoteContentService service) + { + this.service = service; + } + + + @GetMapping("/") + public Mono fetch(@RequestParam String path) + { + return service.getRemoteText(path); + } +} diff --git a/src/test/java/de/juplo/demo/RemoteContentControllerTest.java b/src/test/java/de/juplo/demo/RemoteContentControllerTest.java new file mode 100644 index 0000000..fdba099 --- /dev/null +++ b/src/test/java/de/juplo/demo/RemoteContentControllerTest.java @@ -0,0 +1,44 @@ +package de.juplo.demo; + + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mockito; +import static org.mockito.Mockito.when; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import reactor.core.publisher.Mono; + + +/** + * Unit-Test for class {@link RemoteContentController}. + * @author Kai Moritz + */ +@ExtendWith(SpringExtension.class) +public class RemoteContentControllerTest +{ + RemoteContentController controller; + RemoteContentService service; + + + @BeforeEach + void setUp() + { + service = Mockito.mock(RemoteContentService.class); + controller = new RemoteContentController(service); + } + + + @Test + void test() + { + Mono mono = Mono.empty(); + when(service.getRemoteText("foo")).thenReturn(mono); + + // when + Mono result = controller.fetch("foo"); + + assertThat(result).isSameAs(mono); + } +} -- 2.20.1