From: Kai Moritz Date: Fri, 23 Feb 2024 10:39:26 +0000 (+0100) Subject: fix: Disabled mongodb-autoconfig, if mongodb is not used X-Git-Tag: rebase--2024-02-26--19-46~43 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=49a8c8483e432a20a107d95771ba3806811b55a0;p=demos%2Fkafka%2Fchat fix: Disabled mongodb-autoconfig, if mongodb is not used --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java index f49e385b..ad944fa3 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java @@ -1,5 +1,10 @@ package de.juplo.kafka.chat.backend; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration; +import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration; +import org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,4 +21,15 @@ public class ChatBackendConfiguration { return Clock.systemDefaultZone(); } + + + @ConditionalOnExpression("!'${chat.backend.inmemory.storage-strategy}'.toLowerCase().equals('mongodb')") + @Configuration + @EnableAutoConfiguration(exclude = { + MongoReactiveDataAutoConfiguration.class, + MongoReactiveAutoConfiguration.class, + MongoReactiveRepositoriesAutoConfiguration.class }) + public static class DisableMongoDBConfiguration + { + } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java index 72f8e7d5..45175c9f 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java @@ -4,11 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import de.juplo.kafka.chat.backend.ChatBackendProperties; import de.juplo.kafka.chat.backend.implementation.ShardingStrategy; import de.juplo.kafka.chat.backend.implementation.StorageStrategy; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration; -import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration; -import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -20,11 +16,6 @@ import java.nio.file.Paths; name = "storage-strategy", havingValue = "files") @Configuration -@EnableAutoConfiguration( - exclude = { - MongoReactiveDataAutoConfiguration.class, - MongoReactiveRepositoriesAutoConfiguration.class, - MongoAutoConfiguration.class }) public class FilesStorageConfiguration { @Bean diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageConfiguration.java index dc2bdfcc..0d50b892 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageConfiguration.java @@ -1,11 +1,7 @@ package de.juplo.kafka.chat.backend.storage.nostorage; import de.juplo.kafka.chat.backend.implementation.StorageStrategy; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration; -import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration; -import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,11 +12,6 @@ import org.springframework.context.annotation.Configuration; havingValue = "none", matchIfMissing = true) @Configuration -@EnableAutoConfiguration( - exclude = { - MongoReactiveDataAutoConfiguration.class, - MongoReactiveRepositoriesAutoConfiguration.class, - MongoAutoConfiguration.class }) public class NoStorageStorageConfiguration { @Bean diff --git a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java index e4eaf3ab..0d63b7ed 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java @@ -1,8 +1,13 @@ package de.juplo.kafka.chat.backend; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import java.io.IOException; @@ -15,6 +20,7 @@ import java.nio.file.Paths; "chat.backend.inmemory.sharding-strategy=none", "chat.backend.inmemory.storage-strategy=files", "chat.backend.inmemory.storage-directory=target/files" }) +@ContextConfiguration(classes = InMemoryWithFilesStorageIT.TestConfig.class) @Slf4j public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT { @@ -47,4 +53,17 @@ public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT Files.delete(path); } } + + + static class TestConfig + { + @Bean + ObjectMapper objectMapper() + { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + return objectMapper; + } + } } diff --git a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceTest.java b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceTest.java index 858d03d3..d859b141 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/domain/ChatHomeServiceTest.java @@ -1,5 +1,7 @@ package de.juplo.kafka.chat.backend.domain; +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.domain.exceptions.LoadInProgressException; import de.juplo.kafka.chat.backend.domain.exceptions.UnknownChatroomException; @@ -79,6 +81,14 @@ public abstract class ChatHomeServiceTest static class TestConfiguration { + @Bean + ObjectMapper objectMapper() + { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + return objectMapper; + } + @Bean Clock clock() {