From: Kai Moritz Date: Mon, 13 Jan 2020 14:35:24 +0000 (+0100) Subject: WIP X-Git-Tag: wip-it~21 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=019433a025f725b3119465a8ad8f9637fc3c5f3b;p=demos%2Ftesting WIP -- TODO * IT auf TestWebClient umstellen? MockMvc funktioniert nicht! * Commit für IT ordentlich beschreiben * RemoteContentRestController bei Einführung in RestController umbenennen ** Dort ordentlich die Scheidung text/html | text/plain umsetzen ** Dort Testfall kontrollieren * Danach: Commit für RestController nach IT-Test verschieben * Anpassung / Ergänzung des IT-Tests? --- diff --git a/src/main/java/de/juplo/demo/RemoteContentController.java b/src/main/java/de/juplo/demo/RemoteContentController.java deleted file mode 100644 index 422f5a6..0000000 --- a/src/main/java/de/juplo/demo/RemoteContentController.java +++ /dev/null @@ -1,31 +0,0 @@ -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/main/java/de/juplo/demo/RemoteContentRestController.java b/src/main/java/de/juplo/demo/RemoteContentRestController.java new file mode 100644 index 0000000..312dd3f --- /dev/null +++ b/src/main/java/de/juplo/demo/RemoteContentRestController.java @@ -0,0 +1,32 @@ +package de.juplo.demo; + + +import org.springframework.http.MediaType; +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 RemoteContentRestController +{ + RemoteContentService service; + + + public RemoteContentRestController(RemoteContentService service) + { + this.service = service; + } + + + @GetMapping(path = "/", produces = MediaType.TEXT_PLAIN_VALUE) + 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 deleted file mode 100644 index fdba099..0000000 --- a/src/test/java/de/juplo/demo/RemoteContentControllerTest.java +++ /dev/null @@ -1,44 +0,0 @@ -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); - } -} diff --git a/src/test/java/de/juplo/demo/RemoteContentRestControllerTest.java b/src/test/java/de/juplo/demo/RemoteContentRestControllerTest.java new file mode 100644 index 0000000..c034f0f --- /dev/null +++ b/src/test/java/de/juplo/demo/RemoteContentRestControllerTest.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 RemoteContentRestController}. + * @author Kai Moritz + */ +@ExtendWith(SpringExtension.class) +public class RemoteContentRestControllerTest +{ + RemoteContentRestController controller; + RemoteContentService service; + + + @BeforeEach + void setUp() + { + service = Mockito.mock(RemoteContentService.class); + controller = new RemoteContentRestController(service); + } + + + @Test + void test() + { + Mono mono = Mono.empty(); + when(service.getRemoteText("foo")).thenReturn(mono); + + // when + Mono result = controller.fetch("foo"); + + assertThat(result).isSameAs(mono); + } +}