test: RED - Proofed existence of an NPE in `ShardedChatHome.getChatRoom()`
authorKai Moritz <kai@juplo.de>
Sat, 18 Feb 2023 10:07:21 +0000 (11:07 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 18 Aug 2023 15:18:37 +0000 (17:18 +0200)
- Refined `AbstractConfigurationIT` to show, that an NPE can occure in
  `ShardedChatHome.getChatRoom()`.
- Defined the expected behaviour, if the NPE is handled correctly in the
  refined integration-test.

src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java
src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationWithFixedShardingIT.java [new file with mode: 0644]
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesAndShardingConfigurationIT.java
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesConfigurationIT.java
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbConfigurationIT.java

index c424b29..139c587 100644 (file)
@@ -20,7 +20,7 @@ public abstract class AbstractConfigurationIT
 
   @Test
   @DisplayName("The app starts, the data is restored and accessible")
-  void test()
+  void testAppStartsDataIsRestoredAndAccessible()
   {
     Awaitility
         .await()
diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationWithFixedShardingIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationWithFixedShardingIT.java
new file mode 100644 (file)
index 0000000..789ef62
--- /dev/null
@@ -0,0 +1,38 @@
+package de.juplo.kafka.chat.backend;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.http.MediaType;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+import java.time.Duration;
+
+
+public abstract class AbstractConfigurationWithFixedShardingIT extends AbstractConfigurationIT
+{
+  @Test
+  @DisplayName("A PUT for a not owned shard yields 404 NOT FOUND")
+  void testPutYields404()
+  {
+    Awaitility
+        .await()
+        .atMost(Duration.ofSeconds(15))
+        .untilAsserted(() ->
+        {
+          webTestClient
+              .put()
+              .uri("http://localhost:{port}/97cca12a-af72-11ed-9b9e-f78fa16794ac/otto/66", port)
+              .contentType(MediaType.TEXT_PLAIN)
+              .accept(MediaType.APPLICATION_JSON)
+              .bodyValue("The devil rules route 66")
+              .exchange()
+              .expectStatus().isNotFound();
+          webTestClient
+              .get()
+              .uri("http://localhost:{port}/97cca12a-af72-11ed-9b9e-f78fa16794ac/otto/66", port)
+              .accept(MediaType.APPLICATION_JSON)
+              .exchange()
+              .expectStatus().isNotFound();
+        });
+  }
+}
index d792d25..77c188d 100644 (file)
@@ -10,6 +10,6 @@ import org.springframework.boot.test.context.SpringBootTest;
         "chat.backend.inmemory.sharding-strategy=kafkalike",
         "chat.backend.inmemory.num-shards=10",
         "chat.backend.inmemory.owned-shards=2" })
-class InMemoryWithFilesAndShardingConfigurationIT extends AbstractConfigurationIT
+class InMemoryWithFilesAndShardingConfigurationIT extends AbstractConfigurationWithFixedShardingIT
 {
 }
index 151a833..435fc13 100644 (file)
@@ -8,6 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest;
                properties = {
                                "chat.backend.inmemory.sharding-strategy=none",
                                "chat.backend.inmemory.storage-directory=target/test-classes/data/files" })
-class InMemoryWithFilesConfigurationIT extends AbstractConfigurationIT
+class InMemoryWithFilesConfigurationIT extends AbstractConfigurationWithFixedShardingIT
 {
 }
index 05f1de5..9e36e51 100644 (file)
@@ -21,7 +21,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
                                "chat.backend.inmemory.storage-strategy=mongodb" })
 @Testcontainers
 @Slf4j
-class InMemoryWithMongoDbConfigurationIT extends AbstractConfigurationIT
+class InMemoryWithMongoDbConfigurationIT extends AbstractConfigurationWithFixedShardingIT
 {
        private static final int MONGODB_PORT = 27017;