test: Streamlined the config-IT, so that they use the same expectations
authorKai Moritz <kai@juplo.de>
Fri, 13 Jan 2023 20:44:02 +0000 (21:44 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 15 Jan 2023 18:38:33 +0000 (19:38 +0100)
- 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.

src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java [new file with mode: 0644]
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesConfigurationIT.java
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbConfigurationIT.java
src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java
src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageIT.java
src/test/resources/data/files/5c73531c-6fc4-426c-adcb-afc5c140a0f7.json [new file with mode: 0644]
src/test/resources/data/files/618e89ae-fdc0-4c65-8055-f49908295e8f.json [deleted file]
src/test/resources/data/files/chatrooms.json
src/test/resources/data/mongodb/chatRoomTo.json

diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java
new file mode 100644 (file)
index 0000000..8c309b8
--- /dev/null
@@ -0,0 +1,59 @@
+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!");
+        });
+  }
+}
index 8aa0815..0065219 100644 (file)
@@ -1,54 +1,11 @@
 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");
-                               });
-       }
 }
index 4612aa8..abb0956 100644 (file)
@@ -2,23 +2,14 @@ package de.juplo.kafka.chat.backend;
 
 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(
@@ -29,52 +20,8 @@ import java.time.Duration;
                                "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
index e305c12..84cf7d9 100644 (file)
@@ -40,7 +40,7 @@ public abstract class AbstractStorageStrategyIT
 
     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();
index bd1a5c6..2c72ea0 100644 (file)
@@ -24,7 +24,7 @@ import java.util.function.Supplier;
 @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;
diff --git a/src/test/resources/data/files/5c73531c-6fc4-426c-adcb-afc5c140a0f7.json b/src/test/resources/data/files/5c73531c-6fc4-426c-adcb-afc5c140a0f7.json
new file mode 100644 (file)
index 0000000..af5e6e0
--- /dev/null
@@ -0,0 +1,25 @@
+[ {
+  "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
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
deleted file mode 100644 (file)
index 0c8abcb..0000000
+++ /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"
-} ]
index 5b6c22b..d0f1b92 100644 (file)
@@ -1,4 +1,5 @@
 [ {
-  "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
index c100ceb..5d1bee0 100644 (file)
@@ -1,29 +1,30 @@
 {
-  "_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??"
     }
   ],