From 0023e94bb797dfbafbbd7696f69905200669037e Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 4 Mar 2024 09:29:19 +0100 Subject: [PATCH] test: HandoverIT-POC - Added assertions for the sent/received messages --- .../kafka/chat/backend/AbstractHandoverIT.java | 15 +++++++++++++++ .../de/juplo/kafka/chat/backend/TestWriter.java | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java index dff9b563..bac07fff 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java @@ -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 receivedMessages = testListener.receivedMessages.get(chatRoom.getId()); + + Assertions.assertThat(receivedMessages + .stream() + .filter(message -> message.getUser().equals(testWriter.user.getName())) + ).containsExactlyElementsOf(testWriter.sentMessages); + } } Mono createChatRoom(String name) diff --git a/src/test/java/de/juplo/kafka/chat/backend/TestWriter.java b/src/test/java/de/juplo/kafka/chat/backend/TestWriter.java index 0d2c41e7..d4cc7195 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/TestWriter.java +++ b/src/test/java/de/juplo/kafka/chat/backend/TestWriter.java @@ -100,8 +100,8 @@ public class TestWriter private final WebClient webClient; - private final ChatRoomInfoTo chatRoom; + final ChatRoomInfoTo chatRoom; final User user; final List sentMessages = new LinkedList<>(); -- 2.20.1