- Both tests now use the same data and expect the same results.
- Moved the actual tests and assertions to `AbstractConfigurationIT`.
- Also streamlined `AbstractStorageStrategyIT`, so that it produces
the exact same data, that the configuration-tests are expecting.
This is not a necessary change to get the refined coniguration-tests
running. It just makes it easier, to produce the needed test-data for
future refinements.
- Also streamlined the naming of the directory, where
`InMemoryWithFilesStorageIT` stores its data.
--- /dev/null
+package de.juplo.kafka.chat.backend;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+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;
+
+import java.time.Duration;
+
+
+public abstract class AbstractConfigurationIT
+{
+ @LocalServerPort
+ int port;
+ @Autowired
+ WebTestClient webTestClient;
+
+ @Test
+ @DisplayName("The app starts, the data is restored and accessible")
+ void test()
+ {
+ 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}/5c73531c-6fc4-426c-adcb-afc5c140a0f7", port)
+ .accept(MediaType.APPLICATION_JSON)
+ .exchange()
+ .expectStatus().isOk()
+ .expectBody().jsonPath("$.name").isEqualTo("FOO");
+ webTestClient
+ .get()
+ .uri("http://localhost:{port}/5c73531c-6fc4-426c-adcb-afc5c140a0f7/ute/1", port)
+ .accept(MediaType.APPLICATION_JSON)
+ .exchange()
+ .expectStatus().isOk()
+ .expectBody().jsonPath("$.text").isEqualTo("Ich bin Ute...");
+ webTestClient
+ .get()
+ .uri("http://localhost:{port}/5c73531c-6fc4-426c-adcb-afc5c140a0f7/peter/1", port)
+ .accept(MediaType.APPLICATION_JSON)
+ .exchange()
+ .expectStatus().isOk()
+ .expectBody().jsonPath("$.text").isEqualTo("Hallo, ich heiße Peter!");
+ });
+ }
+}
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;
-
-import java.time.Duration;
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = "chat.backend.storage-directory=target/test-classes/data/files")
-class InMemoryWithFilesConfigurationIT
+class InMemoryWithFilesConfigurationIT extends AbstractConfigurationIT
{
- @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}/618e89ae-fdc0-4c65-8055-f49908295e8f/ute/1478", port)
- .accept(MediaType.APPLICATION_JSON)
- .exchange()
- .expectStatus().isOk()
- .expectBody().jsonPath("$.text").isEqualTo("Nachricht Nr. 1478");
- });
- }
}
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.DisplayName;
-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.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
-import org.springframework.test.web.reactive.server.WebTestClient;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import org.testcontainers.shaded.org.awaitility.Awaitility;
-
-import java.time.Duration;
@SpringBootTest(
"spring.data.mongodb.database=test" })
@Testcontainers
@Slf4j
-class InMemoryWithMongoDbConfigurationIT
+class InMemoryWithMongoDbConfigurationIT extends AbstractConfigurationIT
{
- @LocalServerPort
- private int port;
- @Autowired
- private WebTestClient webTestClient;
-
- @Test
- @DisplayName("The app starts, the data is restored and accessible")
- void test()
- {
- 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}/4ace69b7-a79f-481b-ad0d-d756d60b66ec", port)
- .accept(MediaType.APPLICATION_JSON)
- .exchange()
- .expectStatus().isOk()
- .expectBody().jsonPath("$.name").isEqualTo("FOO");
- webTestClient
- .get()
- .uri("http://localhost:{port}/4ace69b7-a79f-481b-ad0d-d756d60b66ec/ute/1", port)
- .accept(MediaType.APPLICATION_JSON)
- .exchange()
- .expectStatus().isOk()
- .expectBody().jsonPath("$.text").isEqualTo("Ich bin Ute...");
- webTestClient
- .get()
- .uri("http://localhost:{port}/4ace69b7-a79f-481b-ad0d-d756d60b66ec/peter/1", port)
- .accept(MediaType.APPLICATION_JSON)
- .exchange()
- .expectStatus().isOk()
- .expectBody().jsonPath("$.text").isEqualTo("Hallo, ich heiße Peter!");
- });
- }
-
private static final int MONGODB_PORT = 27017;
@Container
assertThat(chathome.getChatRooms().toStream()).hasSize(0);
- UUID chatRoomId = UUID.randomUUID();
+ UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
ChatRoom chatroom = chatRoomFactory.createChatRoom(chatRoomId, "FOO").block();
chathome.putChatRoom(chatroom);
Message m1 = chatroom.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
@Slf4j
public class InMemoryWithFilesStorageIT extends AbstractStorageStrategyIT
{
- final static Path path = Paths.get("target","local-json-files");
+ final static Path path = Paths.get("target","files");
final Clock clock;
final ObjectMapper mapper;
--- /dev/null
+[ {
+ "id" : 1,
+ "serial" : 0,
+ "time" : "2023-01-13T21:46:51.846312215",
+ "user" : "peter",
+ "text" : "Hallo, ich heiße Peter!"
+}, {
+ "id" : 1,
+ "serial" : 1,
+ "time" : "2023-01-13T21:46:51.847319045",
+ "user" : "ute",
+ "text" : "Ich bin Ute..."
+}, {
+ "id" : 2,
+ "serial" : 2,
+ "time" : "2023-01-13T21:46:51.847415356",
+ "user" : "peter",
+ "text" : "Willst du mit mir gehen?"
+}, {
+ "id" : 1,
+ "serial" : 3,
+ "time" : "2023-01-13T21:46:51.847465432",
+ "user" : "klaus",
+ "text" : "Ja? Nein? Vielleicht??"
+} ]
\ 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"
-} ]
[ {
- "id" : "618e89ae-fdc0-4c65-8055-f49908295e8f",
- "name" : "Peter's Chat-Room"
+ "id" : "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
+ "name" : "FOO",
+ "shard" : 0
} ]
\ No newline at end of file
{
- "_id": "4ace69b7-a79f-481b-ad0d-d756d60b66ec",
+ "_id": "5c73531c-6fc4-426c-adcb-afc5c140a0f7",
"name": "FOO",
+ "shard": 0,
"messages": [
{
"_id": "peter--1",
"serial": 0,
- "time": "2023-01-11T20:53:05.143528961",
+ "time": "2023-01-13T20:43:16.803382151",
"text": "Hallo, ich heiße Peter!"
},
{
"_id": "ute--1",
"serial": 1,
- "time": "2023-01-11T20:53:05.144161529",
+ "time": "2023-01-13T20:43:16.804049969",
"text": "Ich bin Ute..."
},
{
"_id": "peter--2",
"serial": 2,
- "time": "2023-01-11T20:53:05.144202513",
+ "time": "2023-01-13T20:43:16.804092782",
"text": "Willst du mit mir gehen?"
},
{
"_id": "klaus--1",
"serial": 3,
- "time": "2023-01-11T20:53:05.144236865",
+ "time": "2023-01-13T20:43:16.804122604",
"text": "Ja? Nein? Vielleicht??"
}
],