1 package de.juplo.kafka.chat.backend.persistence;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.fasterxml.jackson.databind.SerializationFeature;
5 import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
6 import de.juplo.kafka.chat.backend.domain.ChatHomeService;
7 import lombok.extern.slf4j.Slf4j;
8 import org.junit.jupiter.api.BeforeEach;
10 import java.io.IOException;
11 import java.nio.file.Files;
12 import java.nio.file.Path;
13 import java.nio.file.Paths;
14 import java.time.Clock;
15 import java.util.function.Supplier;
19 public class LocalJsonFilesStorageStrategyIT extends AbstractStorageStrategyIT
21 final static Path path = Paths.get("target","local-json-files");
24 final ObjectMapper mapper;
25 final LocalJsonFilesStorageStrategy storageStrategy;
28 public LocalJsonFilesStorageStrategyIT()
30 clock = Clock.systemDefaultZone();
31 mapper = new ObjectMapper();
32 mapper.registerModule(new JavaTimeModule());
33 mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
34 storageStrategy = new LocalJsonFilesStorageStrategy(path, clock, 8, mapper);
40 StorageStrategy getStorageStrategy()
42 return storageStrategy;
46 Supplier<ChatHomeService> chatHomeServiceSupplier()
48 return () -> new InMemoryChatHomeService(getStorageStrategy().readChatrooms(), clock, 8);
52 void reset() throws Exception
54 if (Files.exists(path))
62 if (!file.equals(path))
64 log.debug("Deleting file {}", file);
70 throw new RuntimeException(e);
73 log.debug("Deleting data-directory {}", path);