From c9071e43856d9590be886d2de60a18737ef0384f Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 14 Jan 2020 19:43:15 +0100 Subject: [PATCH] Added an integration-tests for RestController --- .../java/de/juplo/demo/RestControllerIT.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/de/juplo/demo/RestControllerIT.java diff --git a/src/test/java/de/juplo/demo/RestControllerIT.java b/src/test/java/de/juplo/demo/RestControllerIT.java new file mode 100644 index 0000000..68ad229 --- /dev/null +++ b/src/test/java/de/juplo/demo/RestControllerIT.java @@ -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"); + } +} -- 2.20.1