refactor: DRY für shard-selection
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / InMemoryWithFilesStorageIT.java
1 package de.juplo.kafka.chat.backend;
2
3 import org.junit.jupiter.api.Test;
4 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.boot.test.context.SpringBootTest;
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 @SpringBootTest(
15                 webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
16                 properties = "chat.backend.storage-directory=target/test-classes/data/files")
17 class InMemoryWithFilesStorageIT
18 {
19         @LocalServerPort
20         private int port;
21         @Autowired
22         private WebTestClient webTestClient;
23
24         @Test
25         void contextLoads()
26         {
27                 Awaitility
28                                 .await()
29                                 .atMost(Duration.ofSeconds(15))
30                                 .untilAsserted(() ->
31                                 {
32                                         webTestClient
33                                                         .get()
34                                                         .uri("http://localhost:{port}/actuator/health", port)
35                                                         .exchange()
36                                                         .expectStatus().isOk()
37                                                         .expectBody().jsonPath("$.status").isEqualTo("UP");
38                                         webTestClient
39                                                         .get()
40                                                         .uri("http://localhost:{port}/618e89ae-fdc0-4c65-8055-f49908295e8f", port)
41                                                         .accept(MediaType.APPLICATION_JSON)
42                                                         .exchange()
43                                                         .expectStatus().isOk()
44                                                         .expectBody().jsonPath("$.name").isEqualTo("Peter's Chat-Room");
45                                         webTestClient
46                                                         .get()
47                                                         .uri("http://localhost:{port}/618e89ae-fdc0-4c65-8055-f49908295e8f/ute/1478", port)
48                                                         .accept(MediaType.APPLICATION_JSON)
49                                                         .exchange()
50                                                         .expectStatus().isOk()
51                                                         .expectBody().jsonPath("$.text").isEqualTo("Nachricht Nr. 1478");
52                                 });
53         }
54 }