test: Streamlined the config-IT, so that they use the same expectations
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / AbstractConfigurationIT.java
1 package de.juplo.kafka.chat.backend;
2
3 import org.junit.jupiter.api.DisplayName;
4 import org.junit.jupiter.api.Test;
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.boot.test.web.server.LocalServerPort;
7 import org.springframework.http.MediaType;
8 import org.springframework.test.web.reactive.server.WebTestClient;
9 import org.testcontainers.shaded.org.awaitility.Awaitility;
10
11 import java.time.Duration;
12
13
14 public abstract class AbstractConfigurationIT
15 {
16   @LocalServerPort
17   int port;
18   @Autowired
19   WebTestClient webTestClient;
20
21   @Test
22   @DisplayName("The app starts, the data is restored and accessible")
23   void test()
24   {
25     Awaitility
26         .await()
27         .atMost(Duration.ofSeconds(15))
28         .untilAsserted(() ->
29         {
30           webTestClient
31               .get()
32               .uri("http://localhost:{port}/actuator/health", port)
33               .exchange()
34               .expectStatus().isOk()
35               .expectBody().jsonPath("$.status").isEqualTo("UP");
36           webTestClient
37               .get()
38               .uri("http://localhost:{port}/5c73531c-6fc4-426c-adcb-afc5c140a0f7", port)
39               .accept(MediaType.APPLICATION_JSON)
40               .exchange()
41               .expectStatus().isOk()
42               .expectBody().jsonPath("$.name").isEqualTo("FOO");
43           webTestClient
44               .get()
45               .uri("http://localhost:{port}/5c73531c-6fc4-426c-adcb-afc5c140a0f7/ute/1", port)
46               .accept(MediaType.APPLICATION_JSON)
47               .exchange()
48               .expectStatus().isOk()
49               .expectBody().jsonPath("$.text").isEqualTo("Ich bin Ute...");
50           webTestClient
51               .get()
52               .uri("http://localhost:{port}/5c73531c-6fc4-426c-adcb-afc5c140a0f7/peter/1", port)
53               .accept(MediaType.APPLICATION_JSON)
54               .exchange()
55               .expectStatus().isOk()
56               .expectBody().jsonPath("$.text").isEqualTo("Hallo, ich heiße Peter!");
57         });
58   }
59 }