|
|
|
@ -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"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -16,12 +16,16 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.session; |
|
|
|
package org.springframework.boot.autoconfigure.session; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.Duration; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
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.AutoConfigurations; |
|
|
|
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; |
|
|
|
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; |
|
|
|
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; |
|
|
|
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.FilteredClassLoader; |
|
|
|
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; |
|
|
|
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; |
|
|
|
import org.springframework.boot.test.context.runner.ContextConsumer; |
|
|
|
import org.springframework.boot.test.context.runner.ContextConsumer; |
|
|
|
@ -38,16 +42,21 @@ import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Andy Wilkinson |
|
|
|
* @author Andy Wilkinson |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Testcontainers(disabledWithoutDocker = true) |
|
|
|
class SessionAutoConfigurationMongoTests extends AbstractSessionAutoConfigurationTests { |
|
|
|
class SessionAutoConfigurationMongoTests extends AbstractSessionAutoConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Container |
|
|
|
|
|
|
|
static final MongoDBContainer mongoDB = new MongoDBContainer().withStartupAttempts(5) |
|
|
|
|
|
|
|
.withStartupTimeout(Duration.ofMinutes(5)); |
|
|
|
|
|
|
|
|
|
|
|
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() |
|
|
|
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 |
|
|
|
@Test |
|
|
|
void defaultConfig() { |
|
|
|
void defaultConfig() { |
|
|
|
this.contextRunner.withPropertyValues("spring.session.store-type=mongodb") |
|
|
|
this.contextRunner.withPropertyValues("spring.session.store-type=mongodb") |
|
|
|
.withConfiguration(AutoConfigurations.of(EmbeddedMongoAutoConfiguration.class, |
|
|
|
|
|
|
|
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class)) |
|
|
|
|
|
|
|
.run(validateSpringSessionUsesMongo("sessions")); |
|
|
|
.run(validateSpringSessionUsesMongo("sessions")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -56,16 +65,12 @@ class SessionAutoConfigurationMongoTests extends AbstractSessionAutoConfiguratio |
|
|
|
this.contextRunner |
|
|
|
this.contextRunner |
|
|
|
.withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class, |
|
|
|
.withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class, |
|
|
|
JdbcIndexedSessionRepository.class, RedisIndexedSessionRepository.class)) |
|
|
|
JdbcIndexedSessionRepository.class, RedisIndexedSessionRepository.class)) |
|
|
|
.withConfiguration(AutoConfigurations.of(EmbeddedMongoAutoConfiguration.class, |
|
|
|
|
|
|
|
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class)) |
|
|
|
|
|
|
|
.run(validateSpringSessionUsesMongo("sessions")); |
|
|
|
.run(validateSpringSessionUsesMongo("sessions")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void mongoSessionStoreWithCustomizations() { |
|
|
|
void mongoSessionStoreWithCustomizations() { |
|
|
|
this.contextRunner |
|
|
|
this.contextRunner |
|
|
|
.withConfiguration(AutoConfigurations.of(EmbeddedMongoAutoConfiguration.class, |
|
|
|
|
|
|
|
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class)) |
|
|
|
|
|
|
|
.withPropertyValues("spring.session.store-type=mongodb", "spring.session.mongodb.collection-name=foo") |
|
|
|
.withPropertyValues("spring.session.store-type=mongodb", "spring.session.mongodb.collection-name=foo") |
|
|
|
.run(validateSpringSessionUsesMongo("foo")); |
|
|
|
.run(validateSpringSessionUsesMongo("foo")); |
|
|
|
} |
|
|
|
} |
|
|
|
|