1 package de.juplo.kafka.chat.backend;
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;
11 import java.time.Duration;
13 import static org.hamcrest.Matchers.endsWith;
16 public abstract class AbstractConfigurationIT
21 WebTestClient webTestClient;
25 @DisplayName("The app starts, the data is restored and accessible")
26 void testAppStartsDataIsRestoredAndAccessible()
28 String chatRoomId = "5c73531c-6fc4-426c-adcb-afc5c140a0f7";
32 .atMost(Duration.ofSeconds(15))
38 "http://localhost:{port}/actuator/health",
41 .expectStatus().isOk()
42 .expectBody().jsonPath("$.status").isEqualTo("UP");
46 "http://localhost:{port}/list",
48 .accept(MediaType.APPLICATION_JSON)
50 .expectStatus().isOk()
52 .jsonPath("$.length()").isEqualTo(1)
53 .jsonPath("$[0].name").isEqualTo("FOO");
56 .uri("http://localhost:{port}/{chatRoomId}",
59 .accept(MediaType.APPLICATION_JSON)
61 .expectStatus().isOk()
62 .expectBody().jsonPath("$.name").isEqualTo("FOO");
66 "http://localhost:{port}/{chatRoomId}/ute/1",
69 .accept(MediaType.APPLICATION_JSON)
71 .expectStatus().isOk()
72 .expectBody().jsonPath("$.text").isEqualTo("Ich bin Ute...");
76 "http://localhost:{port}/{chatRoomId}/peter/1",
79 .accept(MediaType.APPLICATION_JSON)
81 .expectStatus().isOk()
82 .expectBody().jsonPath("$.text").isEqualTo("Hallo, ich heiße Peter!");
87 @DisplayName("A PUT-message for a non-existent chat-room yields 404 NOT FOUND")
88 void testNotFoundForPutMessageToNonExistentChatRoom()
90 String otherChatRoomId = "7f59ec77-832e-4a17-8d22-55ef46242c17";
94 .atMost(Duration.ofSeconds(15))
99 "http://localhost:{port}/{chatRoomId}/otto/66",
102 .contentType(MediaType.TEXT_PLAIN)
103 .accept(MediaType.APPLICATION_JSON)
104 .bodyValue("The devil rules route 66")
106 .expectStatus().isNotFound()
108 .jsonPath("$.type").value(endsWith("/problem/unknown-chatroom"))
109 .jsonPath("$.chatroomId").isEqualTo(otherChatRoomId));