package de.juplo.demo;
-import java.net.URI;
-import org.junit.jupiter.api.BeforeEach;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
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.autoconfigure.web.reactive.WebFluxTest;
-import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
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.web.context.WebApplicationContext;
+import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.client.WebClient;
-@WebFluxTest
-@AutoConfigureWebMvc
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@EnableAutoConfiguration
class DemoApplicationIT extends IntegrationTestBase
{
- MockMvc mockMvc;
@Autowired
- WebApplicationContext context;
-
-
- @BeforeEach
- void setUp(WebApplicationContext context)
- {
- mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
- }
+ WebTestClient webClient;
@Test
.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("/?path=test.txt")
+ .exchange()
+ .expectStatus().isOk()
+ .expectHeader().contentType(MediaType.TEXT_HTML)
+ .expectBody(String.class).value(rendered ->
+ {
+ Document doc = Jsoup.parse(rendered);
+ assertThat(
+ doc.select("html > body > main > div > div > pre").text())
+ .isEqualTo("Hello World!");
+ });
}
@Configuration
return new RemoteContentService(
WebClient
.builder()
- .baseUrl("http://localhost:" +
- DemoApplicationIT.MOCK_SERVER.getLocalPort())
+ .baseUrl("http://localhost:" + MOCK_SERVER.getLocalPort())
.build());
}