--- /dev/null
+package de.juplo.kafka.chat.backend.persistence;
+
+import de.juplo.kafka.chat.backend.domain.ChatHomeService;
+import de.juplo.kafka.chat.backend.domain.ChatRoomFactory;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomFactory;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+import java.time.Clock;
+
+
+@RequiredArgsConstructor
+@Slf4j
+public abstract class AbstractInMemoryStorageIT extends AbstractStorageStrategyIT
+{
+ final Clock clock;
+
+ @Override
+ protected StorageStrategyITConfig getConfig()
+ {
+ return new StorageStrategyITConfig()
+ {
+ InMemoryChatHomeService chatHomeService = new InMemoryChatHomeService(
+ 1,
+ new int[] { 0 },
+ getStorageStrategy().read());
+
+ InMemoryChatRoomFactory chatRoomFactory = new InMemoryChatRoomFactory(
+ chatRoomId -> 0,
+ clock,
+ 8);
+
+ @Override
+ public ChatHomeService getChatHomeService()
+ {
+ return chatHomeService;
+ }
+
+ @Override
+ public ChatRoomFactory getChatRoomFactory()
+ {
+ return chatRoomFactory;
+ }
+ };
+ }
+}
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.domain.ChatHomeService;
-import de.juplo.kafka.chat.backend.domain.ChatRoomFactory;
-import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomFactory;
import de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy;
-import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
@Slf4j
-public class InMemoryWithFilesStorageIT extends AbstractStorageStrategyIT
+public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT
{
final static Path path = Paths.get("target","files");
- final Clock clock;
final ObjectMapper mapper;
final FilesStorageStrategy storageStrategy;
public InMemoryWithFilesStorageIT()
{
- clock = Clock.systemDefaultZone();
+ super(Clock.systemDefaultZone());
mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return storageStrategy;
}
- @Override
- protected StorageStrategyITConfig getConfig()
- {
- return new StorageStrategyITConfig()
- {
- InMemoryChatHomeService chatHomeService = new InMemoryChatHomeService(
- 1,
- new int[] { 0 },
- getStorageStrategy().read());
-
- InMemoryChatRoomFactory chatRoomFactory = new InMemoryChatRoomFactory(
- chatRoomId -> 0,
- clock,
- 8);
-
- @Override
- public ChatHomeService getChatHomeService()
- {
- return chatHomeService;
- }
-
- @Override
- public ChatRoomFactory getChatRoomFactory()
- {
- return chatRoomFactory;
- }
- };
- }
-
@BeforeEach
void reset() throws Exception
{
package de.juplo.kafka.chat.backend.persistence;
-import de.juplo.kafka.chat.backend.domain.ChatHomeService;
-import de.juplo.kafka.chat.backend.domain.ChatRoomFactory;
-import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
import de.juplo.kafka.chat.backend.persistence.InMemoryWithMongoDbStorageIT.DataSourceInitializer;
-import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomFactory;
import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
import de.juplo.kafka.chat.backend.persistence.storage.mongodb.ChatRoomRepository;
import de.juplo.kafka.chat.backend.persistence.storage.mongodb.MongoDbStorageStrategy;
@AutoConfigureDataMongo
@ContextConfiguration(initializers = DataSourceInitializer.class)
@Slf4j
-public class InMemoryWithMongoDbStorageIT extends AbstractStorageStrategyIT
+public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT
{
@Autowired
MongoDbStorageStrategy storageStrategy;
Clock clock;
- @Override
- protected StorageStrategy getStorageStrategy()
+ public InMemoryWithMongoDbStorageIT()
{
- return storageStrategy;
+ super(Clock.systemDefaultZone());
}
+
@Override
- protected StorageStrategyITConfig getConfig()
+ protected StorageStrategy getStorageStrategy()
{
- return new StorageStrategyITConfig()
- {
- InMemoryChatHomeService chatHomeService = new InMemoryChatHomeService(
- 1,
- new int[] { 0 },
- getStorageStrategy().read());
-
- InMemoryChatRoomFactory chatRoomFactory = new InMemoryChatRoomFactory(
- chatRoomId -> 0,
- clock,
- 8);
-
- @Override
- public ChatHomeService getChatHomeService()
- {
- return chatHomeService;
- }
-
- @Override
- public ChatRoomFactory getChatRoomFactory()
- {
- return chatRoomFactory;
- }
- };
+ return storageStrategy;
}
@TestConfiguration