WIP:it FIX!
[demos/testing] / src / test / java / de / juplo / demo / DemoApplicationIT.java
1 package de.juplo.demo;
2
3 import java.net.URI;
4 import org.junit.jupiter.api.Test;
5 import org.junit.jupiter.api.extension.ExtendWith;
6 import static org.mockserver.matchers.Times.exactly;
7 import static org.mockserver.model.HttpForward.forward;
8 import static org.mockserver.model.HttpRequest.request;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
11 import org.springframework.context.annotation.Bean;
12 import org.springframework.context.annotation.Configuration;
13 import org.springframework.http.MediaType;
14 import org.springframework.test.context.junit.jupiter.SpringExtension;
15 import org.springframework.test.web.reactive.server.WebTestClient;
16 import org.springframework.web.reactive.function.client.WebClient;
17
18 @ExtendWith(SpringExtension.class)
19 @WebFluxTest
20 class DemoApplicationIT extends IntegrationTestBase
21 {
22   @Autowired
23   WebTestClient webClient;
24
25
26   @Test
27   void test() throws Exception
28   {
29     MOCK_SERVER
30         .when(request().withPath("/test.txt"), exactly(1))
31         .forward(forward()
32             .withHost(NGINX.getContainerIpAddress())
33             .withPort(NGINX.getMappedPort(80)));
34     webClient
35         .get()
36         .uri(URI.create("http://S.U.T/?path=test.txt"))
37         .exchange()
38         .expectStatus().isOk()
39         .expectHeader().contentType(MediaType.TEXT_HTML)
40         .expectBody(String.class).isEqualTo("Hello World!\n");
41   }
42
43   @Configuration
44   static class Application
45   {
46     @Bean
47     RemoteContentService service()
48     {
49       return new RemoteContentService(
50           WebClient
51               .builder()
52               .baseUrl("http://localhost:" + MOCK_SERVER.getLocalPort())
53               .build());
54     }
55
56     @Bean
57     HtmlController controller(RemoteContentService service)
58     {
59       return new HtmlController(service);
60     }
61   }
62 }