fix: `ChatBackendApplicationTest` cannot corrupt the real data anymore
authorKai Moritz <kai@juplo.de>
Mon, 9 Jan 2023 20:14:35 +0000 (21:14 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 15 Jan 2023 18:37:26 +0000 (19:37 +0100)
- The test used the default storage-direcory.
- Because the app is sometimes aborted during the shutdown, this sometimes
  lead to corrupted data in the default storage-directory.
- The test now uses a predefined set of data underneath the build-directory.
- Also changed the name of the according property to `storage-directory`.

src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java
src/test/java/de/juplo/kafka/chat/backend/ChatBackendApplicationTests.java
src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json [new file with mode: 0644]
src/test/resources/data/chatrooms.json [new file with mode: 0644]

index 68ccc4f..6570862 100644 (file)
@@ -43,7 +43,7 @@ public class ChatBackendConfiguration
       ObjectMapper mapper)
   {
     return new LocalJsonFilesStorageStrategy(
-        Paths.get(properties.getDatadir()),
+        Paths.get(properties.getStorageDirectory()),
         clock,
         properties.getChatroomBufferSize(),
         mapper);
index 26149de..48e5816 100644 (file)
@@ -12,7 +12,7 @@ import java.nio.file.Paths;
 @Setter
 public class ChatBackendProperties
 {
-  private String datadir = Paths.get(System.getProperty("java.io.tmpdir"),"chat", "backend").toString();
+  private String storageDirectory = Paths.get(System.getProperty("java.io.tmpdir"),"chat", "backend").toString();
   private String allowedOrigins = "http://localhost:4200";
   private int chatroomBufferSize = 8;
 }
index fde473c..9accd8a 100644 (file)
@@ -3,7 +3,7 @@ package de.juplo.kafka.chat.backend;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 
-@SpringBootTest
+@SpringBootTest(properties = "chat.backend.storage-directory=target/test-classes/data/")
 class ChatBackendApplicationTests
 {
        @Test
diff --git a/src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json b/src/test/resources/data/618e89ae-fdc0-4c65-8055-f49908295e8f.json
new file mode 100644 (file)
index 0000000..0c8abcb
--- /dev/null
@@ -0,0 +1,19 @@
+[ {
+  "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"
+} ]
diff --git a/src/test/resources/data/chatrooms.json b/src/test/resources/data/chatrooms.json
new file mode 100644 (file)
index 0000000..5b6c22b
--- /dev/null
@@ -0,0 +1,4 @@
+[ {
+  "id" : "618e89ae-fdc0-4c65-8055-f49908295e8f",
+  "name" : "Peter's Chat-Room"
+} ]
\ No newline at end of file