fix: Config-ITs do not fail, if run multiple times
authorKai Moritz <kai@juplo.de>
Sat, 3 Feb 2024 11:08:15 +0000 (12:08 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 09:35:33 +0000 (10:35 +0100)
src/test/java/de/juplo/kafka/chat/backend/AbstractConfigurationIT.java

index f2cb579..41618e5 100644 (file)
@@ -15,7 +15,9 @@ import org.testcontainers.shaded.org.awaitility.Awaitility;
 import java.io.IOException;
 import java.time.Duration;
 import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.Matchers.endsWith;
 
 
@@ -62,6 +64,7 @@ public abstract class AbstractConfigurationIT
         .atMost(Duration.ofSeconds(15))
         .untilAsserted(() ->
         {
+          AtomicBoolean existingChatRoomFound = new AtomicBoolean(false);
           webTestClient
               .get()
               .uri(
@@ -70,9 +73,20 @@ public abstract class AbstractConfigurationIT
               .accept(MediaType.APPLICATION_JSON)
               .exchange()
               .expectStatus().isOk()
-              .expectBody()
-                .jsonPath("$.length()").isEqualTo(1)
-                .jsonPath("$[0].name").isEqualTo("FOO");
+              .returnResult(ChatRoomInfoTo.class)
+              .getResponseBody()
+              .toIterable()
+              .forEach(chatRoomInfoTo ->
+              {
+                log.debug("Inspecting chat-room {}", chatRoomInfoTo);
+                if (chatRoomInfoTo.getId().equals(UUID.fromString(EXISTING_CHATROOM)))
+                {
+                  log.debug("Found existing chat-room {}", chatRoomInfoTo);
+                  existingChatRoomFound.set(true);
+                  assertThat(chatRoomInfoTo.getName().equals("FOO"));
+                }
+              });
+          assertThat(existingChatRoomFound.get()).isTrue();
         });
   }