X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2FInMemoryWithFilesStorageIT.java;h=0d63b7ed51acff8ac6aeb41daab0a29f5f3d9133;hb=64ede95835a496e84857c38213dbf8ea451878e0;hp=19e3cc1a5f4510ce0c25fc7c40735becc385ef91;hpb=386f950f8b329bf2b956fa7896e270a39037967d;p=demos%2Fkafka%2Fchat 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 19e3cc1a..0d63b7ed 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java @@ -3,49 +3,33 @@ 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 de.juplo.kafka.chat.backend.implementation.StorageStrategy; -import de.juplo.kafka.chat.backend.storage.files.FilesStorageStrategy; 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; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.time.Clock; +@TestPropertySource(properties = { + "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 { - final static Path path = Paths.get("target","files"); - - final ObjectMapper mapper; - final FilesStorageStrategy storageStrategy; - - - public InMemoryWithFilesStorageIT() - { - super(Clock.systemDefaultZone()); - mapper = new ObjectMapper(); - mapper.registerModule(new JavaTimeModule()); - mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - storageStrategy = new FilesStorageStrategy( - path, - chatRoomId -> 0, - mapper); - } - - - @Override - protected StorageStrategy getStorageStrategy() - { - return storageStrategy; - } - @BeforeEach - void reset() throws Exception + void resetStorage( + @Autowired ChatBackendProperties properties) + throws Exception { + Path path = Paths.get(properties.getInmemory().getStorageDirectory()); if (Files.exists(path)) { Files @@ -69,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; + } + } }