test: HandoverIT-POC - Added assertions for the sent/received messages
authorKai Moritz <kai@juplo.de>
Mon, 4 Mar 2024 08:29:19 +0000 (09:29 +0100)
committerKai Moritz <kai@juplo.de>
Mon, 4 Mar 2024 08:33:38 +0000 (09:33 +0100)
src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java
src/test/java/de/juplo/kafka/chat/backend/TestWriter.java

index dff9b56..bac07ff 100644 (file)
@@ -1,6 +1,7 @@
 package de.juplo.kafka.chat.backend;
 
 import de.juplo.kafka.chat.backend.api.ChatRoomInfoTo;
+import de.juplo.kafka.chat.backend.api.MessageTo;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -8,9 +9,11 @@ import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.web.reactive.function.client.WebClient;
 import org.testcontainers.junit.jupiter.Testcontainers;
+import pl.rzrz.assertj.reactor.Assertions;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+import java.util.List;
 import java.util.concurrent.CompletableFuture;
 
 
@@ -75,6 +78,18 @@ public abstract class AbstractHandoverIT
 
     // Yield the work, so that the last messages can be received
     Thread.sleep(500);
+
+    for (int i = 0; i < NUM_CLIENTS; i++)
+    {
+      TestWriter testWriter = testWriters[i];
+      ChatRoomInfoTo chatRoom = testWriter.chatRoom;
+      List<MessageTo> receivedMessages = testListener.receivedMessages.get(chatRoom.getId());
+
+      Assertions.assertThat(receivedMessages
+          .stream()
+          .filter(message -> message.getUser().equals(testWriter.user.getName()))
+          ).containsExactlyElementsOf(testWriter.sentMessages);
+    }
   }
 
   Mono<ChatRoomInfoTo> createChatRoom(String name)
index 0d2c41e..d4cc719 100644 (file)
@@ -100,8 +100,8 @@ public class TestWriter
 
 
   private final WebClient webClient;
-  private final ChatRoomInfoTo chatRoom;
 
+  final ChatRoomInfoTo chatRoom;
   final User user;
   final List<MessageTo> sentMessages = new LinkedList<>();