1 package de.juplo.kafka.chat.backend.domain;
3 import org.junit.jupiter.api.DisplayName;
4 import org.junit.jupiter.api.Test;
5 import org.junit.jupiter.api.extension.ExtendWith;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.test.context.junit.jupiter.SpringExtension;
8 import reactor.core.publisher.Mono;
9 import reactor.util.retry.Retry;
11 import java.time.Duration;
12 import java.util.UUID;
14 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
17 @ExtendWith(SpringExtension.class)
18 public abstract class ChatHomeTest
25 @DisplayName("Assert chatroom is delivered, if it exists")
26 void testGetExistingChatroom()
29 UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
32 Mono<ChatRoomData> mono = Mono
33 .defer(() -> chatHome.getChatRoomData(chatRoomId))
34 .log("testGetExistingChatroom")
36 .backoff(5, Duration.ofSeconds(1))
37 .filter(throwable -> throwable instanceof LoadInProgressException));
40 assertThat(mono).emitsCount(1);
44 @DisplayName("Assert UnknownChatroomException is thrown, if chatroom does not exist")
45 void testGetNonExistentChatroom()
48 UUID chatRoomId = UUID.fromString("7f59ec77-832e-4a17-8d22-55ef46242c17");
51 Mono<ChatRoomData> mono = Mono
52 .defer(() -> chatHome.getChatRoomData(chatRoomId))
53 .log("testGetNonExistentChatroom")
55 .backoff(5, Duration.ofSeconds(1))
56 .filter(throwable -> throwable instanceof LoadInProgressException));
59 assertThat(mono).sendsError(e ->
61 assertThat(e).isInstanceOf(UnknownChatroomException.class);
62 UnknownChatroomException unknownChatroomException = (UnknownChatroomException) e;
63 assertThat(unknownChatroomException.getChatroomId()).isEqualTo(chatRoomId);