test: RED - Proofed existence of an NPE in `ShardedChatHome.getChatRoom()`
[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 testAppStartsDataIsRestoredAndAccessible()
24   {
25     String chatRoomId = "5c73531c-6fc4-426c-adcb-afc5c140a0f7";
26
27     Awaitility
28         .await()
29         .atMost(Duration.ofSeconds(15))
30         .untilAsserted(() ->
31         {
32           webTestClient
33               .get()
34               .uri(
35                   "http://localhost:{port}/actuator/health",
36                   port)
37               .exchange()
38               .expectStatus().isOk()
39               .expectBody().jsonPath("$.status").isEqualTo("UP");
40           webTestClient
41               .get()
42               .uri(
43                   "http://localhost:{port}/list",
44                   port)
45               .accept(MediaType.APPLICATION_JSON)
46               .exchange()
47               .expectStatus().isOk()
48               .expectBody()
49                 .jsonPath("$.length()").isEqualTo(1)
50                 .jsonPath("$[0].name").isEqualTo("FOO");
51           webTestClient
52               .get()
53               .uri("http://localhost:{port}/{chatRoomId}",
54                   port,
55                   chatRoomId)
56               .accept(MediaType.APPLICATION_JSON)
57               .exchange()
58               .expectStatus().isOk()
59               .expectBody().jsonPath("$.name").isEqualTo("FOO");
60           webTestClient
61               .get()
62               .uri(
63                   "http://localhost:{port}/{chatRoomId}/ute/1",
64                   port,
65                   chatRoomId)
66               .accept(MediaType.APPLICATION_JSON)
67               .exchange()
68               .expectStatus().isOk()
69               .expectBody().jsonPath("$.text").isEqualTo("Ich bin Ute...");
70           webTestClient
71               .get()
72               .uri(
73                   "http://localhost:{port}/{chatRoomId}/peter/1",
74                   port,
75                   chatRoomId)
76               .accept(MediaType.APPLICATION_JSON)
77               .exchange()
78               .expectStatus().isOk()
79               .expectBody().jsonPath("$.text").isEqualTo("Hallo, ich heiße Peter!");
80         });
81   }
82 }