X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2FInMemoryWithMongoDbStorageIT.java;h=464513bdd9f4135f8f3f5013be056644062f5adf;hb=64ede95835a496e84857c38213dbf8ea451878e0;hp=7055af54166c855bb4add457963846b3dc21b6da;hpb=b4ba2e35e606a6463e9842a15c9f77b97435ecb5;p=demos%2Fkafka%2Fchat diff --git a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java index 7055af54..464513bd 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java @@ -1,83 +1,45 @@ package de.juplo.kafka.chat.backend; -import de.juplo.kafka.chat.backend.implementation.StorageStrategy; import de.juplo.kafka.chat.backend.storage.mongodb.ChatRoomRepository; import de.juplo.kafka.chat.backend.storage.mongodb.MessageRepository; -import de.juplo.kafka.chat.backend.storage.mongodb.MongoDbStorageStrategy; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo; -import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.TestPropertySource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.MongoDBContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import java.time.Clock; - +@TestPropertySource(properties = { + "chat.backend.inmemory.sharding-strategy=none", + "chat.backend.inmemory.storage-strategy=mongodb" }) @Testcontainers -@ExtendWith({SpringExtension.class}) @EnableAutoConfiguration -@AutoConfigureDataMongo @Slf4j public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT { - @Autowired - MongoDbStorageStrategy storageStrategy; - @Autowired - ChatRoomRepository chatRoomRepository; - @Autowired - MessageRepository messageRepository; - - - public InMemoryWithMongoDbStorageIT() - { - super(Clock.systemDefaultZone()); - } - - - @Override - protected StorageStrategy getStorageStrategy() - { - return storageStrategy; - } - - @TestConfiguration - static class InMemoryWithMongoDbStorageStrategyITConfig - { - @Bean - MongoDbStorageStrategy storageStrategy( - ChatRoomRepository chatRoomRepository, - MessageRepository messageRepository) - { - return new MongoDbStorageStrategy(chatRoomRepository, messageRepository); - } - - @Bean - Clock clock() - { - return Clock.systemDefaultZone(); - } - } - @Container @ServiceConnection private static final GenericContainer MONGODB = new MongoDBContainer("mongo:6"); + @BeforeEach + void resetStorage( + @Autowired ChatRoomRepository chatRoomRepository, + @Autowired MessageRepository messageRepository) + { + chatRoomRepository.deleteAll().block(); + messageRepository.deleteAll().block(); + } + @BeforeEach void setUpLogging() { Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log); MONGODB.followOutput(logConsumer); - chatRoomRepository.deleteAll(); - messageRepository.deleteAll(); } }