refactor: Moved exceptions into package `exceptions` - Aligned Code
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / domain / ChatHomeTest.java
1 package de.juplo.kafka.chat.backend.domain;
2
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;
12
13 import java.time.Duration;
14 import java.util.UUID;
15
16 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
17
18
19 @ExtendWith(SpringExtension.class)
20 public abstract class ChatHomeTest
21 {
22   @Autowired
23   ChatHome chatHome;
24
25
26   @Test
27   @DisplayName("Assert chatroom is delivered, if it exists")
28   void testGetExistingChatroom()
29   {
30     // Given
31     UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
32
33     // When
34     Mono<ChatRoomData> mono = Mono
35         .defer(() -> chatHome.getChatRoomData(chatRoomId))
36         .log("testGetExistingChatroom")
37         .retryWhen(Retry
38             .backoff(5, Duration.ofSeconds(1))
39             .filter(throwable -> throwable instanceof LoadInProgressException));
40
41     // Then
42     assertThat(mono).emitsCount(1);
43   }
44
45   @Test
46   @DisplayName("Assert UnknownChatroomException is thrown, if chatroom does not exist")
47   void testGetNonExistentChatroom()
48   {
49     // Given
50     UUID chatRoomId = UUID.fromString("7f59ec77-832e-4a17-8d22-55ef46242c17");
51
52     // When
53     Mono<ChatRoomData> mono = Mono
54         .defer(() -> chatHome.getChatRoomData(chatRoomId))
55         .log("testGetNonExistentChatroom")
56         .retryWhen(Retry
57             .backoff(5, Duration.ofSeconds(1))
58             .filter(throwable -> throwable instanceof LoadInProgressException));
59
60     // Then
61     assertThat(mono).sendsError(e ->
62     {
63       assertThat(e).isInstanceOf(UnknownChatroomException.class);
64       UnknownChatroomException unknownChatroomException = (UnknownChatroomException) e;
65       assertThat(unknownChatroomException.getChatroomId()).isEqualTo(chatRoomId);
66     });
67   }
68 }