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.implementation.kafka.KafkaServicesConfiguration;
8 import de.juplo.kafka.chat.backend.storage.files.FilesStorageConfiguration;
9 import org.junit.jupiter.api.DisplayName;
10 import org.junit.jupiter.api.Test;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.boot.context.properties.EnableConfigurationProperties;
13 import org.springframework.context.annotation.Bean;
14 import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
15 import reactor.core.publisher.Mono;
16 import reactor.util.retry.Retry;
18 import java.time.Clock;
19 import java.time.Duration;
20 import java.util.UUID;
22 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
25 @SpringJUnitConfig(classes = {
26 InMemoryServicesConfiguration.class,
27 FilesStorageConfiguration.class,
28 KafkaServicesConfiguration.class,
29 ChatHomeServiceTest.TestConfiguration.class })
30 @EnableConfigurationProperties(ChatBackendProperties.class)
31 public abstract class ChatHomeServiceTest
34 ChatHomeService chatHomeService;
38 @DisplayName("Assert chatroom is delivered, if it exists")
39 void testGetExistingChatroom()
42 UUID chatRoomId = UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7");
45 Mono<ChatRoomData> mono = Mono
46 .defer(() -> chatHomeService.getChatRoomData(chatRoomId))
47 .log("testGetExistingChatroom")
49 .backoff(5, Duration.ofSeconds(1))
50 .filter(throwable -> throwable instanceof LoadInProgressException));
53 assertThat(mono).emitsCount(1);
57 @DisplayName("Assert UnknownChatroomException is thrown, if chatroom does not exist")
58 void testGetNonExistentChatroom()
61 UUID chatRoomId = UUID.fromString("7f59ec77-832e-4a17-8d22-55ef46242c17");
64 Mono<ChatRoomData> mono = Mono
65 .defer(() -> chatHomeService.getChatRoomData(chatRoomId))
66 .log("testGetNonExistentChatroom")
68 .backoff(5, Duration.ofSeconds(1))
69 .filter(throwable -> throwable instanceof LoadInProgressException));
72 assertThat(mono).sendsError(e ->
74 assertThat(e).isInstanceOf(UnknownChatroomException.class);
75 UnknownChatroomException unknownChatroomException = (UnknownChatroomException) e;
76 assertThat(unknownChatroomException.getChatroomId()).isEqualTo(chatRoomId);
80 static class TestConfiguration
85 return Clock.systemDefaultZone();