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

index 6992d86..66f06d4 100644 (file)
@@ -19,6 +19,7 @@ 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.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
 import org.testcontainers.junit.jupiter.Container;
 import org.testcontainers.junit.jupiter.Testcontainers;
 
@@ -75,13 +76,15 @@ public class InMemoryWithMongoDbStorageStrategyIT extends AbstractStorageStrateg
     }
   }
 
+  private static final int MONGODB_PORT = 27017;
 
   @Container
-  private static final GenericContainer mongodb =
+  private static final GenericContainer CONTAINER =
       new GenericContainer("mongo:6")
           .withEnv("MONGO_INITDB_ROOT_USERNAME", "mongo")
           .withEnv("MONGO_INITDB_ROOT_PASSWORD", "mongo")
-          .withEnv("MONGO_INITDB_DATABASE", "test");
+          .withEnv("MONGO_INITDB_DATABASE", "test")
+          .withExposedPorts(MONGODB_PORT);
 
   public static class DataSourceInitializer
       implements ApplicationContextInitializer<ConfigurableApplicationContext>
@@ -92,10 +95,12 @@ public class InMemoryWithMongoDbStorageStrategyIT extends AbstractStorageStrateg
       TestPropertySourceUtils.addInlinedPropertiesToEnvironment(
           applicationContext,
           "spring.data.mongodb.host=localhost",
-          "spring.data.mongodb.port=27017",
+          "spring.data.mongodb.port=" + CONTAINER.getMappedPort(MONGODB_PORT),
           "spring.data.mongodb.username=mongo",
           "spring.data.mongodb.password=mongo",
           "spring.data.mongodb.database=test");
-    }
+
+      Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);
+      CONTAINER.followOutput(logConsumer);    }
   }
 }