X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2FAbstractStorageStrategyIT.java;h=74c7c6fd63809f49c15aa67259816c083c2c6dd3;hb=64ede95835a496e84857c38213dbf8ea451878e0;hp=03c3aa45ee967258bbcaaa42f2dffe6cf9b7f929;hpb=9ac32a888a2a03e7d40679226213c3b3b67d586e;p=demos%2Fkafka%2Fchat diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractStorageStrategyIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractStorageStrategyIT.java index 03c3aa45..74c7c6fd 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractStorageStrategyIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractStorageStrategyIT.java @@ -1,40 +1,52 @@ package de.juplo.kafka.chat.backend; import de.juplo.kafka.chat.backend.domain.*; -import de.juplo.kafka.chat.backend.persistence.StorageStrategy; +import de.juplo.kafka.chat.backend.implementation.StorageStrategy; +import de.juplo.kafka.chat.backend.implementation.inmemory.InMemoryServicesConfiguration; +import de.juplo.kafka.chat.backend.storage.files.FilesStorageConfiguration; +import de.juplo.kafka.chat.backend.storage.mongodb.MongoDbStorageConfiguration; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import java.time.Clock; import java.util.List; import java.util.UUID; import static pl.rzrz.assertj.reactor.Assertions.*; +@SpringJUnitConfig(classes = { + InMemoryServicesConfiguration.class, + FilesStorageConfiguration.class, + MongoDbStorageConfiguration.class, + AbstractStorageStrategyIT.TestConfig.class }) +@EnableConfigurationProperties(ChatBackendProperties.class) @Slf4j public abstract class AbstractStorageStrategyIT { - protected ChatHomeService chathome; + @Autowired + ChatHomeService chathome; + @Autowired + StorageStrategy storageStrategy; - protected abstract StorageStrategy getStorageStrategy(); - protected abstract StorageStrategyITConfig getConfig(); + abstract void restore(); - protected void start() + void store() { - StorageStrategyITConfig config = getConfig(); - chathome = config.getChatHome(); - } - - protected void stop() - { - getStorageStrategy().write(chathome); + storageStrategy + .write(chathome) + .block(); } @Test - protected void testStoreAndRecreate() + void testStoreAndRecreate() { - start(); + restore(); assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0); @@ -53,8 +65,8 @@ public abstract class AbstractStorageStrategyIT .getChatRoomData(chatRoomId) .flatMapMany(cr -> cr.getMessages())).emitsExactly(m1, m2, m3, m4); - stop(); - start(); + store(); + restore(); assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyElementsOf(List.of(info)); assertThat(chathome.getChatRoomInfo(chatRoomId)).emitsExactly(info); @@ -64,9 +76,9 @@ public abstract class AbstractStorageStrategyIT } @Test - protected void testStoreAndRecreateParallelChatRooms() + void testStoreAndRecreateParallelChatRooms() { - start(); + restore(); assertThat(chathome.getChatRoomInfo().toStream()).hasSize(0); @@ -98,8 +110,8 @@ public abstract class AbstractStorageStrategyIT .getChatRoomData(chatRoomBId) .flatMapMany(cr -> cr.getMessages())).emitsExactly(mb1, mb2, mb3, mb4); - stop(); - start(); + store(); + restore(); assertThat(chathome.getChatRoomInfo().toStream()).containsExactlyInAnyOrderElementsOf(List.of(infoA, infoB)); assertThat(chathome.getChatRoomInfo(chatRoomAId)).emitsExactly(infoA); @@ -113,8 +125,12 @@ public abstract class AbstractStorageStrategyIT } - interface StorageStrategyITConfig + static class TestConfig { - ChatHomeService getChatHome(); + @Bean + Clock clock() + { + return Clock.systemDefaultZone(); + } } }