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))
39 "http://localhost:{port}/actuator/health",
42 .expectStatus().isOk()
43 .expectBody().jsonPath("$.status").isEqualTo("UP");
48 @DisplayName("Restored chat-rooms can be listed")
49 void testRestoredChatRoomsCanBeListed()
53 .atMost(Duration.ofSeconds(15))
59 "http://localhost:{port}/list",
61 .accept(MediaType.APPLICATION_JSON)
63 .expectStatus().isOk()
65 .jsonPath("$.length()").isEqualTo(1)
66 .jsonPath("$[0].name").isEqualTo("FOO");
71 @DisplayName("Details as expected for restored chat-room")
72 void testRestoredChatRoomHasExpectedDetails()
76 .atMost(Duration.ofSeconds(15))
82 "http://localhost:{port}/{chatRoomId}",
85 .accept(MediaType.APPLICATION_JSON)
87 .expectStatus().isOk()
88 .expectBody().jsonPath("$.name").isEqualTo("FOO");
93 @DisplayName("Restored message from Ute has expected Text")
94 void testRestoredMessageForUteHasExpectedText()
98 .atMost(Duration.ofSeconds(15))
104 "http://localhost:{port}/{chatRoomId}/ute/1",
107 .accept(MediaType.APPLICATION_JSON)
109 .expectStatus().isOk()
110 .expectBody().jsonPath("$.text").isEqualTo("Ich bin Ute...");
115 @DisplayName("Restored message from Peter has expected Text")
116 void testRestoredMessageForPeterHasExpectedText()
120 .atMost(Duration.ofSeconds(15))
126 "http://localhost:{port}/{chatRoomId}/peter/1",
129 .accept(MediaType.APPLICATION_JSON)
131 .expectStatus().isOk()
132 .expectBody().jsonPath("$.text").isEqualTo("Hallo, ich heiße Peter!");
137 @DisplayName("A PUT-message for a non-existent chat-room yields 404 NOT FOUND")
138 void testNotFoundForPutMessageToNonExistentChatRoom()
140 String otherChatRoomId = "7f59ec77-832e-4a17-8d22-55ef46242c17";
144 .atMost(Duration.ofSeconds(15))
150 "http://localhost:{port}/{chatRoomId}/otto/66",
153 .contentType(MediaType.TEXT_PLAIN)
154 .accept(MediaType.APPLICATION_JSON)
155 .bodyValue("The devil rules route 66")
157 .expectStatus().isNotFound()
159 .jsonPath("$.type").value(endsWith("/problem/unknown-chatroom"))
160 .jsonPath("$.chatroomId").isEqualTo(otherChatRoomId);