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
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;
+ }
+ }
}