WIP:refactor: Refined channel-states, introduced `ChannelState` -- ALIGN
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / AbstractStorageStrategyIT.java
index 5eaf541..74c7c6f 100644 (file)
@@ -2,39 +2,51 @@ package de.juplo.kafka.chat.backend;
 
 import de.juplo.kafka.chat.backend.domain.*;
 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();
+    }
   }
 }