WIP:itflux
[demos/testing] / src / test / java / de / juplo / demo / DemoApplicationIT.java
index 00fdbd4..131c52e 100644 (file)
@@ -1,34 +1,28 @@
 package de.juplo.demo;
 
-import de.juplo.demo.DemoApplicationIT.Application;
-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.context.ApplicationContext;
+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.context.junit.jupiter.SpringJUnitConfig;
 import org.springframework.test.web.reactive.server.WebTestClient;
 import org.springframework.web.reactive.function.client.WebClient;
 
-@SpringJUnitConfig(Application.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@EnableAutoConfiguration
 class DemoApplicationIT extends IntegrationTestBase
 {
-  WebTestClient webClient;
   @Autowired
-  ApplicationContext context;
-
-
-  @BeforeEach
-  void setUp()
-  {
-    webClient = WebTestClient.bindToApplicationContext(context).build();
-  }
+  WebTestClient webClient;
 
 
   @Test
@@ -41,11 +35,17 @@ class DemoApplicationIT extends IntegrationTestBase
             .withPort(NGINX.getMappedPort(80)));
     webClient
         .get()
-        .uri(URI.create("http://S.U.T/?path=test.txt"))
+        .uri("/?path=test.txt")
         .exchange()
         .expectStatus().isOk()
         .expectHeader().contentType(MediaType.TEXT_HTML)
-        .expectBody(String.class).isEqualTo("Hello World!\n");
+        .expectBody(String.class).value(rendered ->
+        {
+          Document doc = Jsoup.parse(rendered);
+          assertThat(
+              doc.select("html > body > main > div > div > pre").text())
+              .isEqualTo("Hello World!");
+        });
   }
 
   @Configuration