3 import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
4 import org.jsoup.Jsoup;
5 import org.jsoup.nodes.Document;
6 import org.junit.jupiter.api.Test;
7 import static org.mockserver.matchers.Times.exactly;
8 import static org.mockserver.model.HttpForward.forward;
9 import static org.mockserver.model.HttpRequest.request;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
12 import org.springframework.boot.test.context.SpringBootTest;
13 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
14 import org.springframework.context.annotation.Bean;
15 import org.springframework.context.annotation.Configuration;
16 import org.springframework.http.MediaType;
17 import org.springframework.test.web.reactive.server.WebTestClient;
18 import org.springframework.web.reactive.function.client.WebClient;
20 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
21 @EnableAutoConfiguration
22 class DemoApplicationIT extends IntegrationTestBase
25 WebTestClient webClient;
29 void test() throws Exception
32 .when(request().withPath("/test.txt"), exactly(1))
34 .withHost(NGINX.getContainerIpAddress())
35 .withPort(NGINX.getMappedPort(80)));
38 .uri("/?path=test.txt")
40 .expectStatus().isOk()
41 .expectHeader().contentType(MediaType.TEXT_HTML)
42 .expectBody(String.class).value(rendered ->
44 Document doc = Jsoup.parse(rendered);
46 doc.select("html > body > main > div > div > pre").text())
47 .isEqualTo("Hello World!");
52 static class Application
55 RemoteContentService service()
57 return new RemoteContentService(
60 .baseUrl("http://localhost:" + MOCK_SERVER.getLocalPort())
65 HtmlController controller(RemoteContentService service)
67 return new HtmlController(service);