From: Kai Moritz Date: Mon, 4 Mar 2024 08:29:19 +0000 (+0100) Subject: test: HandoverIT-POC - Added assertions for the sent/received messages X-Git-Tag: rebase--2024-03-05--09-07~17 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=0023e94bb797dfbafbbd7696f69905200669037e;p=demos%2Fkafka%2Fchat test: HandoverIT-POC - Added assertions for the sent/received messages --- 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<>();