1 package de.juplo.kafka.chat.backend.domain;
3 import de.juplo.kafka.chat.backend.domain.exceptions.LoadInProgressException;
4 import de.juplo.kafka.chat.backend.domain.exceptions.UnknownChatroomException;
5 import org.junit.jupiter.api.DisplayName;
6 import org.junit.jupiter.api.Test;
7 import org.junit.jupiter.api.extension.ExtendWith;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.test.context.junit.jupiter.SpringExtension;
10 import reactor.core.publisher.Mono;
11 import reactor.util.retry.Retry;
13 import java.time.Duration;
14 import java.util.UUID;
16 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
19 @ExtendWith(SpringExtension.class)
20 public abstract class ChatHomeTest
27 @DisplayName("Assert chatroom is delivered, if it exists")
28 void testGetExistingChatroom()
31 UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
34 Mono<ChatRoomData> mono = Mono
35 .defer(() -> chatHome.getChatRoomData(chatRoomId))
36 .log("testGetExistingChatroom")
38 .backoff(5, Duration.ofSeconds(1))
39 .filter(throwable -> throwable instanceof LoadInProgressException));
42 assertThat(mono).emitsCount(1);
46 @DisplayName("Assert UnknownChatroomException is thrown, if chatroom does not exist")
47 void testGetNonExistentChatroom()
50 UUID chatRoomId = UUID.fromString("7f59ec77-832e-4a17-8d22-55ef46242c17");
53 Mono<ChatRoomData> mono = Mono
54 .defer(() -> chatHome.getChatRoomData(chatRoomId))
55 .log("testGetNonExistentChatroom")
57 .backoff(5, Duration.ofSeconds(1))
58 .filter(throwable -> throwable instanceof LoadInProgressException));
61 assertThat(mono).sendsError(e ->
63 assertThat(e).isInstanceOf(UnknownChatroomException.class);
64 UnknownChatroomException unknownChatroomException = (UnknownChatroomException) e;
65 assertThat(unknownChatroomException.getChatroomId()).isEqualTo(chatRoomId);