From 29631b1b25010f6c1ee30fe0755c6e9421ce154b Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 11 Jan 2023 21:55:07 +0100 Subject: [PATCH] WIP --- pom.xml | 10 ++++- .../backend/ChatBackendApplicationTests.java | 43 ++++++++++++++++++- .../618e89ae-fdc0-4c65-8055-f49908295e8f.json | 0 .../resources/data/{ => files}/chatrooms.json | 0 4 files changed, 51 insertions(+), 2 deletions(-) rename src/test/resources/data/{ => files}/618e89ae-fdc0-4c65-8055-f49908295e8f.json (100%) rename src/test/resources/data/{ => files}/chatrooms.json (100%) 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/files/618e89ae-fdc0-4c65-8055-f49908295e8f.json similarity index 100% rename from src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json rename to src/test/resources/data/files/618e89ae-fdc0-4c65-8055-f49908295e8f.json diff --git a/src/test/resources/data/chatrooms.json b/src/test/resources/data/files/chatrooms.json similarity index 100% rename from src/test/resources/data/chatrooms.json rename to src/test/resources/data/files/chatrooms.json -- 2.20.1