feat: Introduced config-parameters for the `io.projectreactor`-logging
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / InMemoryWithFilesStorageIT.java
1 package de.juplo.kafka.chat.backend;
2
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.implementation.StorageStrategy;
7 import de.juplo.kafka.chat.backend.storage.files.FilesStorageStrategy;
8 import lombok.extern.slf4j.Slf4j;
9 import org.junit.jupiter.api.BeforeEach;
10
11 import java.io.IOException;
12 import java.nio.file.Files;
13 import java.nio.file.Path;
14 import java.nio.file.Paths;
15 import java.time.Clock;
16 import java.util.logging.Level;
17
18
19 @Slf4j
20 public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT
21 {
22   final static Path path = Paths.get("target","files");
23
24   final ObjectMapper mapper;
25   final FilesStorageStrategy storageStrategy;
26
27
28   public InMemoryWithFilesStorageIT()
29   {
30     super(Clock.systemDefaultZone());
31     mapper = new ObjectMapper();
32     mapper.registerModule(new JavaTimeModule());
33     mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
34     storageStrategy = new FilesStorageStrategy(
35         path,
36         chatRoomId -> 0,
37         mapper,
38         Level.FINE,
39         true);
40   }
41
42
43   @Override
44   protected StorageStrategy getStorageStrategy()
45   {
46     return storageStrategy;
47   }
48
49   @BeforeEach
50   void reset() throws Exception
51   {
52     if (Files.exists(path))
53     {
54       Files
55           .walk(path)
56           .forEach(file ->
57           {
58             try
59             {
60               if (!file.equals(path))
61               {
62                 log.debug("Deleting file {}", file);
63                 Files.delete(file);
64               }
65             }
66             catch (IOException e)
67             {
68               throw new RuntimeException(e);
69             }
70           });
71       log.debug("Deleting data-directory {}", path);
72       Files.delete(path);
73     }
74   }
75 }