<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
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");
+ });
}
}
+++ /dev/null
-[ {
- "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"
-} ]
+++ /dev/null
-[ {
- "id" : "618e89ae-fdc0-4c65-8055-f49908295e8f",
- "name" : "Peter's Chat-Room"
-} ]
\ No newline at end of file
--- /dev/null
+[ {
+ "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"
+} ]
--- /dev/null
+[ {
+ "id" : "618e89ae-fdc0-4c65-8055-f49908295e8f",
+ "name" : "Peter's Chat-Room"
+} ]
\ No newline at end of file