1 package de.juplo.kafka.chat.backend;
3 import lombok.extern.slf4j.Slf4j;
4 import org.junit.jupiter.api.BeforeEach;
5 import org.junit.jupiter.api.DisplayName;
6 import org.junit.jupiter.api.Test;
7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.boot.test.context.SpringBootTest;
9 import org.springframework.boot.test.web.server.LocalServerPort;
10 import org.springframework.http.MediaType;
11 import org.springframework.test.context.DynamicPropertyRegistry;
12 import org.springframework.test.context.DynamicPropertySource;
13 import org.springframework.test.web.reactive.server.WebTestClient;
14 import org.testcontainers.containers.BindMode;
15 import org.testcontainers.containers.GenericContainer;
16 import org.testcontainers.containers.output.Slf4jLogConsumer;
17 import org.testcontainers.junit.jupiter.Container;
18 import org.testcontainers.junit.jupiter.Testcontainers;
19 import org.testcontainers.shaded.org.awaitility.Awaitility;
21 import java.time.Duration;
25 webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
27 "chat.backend.storage=mongodb",
28 "spring.data.mongodb.host=localhost",
29 "spring.data.mongodb.database=test" })
32 class InMemoryWithMongoDbConfigurationIT
37 private WebTestClient webTestClient;
40 @DisplayName("The app starts, the data is restored and accessible")
45 .atMost(Duration.ofSeconds(15))
50 .uri("http://localhost:{port}/actuator/health", port)
52 .expectStatus().isOk()
53 .expectBody().jsonPath("$.status").isEqualTo("UP");
56 .uri("http://localhost:{port}/4ace69b7-a79f-481b-ad0d-d756d60b66ec", port)
57 .accept(MediaType.APPLICATION_JSON)
59 .expectStatus().isOk()
60 .expectBody().jsonPath("$.name").isEqualTo("FOO");
63 .uri("http://localhost:{port}/4ace69b7-a79f-481b-ad0d-d756d60b66ec/ute/1", port)
64 .accept(MediaType.APPLICATION_JSON)
66 .expectStatus().isOk()
67 .expectBody().jsonPath("$.text").isEqualTo("Ich bin Ute...");
70 .uri("http://localhost:{port}/4ace69b7-a79f-481b-ad0d-d756d60b66ec/peter/1", port)
71 .accept(MediaType.APPLICATION_JSON)
73 .expectStatus().isOk()
74 .expectBody().jsonPath("$.text").isEqualTo("Hallo, ich heiße Peter!");
78 private static final int MONGODB_PORT = 27017;
81 private static final GenericContainer CONTAINER =
82 new GenericContainer("mongo:6")
83 .withClasspathResourceMapping(
85 "/docker-entrypoint-initdb.d",
87 .withExposedPorts(MONGODB_PORT);
89 @DynamicPropertySource
90 static void addMongoPortProperty(DynamicPropertyRegistry registry)
92 registry.add("spring.data.mongodb.port", () -> CONTAINER.getMappedPort(27017));
98 Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);
99 CONTAINER.followOutput(logConsumer);