diff --git a/spring-boot-project/spring-boot-autoconfigure/pom.xml b/spring-boot-project/spring-boot-autoconfigure/pom.xml
index b54887fd6e..08d93feecf 100755
--- a/spring-boot-project/spring-boot-autoconfigure/pom.xml
+++ b/spring-boot-project/spring-boot-autoconfigure/pom.xml
@@ -993,6 +993,11 @@
junit-jupiter
test
+
+ org.testcontainers
+ mongodb
+ test
+
org.testcontainers
testcontainers
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationMongoTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationMongoTests.java
index 982bbb8a7e..919a83cae2 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationMongoTests.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationMongoTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,16 @@
package org.springframework.boot.autoconfigure.session;
+import java.time.Duration;
+
import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.MongoDBContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
-import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
import org.springframework.boot.test.context.runner.ContextConsumer;
@@ -38,16 +42,21 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
+@Testcontainers(disabledWithoutDocker = true)
class SessionAutoConfigurationMongoTests extends AbstractSessionAutoConfigurationTests {
+ @Container
+ static final MongoDBContainer mongoDB = new MongoDBContainer().withStartupAttempts(5)
+ .withStartupTimeout(Duration.ofMinutes(5));
+
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
- .withConfiguration(AutoConfigurations.of(SessionAutoConfiguration.class));
+ .withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
+ SessionAutoConfiguration.class))
+ .withPropertyValues("spring.data.mongodb.uri=" + mongoDB.getReplicaSetUrl());
@Test
void defaultConfig() {
this.contextRunner.withPropertyValues("spring.session.store-type=mongodb")
- .withConfiguration(AutoConfigurations.of(EmbeddedMongoAutoConfiguration.class,
- MongoAutoConfiguration.class, MongoDataAutoConfiguration.class))
.run(validateSpringSessionUsesMongo("sessions"));
}
@@ -56,16 +65,12 @@ class SessionAutoConfigurationMongoTests extends AbstractSessionAutoConfiguratio
this.contextRunner
.withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class,
JdbcIndexedSessionRepository.class, RedisIndexedSessionRepository.class))
- .withConfiguration(AutoConfigurations.of(EmbeddedMongoAutoConfiguration.class,
- MongoAutoConfiguration.class, MongoDataAutoConfiguration.class))
.run(validateSpringSessionUsesMongo("sessions"));
}
@Test
void mongoSessionStoreWithCustomizations() {
this.contextRunner
- .withConfiguration(AutoConfigurations.of(EmbeddedMongoAutoConfiguration.class,
- MongoAutoConfiguration.class, MongoDataAutoConfiguration.class))
.withPropertyValues("spring.session.store-type=mongodb", "spring.session.mongodb.collection-name=foo")
.run(validateSpringSessionUsesMongo("foo"));
}