1 package de.juplo.kafka.chat.backend.domain;
3 import de.juplo.kafka.chat.backend.ChatBackendProperties;
4 import de.juplo.kafka.chat.backend.domain.exceptions.LoadInProgressException;
5 import de.juplo.kafka.chat.backend.domain.exceptions.UnknownChatroomException;
6 import de.juplo.kafka.chat.backend.implementation.inmemory.InMemoryServicesConfiguration;
7 import de.juplo.kafka.chat.backend.storage.files.FilesStorageConfiguration;
8 import org.junit.jupiter.api.DisplayName;
9 import org.junit.jupiter.api.Test;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.boot.context.properties.EnableConfigurationProperties;
12 import org.springframework.context.annotation.Bean;
13 import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
14 import reactor.core.publisher.Mono;
15 import reactor.util.retry.Retry;
17 import java.time.Clock;
18 import java.time.Duration;
19 import java.util.UUID;
21 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
24 @SpringJUnitConfig(classes = {
25 InMemoryServicesConfiguration.class,
26 FilesStorageConfiguration.class,
27 ChatHomeServiceTest.TestConfiguration.class })
28 @EnableConfigurationProperties(ChatBackendProperties.class)
29 public abstract class ChatHomeServiceTest
32 ChatHomeService chatHomeService;
36 @DisplayName("Assert chatroom is delivered, if it exists")
37 void testGetExistingChatroom()
40 UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
43 Mono<ChatRoomData> mono = Mono
44 .defer(() -> chatHomeService.getChatRoomData(chatRoomId))
45 .log("testGetExistingChatroom")
47 .backoff(5, Duration.ofSeconds(1))
48 .filter(throwable -> throwable instanceof LoadInProgressException));
51 assertThat(mono).emitsCount(1);
55 @DisplayName("Assert UnknownChatroomException is thrown, if chatroom does not exist")
56 void testGetNonExistentChatroom()
59 UUID chatRoomId = UUID.fromString("7f59ec77-832e-4a17-8d22-55ef46242c17");
62 Mono<ChatRoomData> mono = Mono
63 .defer(() -> chatHomeService.getChatRoomData(chatRoomId))
64 .log("testGetNonExistentChatroom")
66 .backoff(5, Duration.ofSeconds(1))
67 .filter(throwable -> throwable instanceof LoadInProgressException));
70 assertThat(mono).sendsError(e ->
72 assertThat(e).isInstanceOf(UnknownChatroomException.class);
73 UnknownChatroomException unknownChatroomException = (UnknownChatroomException) e;
74 assertThat(unknownChatroomException.getChatroomId()).isEqualTo(chatRoomId);
78 static class TestConfiguration
83 return Clock.systemDefaultZone();