WIP:test: `*ConfigurationIT` asserts, if restored messages can be seen
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / domain / ChatHomeServiceTest.java
index 6282643..3be9a35 100644 (file)
@@ -1,26 +1,39 @@
 package de.juplo.kafka.chat.backend.domain;
 
-import de.juplo.kafka.chat.backend.domain.exceptions.LoadInProgressException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import de.juplo.kafka.chat.backend.ChatBackendProperties;
+import de.juplo.kafka.chat.backend.implementation.kafka.ChannelNotReadyException;
 import de.juplo.kafka.chat.backend.domain.exceptions.UnknownChatroomException;
+import de.juplo.kafka.chat.backend.implementation.inmemory.InMemoryServicesConfiguration;
+import de.juplo.kafka.chat.backend.implementation.kafka.KafkaServicesConfiguration;
+import de.juplo.kafka.chat.backend.storage.files.FilesStorageConfiguration;
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
 import reactor.core.publisher.Mono;
 import reactor.util.retry.Retry;
 
+import java.time.Clock;
 import java.time.Duration;
 import java.util.UUID;
 
 import static pl.rzrz.assertj.reactor.Assertions.assertThat;
 
 
-@ExtendWith(SpringExtension.class)
-public abstract class ChatHomeTest
+@SpringJUnitConfig(classes = {
+    InMemoryServicesConfiguration.class,
+    FilesStorageConfiguration.class,
+    KafkaServicesConfiguration.class,
+    ChatHomeServiceTest.TestConfiguration.class })
+@EnableConfigurationProperties(ChatBackendProperties.class)
+public abstract class ChatHomeServiceTest
 {
   @Autowired
-  ChatHome chatHome;
+  ChatHomeService chatHomeService;
 
 
   @Test
@@ -32,11 +45,11 @@ public abstract class ChatHomeTest
 
     // When
     Mono<ChatRoomData> mono = Mono
-        .defer(() -> chatHome.getChatRoomData(chatRoomId))
+        .defer(() -> chatHomeService.getChatRoomData(chatRoomId))
         .log("testGetExistingChatroom")
         .retryWhen(Retry
             .backoff(5, Duration.ofSeconds(1))
-            .filter(throwable -> throwable instanceof LoadInProgressException));
+            .filter(throwable -> throwable instanceof ChannelNotReadyException));
 
     // Then
     assertThat(mono).emitsCount(1);
@@ -51,11 +64,11 @@ public abstract class ChatHomeTest
 
     // When
     Mono<ChatRoomData> mono = Mono
-        .defer(() -> chatHome.getChatRoomData(chatRoomId))
+        .defer(() -> chatHomeService.getChatRoomData(chatRoomId))
         .log("testGetNonExistentChatroom")
         .retryWhen(Retry
             .backoff(5, Duration.ofSeconds(1))
-            .filter(throwable -> throwable instanceof LoadInProgressException));
+            .filter(throwable -> throwable instanceof ChannelNotReadyException));
 
     // Then
     assertThat(mono).sendsError(e ->
@@ -65,4 +78,21 @@ public abstract class ChatHomeTest
       assertThat(unknownChatroomException.getChatroomId()).isEqualTo(chatRoomId);
     });
   }
+
+  static class TestConfiguration
+  {
+    @Bean
+    ObjectMapper objectMapper()
+    {
+      ObjectMapper objectMapper = new ObjectMapper();
+      objectMapper.registerModule(new JavaTimeModule());
+      return objectMapper;
+    }
+
+    @Bean
+    Clock clock()
+    {
+      return Clock.systemDefaultZone();
+    }
+  }
 }