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();
}
.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