fix: Fixed a NPE in `ShardedChatHome.getChatRooms()`
[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}/list", port)
39               .accept(MediaType.APPLICATION_JSON)
40               .exchange()
41               .expectStatus().isOk()
42               .expectBody()
43                 .jsonPath("$.length()").isEqualTo(1)
44                 .jsonPath("$[0].name").isEqualTo("FOO");
45           webTestClient
46               .get()
47               .uri("http://localhost:{port}/5c73531c-6fc4-426c-adcb-afc5c140a0f7", port)
48               .accept(MediaType.APPLICATION_JSON)
49               .exchange()
50               .expectStatus().isOk()
51               .expectBody().jsonPath("$.name").isEqualTo("FOO");
52           webTestClient
53               .get()
54               .uri("http://localhost:{port}/5c73531c-6fc4-426c-adcb-afc5c140a0f7/ute/1", port)
55               .accept(MediaType.APPLICATION_JSON)
56               .exchange()
57               .expectStatus().isOk()
58               .expectBody().jsonPath("$.text").isEqualTo("Ich bin Ute...");
59           webTestClient
60               .get()
61               .uri("http://localhost:{port}/5c73531c-6fc4-426c-adcb-afc5c140a0f7/peter/1", port)
62               .accept(MediaType.APPLICATION_JSON)
63               .exchange()
64               .expectStatus().isOk()
65               .expectBody().jsonPath("$.text").isEqualTo("Hallo, ich heiße Peter!");
66         });
67   }
68 }