From: Kai Moritz Date: Wed, 11 Jan 2023 20:55:07 +0000 (+0100) Subject: WIP X-Git-Tag: wip-config-package~3 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=29631b1b25010f6c1ee30fe0755c6e9421ce154b;p=demos%2Fkafka%2Fchat WIP --- diff --git a/pom.xml b/pom.xml index 3c31a27c..769c1383 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,10 @@ org.springframework.boot spring-boot-starter-webflux - + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.boot spring-boot-devtools @@ -81,6 +84,11 @@ junit-jupiter test + + org.awaitility + awaitility + test + diff --git a/src/test/java/de/juplo/kafka/chat/backend/ChatBackendApplicationTests.java b/src/test/java/de/juplo/kafka/chat/backend/ChatBackendApplicationTests.java index 9accd8af..ecabaf7d 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/ChatBackendApplicationTests.java +++ b/src/test/java/de/juplo/kafka/chat/backend/ChatBackendApplicationTests.java @@ -1,13 +1,54 @@ package de.juplo.kafka.chat.backend; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.testcontainers.shaded.org.awaitility.Awaitility; -@SpringBootTest(properties = "chat.backend.storage-directory=target/test-classes/data/") +import java.time.Duration; + + +@SpringBootTest( + properties = "chat.backend.storage-directory=target/test-classes/data/files", + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class ChatBackendApplicationTests { + @LocalServerPort + private int port; + @Autowired + private WebTestClient webTestClient; + @Test void contextLoads() { + Awaitility + .await() + .atMost(Duration.ofSeconds(15)) + .untilAsserted(() -> + { + webTestClient + .get() + .uri("http://localhost:{port}/actuator/health", port) + .exchange() + .expectStatus().isOk() + .expectBody().jsonPath("$.status").isEqualTo("UP"); + webTestClient + .get() + .uri("http://localhost:{port}/618e89ae-fdc0-4c65-8055-f49908295e8f", port) + .accept(MediaType.APPLICATION_JSON) + .exchange() + .expectStatus().isOk() + .expectBody().jsonPath("$.name").isEqualTo("Peter's Chat-Room"); + webTestClient + .get() + .uri("http://localhost:{port}/4ace69b7-a79f-481b-ad0d-d756d60b66ec/ute/1478", port) + .accept(MediaType.APPLICATION_JSON) + .exchange() + .expectStatus().isOk() + .expectBody().jsonPath("$.text").isEqualTo("Nachricht Nr. 1478"); + }); } } diff --git a/src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json b/src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json deleted file mode 100644 index 0c8abcbe..00000000 --- a/src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json +++ /dev/null @@ -1,19 +0,0 @@ -[ { - "id" : 1477, - "serial" : 0, - "time" : "2023-01-08T00:10:08.817267716", - "user" : "ute", - "text" : "Nachricht Nr. 1477" -}, { - "id" : 1478, - "serial" : 1, - "time" : "2023-01-08T00:10:10.03333094", - "user" : "ute", - "text" : "Nachricht Nr. 1478" -}, { - "id" : 1479, - "serial" : 2, - "time" : "2023-01-08T00:10:11.22582036", - "user" : "ute", - "text" : "Nachricht Nr. 1479" -} ] diff --git a/src/test/resources/data/chatrooms.json b/src/test/resources/data/chatrooms.json deleted file mode 100644 index 5b6c22b5..00000000 --- a/src/test/resources/data/chatrooms.json +++ /dev/null @@ -1,4 +0,0 @@ -[ { - "id" : "618e89ae-fdc0-4c65-8055-f49908295e8f", - "name" : "Peter's Chat-Room" -} ] \ No newline at end of file diff --git a/src/test/resources/data/files/618e89ae-fdc0-4c65-8055-f49908295e8f.json b/src/test/resources/data/files/618e89ae-fdc0-4c65-8055-f49908295e8f.json new file mode 100644 index 00000000..0c8abcbe --- /dev/null +++ b/src/test/resources/data/files/618e89ae-fdc0-4c65-8055-f49908295e8f.json @@ -0,0 +1,19 @@ +[ { + "id" : 1477, + "serial" : 0, + "time" : "2023-01-08T00:10:08.817267716", + "user" : "ute", + "text" : "Nachricht Nr. 1477" +}, { + "id" : 1478, + "serial" : 1, + "time" : "2023-01-08T00:10:10.03333094", + "user" : "ute", + "text" : "Nachricht Nr. 1478" +}, { + "id" : 1479, + "serial" : 2, + "time" : "2023-01-08T00:10:11.22582036", + "user" : "ute", + "text" : "Nachricht Nr. 1479" +} ] diff --git a/src/test/resources/data/files/chatrooms.json b/src/test/resources/data/files/chatrooms.json new file mode 100644 index 00000000..5b6c22b5 --- /dev/null +++ b/src/test/resources/data/files/chatrooms.json @@ -0,0 +1,4 @@ +[ { + "id" : "618e89ae-fdc0-4c65-8055-f49908295e8f", + "name" : "Peter's Chat-Room" +} ] \ No newline at end of file