1 package de.juplo.kafka.chat.backend.persistence;
3 import de.juplo.kafka.chat.backend.domain.*;
4 import lombok.extern.slf4j.Slf4j;
5 import org.junit.jupiter.api.Test;
9 import java.util.function.Supplier;
11 import static pl.rzrz.assertj.reactor.Assertions.*;
15 public abstract class AbstractStorageStrategyIT
17 protected ChatHome chathome;
18 protected ChatRoomFactory chatRoomFactory;
21 protected abstract StorageStrategy getStorageStrategy();
22 protected abstract Supplier<ChatHomeService> getChatHomeServiceSupplier();
23 protected abstract ChatRoomFactory getChatRoomFactory();
25 protected void start()
27 chathome = new ChatHome(getChatHomeServiceSupplier().get(), 0);
28 chatRoomFactory = getChatRoomFactory();
33 getStorageStrategy().write(chathome.getChatRooms());
37 protected void testStoreAndRecreate()
41 assertThat(chathome.getChatRooms().toStream()).hasSize(0);
43 UUID chatRoomId = UUID.randomUUID();
44 ChatRoom chatroom = chatRoomFactory.createChatRoom(chatRoomId, "FOO").block();
45 chathome.putChatRoom(chatroom);
46 Message m1 = chatroom.addMessage(1l,"peter", "Hallo, ich heiße Peter!").block();
47 Message m2 = chatroom.addMessage(1l, "ute", "Ich bin Ute...").block();
48 Message m3 = chatroom.addMessage(2l, "peter", "Willst du mit mir gehen?").block();
49 Message m4 = chatroom.addMessage(1l, "klaus", "Ja? Nein? Vielleicht??").block();
51 assertThat(chathome.getChatRooms().toStream()).containsExactlyElementsOf(List.of(chatroom));
52 assertThat(chathome.getChatRoom(chatroom.getId())).emitsExactly(chatroom);
54 .getChatRoom(chatroom.getId())
55 .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);
60 assertThat(chathome.getChatRooms().toStream()).containsExactlyElementsOf(List.of(chatroom));
61 assertThat(chathome.getChatRoom(chatroom.getId())).emitsExactly(chatroom);
63 .getChatRoom(chatroom.getId())
64 .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4);