WIP
authorKai Moritz <kai@juplo.de>
Tue, 10 Jan 2023 18:26:33 +0000 (19:26 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 10 Jan 2023 18:26:33 +0000 (19:26 +0100)
pom.xml
src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithMongoDbStorageStrategyIT.java

diff --git a/pom.xml b/pom.xml
index f9c93a0..7b32556 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                        <artifactId>testcontainers</artifactId>
                        <scope>test</scope>
                </dependency>
-       
                <dependency>
                        <groupId>org.testcontainers</groupId>
                        <artifactId>junit-jupiter</artifactId>
                        <scope>test</scope>
                </dependency>
-       
-               <dependency>
-                       <groupId>org.testcontainers</groupId>
-                       <artifactId>mongodb</artifactId>
-                       <scope>test</scope>
-               </dependency>
        </dependencies>
 
        <build>
index 386c820..06b6c2d 100644 (file)
@@ -6,13 +6,16 @@ import de.juplo.kafka.chat.backend.persistence.InMemoryWithMongoDbStorageStrateg
 import de.juplo.kafka.chat.backend.persistence.storage.mongodb.ChatHomeRepository;
 import de.juplo.kafka.chat.backend.persistence.storage.mongodb.MongoDbStorageStrategy;
 import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo;
 import org.springframework.context.ApplicationContextInitializer;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.test.context.support.TestPropertySourceUtils;
-import org.testcontainers.containers.MongoDBContainer;
+import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.junit.jupiter.Container;
 import org.testcontainers.junit.jupiter.Testcontainers;
 
@@ -21,7 +24,9 @@ import java.util.function.Supplier;
 
 
 @Testcontainers
-@DataMongoTest
+@ExtendWith({SpringExtension.class})
+@EnableAutoConfiguration
+@AutoConfigureDataMongo
 @ContextConfiguration(initializers = DataSourceInitializer.class)
 @Slf4j
 public class InMemoryWithMongoDbStorageStrategyIT extends AbstractStorageStrategyIT
@@ -30,8 +35,6 @@ public class InMemoryWithMongoDbStorageStrategyIT extends AbstractStorageStrateg
   MongoDbStorageStrategy storageStrategy;
   @Autowired
   Clock clock;
-  @Autowired
-  ChatHomeRepository repository;
 
 
   @Override
@@ -47,10 +50,11 @@ public class InMemoryWithMongoDbStorageStrategyIT extends AbstractStorageStrateg
   }
 
   @Container
-  private static final MongoDBContainer mongodb =
-      new MongoDBContainer("mongo:6")
+  private static final GenericContainer mongodb =
+      new GenericContainer("mongo:6")
           .withEnv("MONGO_INITDB_ROOT_USERNAME", "mongo")
-          .withEnv("MONGO_INITDB_ROOT_PASSWORD", "mongo");
+          .withEnv("MONGO_INITDB_ROOT_PASSWORD", "mongo")
+          .withEnv("MONGO_INITDB_DATABASE", "test");
 
   public static class DataSourceInitializer
       implements ApplicationContextInitializer<ConfigurableApplicationContext>
@@ -62,9 +66,9 @@ public class InMemoryWithMongoDbStorageStrategyIT extends AbstractStorageStrateg
           applicationContext,
           "spring.data.mongodb.host=localhost",
           "spring.data.mongodb.port=27017",
-          "spring.data.mongodb.database=test",
           "spring.data.mongodb.username=mongo",
-          "spring.data.mongodb.password=mongo");
+          "spring.data.mongodb.password=mongo",
+          "spring.data.mongodb.database=test");
     }
   }
 }