1 package de.juplo.kafka.chat.backend;
3 import org.junit.jupiter.api.BeforeEach;
4 import org.junit.jupiter.api.DisplayName;
5 import org.junit.jupiter.api.Test;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.boot.test.web.server.LocalServerPort;
8 import org.springframework.http.MediaType;
9 import org.springframework.test.web.reactive.server.WebTestClient;
10 import org.testcontainers.shaded.org.awaitility.Awaitility;
12 import java.time.Duration;
14 import static org.hamcrest.Matchers.endsWith;
17 public abstract class AbstractConfigurationIT
19 final static String EXISTING_CHATROOM = "5c73531c-6fc4-426c-adcb-afc5c140a0f7";
25 WebTestClient webTestClient;
33 .atMost(Duration.ofSeconds(15))
38 "http://localhost:{port}/actuator/health",
41 .expectStatus().isOk()
42 .expectBody().jsonPath("$.status").isEqualTo("UP"));
46 @DisplayName("Restored chat-rooms can be listed")
47 void testRestoredChatRoomsCanBeListed()
52 "http://localhost:{port}/list",
54 .accept(MediaType.APPLICATION_JSON)
56 .expectStatus().isOk()
58 .jsonPath("$.length()").isEqualTo(1)
59 .jsonPath("$[0].name").isEqualTo("FOO");
63 @DisplayName("Details as expected for restored chat-room")
64 void testRestoredChatRoomHasExpectedDetails()
69 "http://localhost:{port}/{chatRoomId}",
72 .accept(MediaType.APPLICATION_JSON)
74 .expectStatus().isOk()
75 .expectBody().jsonPath("$.name").isEqualTo("FOO");
79 @DisplayName("Restored message from Ute has expected Text")
80 void testRestoredMessageForUteHasExpectedText()
85 "http://localhost:{port}/{chatRoomId}/ute/1",
88 .accept(MediaType.APPLICATION_JSON)
90 .expectStatus().isOk()
91 .expectBody().jsonPath("$.text").isEqualTo("Ich bin Ute...");
95 @DisplayName("Restored message from Peter has expected Text")
96 void testRestoredMessageForPeterHasExpectedText()
101 "http://localhost:{port}/{chatRoomId}/peter/1",
104 .accept(MediaType.APPLICATION_JSON)
106 .expectStatus().isOk()
107 .expectBody().jsonPath("$.text").isEqualTo("Hallo, ich heiße Peter!");
111 @DisplayName("A PUT-message for a non-existent chat-room yields 404 NOT FOUND")
112 void testNotFoundForPutMessageToNonExistentChatRoom()
114 String otherChatRoomId = "7f59ec77-832e-4a17-8d22-55ef46242c17";
118 .atMost(Duration.ofSeconds(15))
123 "http://localhost:{port}/{chatRoomId}/otto/66",
126 .contentType(MediaType.TEXT_PLAIN)
127 .accept(MediaType.APPLICATION_JSON)
128 .bodyValue("The devil rules route 66")
130 .expectStatus().isNotFound()
132 .jsonPath("$.type").value(endsWith("/problem/unknown-chatroom"))
133 .jsonPath("$.chatroomId").isEqualTo(otherChatRoomId));