From 3e2bf879f947df4fda04ea0a2d3c1b4fa9ae6ed4 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 14 Jan 2020 08:46:57 +0100 Subject: [PATCH] WIP:itflux --- .../java/de/juplo/demo/DemoApplicationIT.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/test/java/de/juplo/demo/DemoApplicationIT.java b/src/test/java/de/juplo/demo/DemoApplicationIT.java index be40c75..db6448a 100644 --- a/src/test/java/de/juplo/demo/DemoApplicationIT.java +++ b/src/test/java/de/juplo/demo/DemoApplicationIT.java @@ -6,31 +6,24 @@ import org.junit.jupiter.api.Test; import static org.mockserver.matchers.Times.exactly; import static org.mockserver.model.HttpForward.forward; import static org.mockserver.model.HttpRequest.request; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.reactive.function.client.WebClient; @SpringBootTest class DemoApplicationIT extends IntegrationTestBase { - MockMvc mockMvc; - @Autowired - WebApplicationContext context; + WebTestClient webClient; @BeforeEach void setUp(WebApplicationContext context) { - mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); + webClient = WebTestClient.bindToApplicationContext(context).build(); } @@ -42,11 +35,13 @@ class DemoApplicationIT extends IntegrationTestBase .forward(forward() .withHost(NGINX.getContainerIpAddress()) .withPort(NGINX.getMappedPort(80))); - mockMvc - .perform(get(URI.create("http://S.U.T/?path=test.txt"))) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.TEXT_PLAIN)) - .andExpect(content().string("Hello World!\n")); + webClient + .get() + .uri(URI.create("http://S.U.T/?path=test.txt")) + .exchange() + .expectStatus().is2xxSuccessful() + .expectHeader().contentType(MediaType.TEXT_HTML) + .expectBody(String.class).isEqualTo("Hello World!\n"); } @Configuration -- 2.20.1