Polish
This commit is contained in:
@@ -121,8 +121,8 @@ public class OAuth2RestOperationsConfigurationTests {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import({ SecurityProperties.class,
|
||||
OAuth2ClientConfiguration.class, OAuth2RestOperationsConfiguration.class })
|
||||
@Import({ SecurityProperties.class, OAuth2ClientConfiguration.class,
|
||||
OAuth2RestOperationsConfiguration.class })
|
||||
protected static class ConfigForSessionScopedConfiguration
|
||||
extends WebApplicationConfiguration {
|
||||
|
||||
|
||||
@@ -52,23 +52,22 @@ public class SessionAutoConfigurationHazelcastTests
|
||||
|
||||
@Test
|
||||
public void defaultConfig() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=hazelcast")
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=hazelcast")
|
||||
.run(this::validateDefaultConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultConfigWithUniqueStoreImplementation() {
|
||||
this.contextRunner.withClassLoader(new HideClassesClassLoader(
|
||||
JdbcOperationsSessionRepository.class,
|
||||
RedisOperationsSessionRepository.class)).run(
|
||||
this::validateDefaultConfig);
|
||||
this.contextRunner
|
||||
.withClassLoader(
|
||||
new HideClassesClassLoader(JdbcOperationsSessionRepository.class,
|
||||
RedisOperationsSessionRepository.class))
|
||||
.run(this::validateDefaultConfig);
|
||||
}
|
||||
|
||||
private void validateDefaultConfig(AssertableWebApplicationContext context) {
|
||||
validateSessionRepository(context, HazelcastSessionRepository.class);
|
||||
HazelcastInstance hazelcastInstance = context
|
||||
.getBean(HazelcastInstance.class);
|
||||
HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class);
|
||||
verify(hazelcastInstance, times(1)).getMap("spring:session:sessions");
|
||||
}
|
||||
|
||||
@@ -95,7 +94,7 @@ public class SessionAutoConfigurationHazelcastTests
|
||||
context, HazelcastSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository)
|
||||
.getPropertyValue("hazelcastFlushMode"))
|
||||
.isEqualTo(HazelcastFlushMode.IMMEDIATE);
|
||||
.isEqualTo(HazelcastFlushMode.IMMEDIATE);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -46,32 +46,32 @@ public class SessionAutoConfigurationIntegrationTests
|
||||
SessionAutoConfiguration.class))
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true");
|
||||
|
||||
|
||||
@Test
|
||||
public void severalCandidatesWithNoSessionStore() {
|
||||
this.contextRunner.withUserConfiguration(HazelcastConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure()
|
||||
.hasCauseInstanceOf(NonUniqueSessionRepositoryException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"Multiple session repository candidates are available");
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"set the 'spring.session.store-type' property accordingly");
|
||||
});
|
||||
this.contextRunner.withUserConfiguration(HazelcastConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().hasCauseInstanceOf(
|
||||
NonUniqueSessionRepositoryException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"Multiple session repository candidates are available");
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"set the 'spring.session.store-type' property accordingly");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalCandidatesWithWrongSessionStore() {
|
||||
this.contextRunner.withUserConfiguration(HazelcastConfiguration.class)
|
||||
.withPropertyValues("spring.session.store-type=redis").run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure()
|
||||
.hasCauseInstanceOf(SessionRepositoryUnavailableException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"No session repository could be auto-configured");
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"session store type is 'redis'");
|
||||
});
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().hasCauseInstanceOf(
|
||||
SessionRepositoryUnavailableException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"No session repository could be auto-configured");
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("session store type is 'redis'");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +82,6 @@ public class SessionAutoConfigurationIntegrationTests
|
||||
JdbcOperationsSessionRepository.class));
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class HazelcastConfiguration {
|
||||
|
||||
|
||||
@@ -58,8 +58,7 @@ public class SessionAutoConfigurationJdbcTests
|
||||
|
||||
@Test
|
||||
public void defaultConfig() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=jdbc")
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc")
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(JdbcTemplateAutoConfiguration.class))
|
||||
.run(this::validateDefaultConfig);
|
||||
@@ -68,22 +67,20 @@ public class SessionAutoConfigurationJdbcTests
|
||||
@Test
|
||||
public void defaultConfigWithUniqueStoreImplementation() {
|
||||
this.contextRunner
|
||||
.withClassLoader(new HideClassesClassLoader(
|
||||
HazelcastSessionRepository.class,
|
||||
RedisOperationsSessionRepository.class)
|
||||
)
|
||||
.withClassLoader(
|
||||
new HideClassesClassLoader(HazelcastSessionRepository.class,
|
||||
RedisOperationsSessionRepository.class))
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(JdbcTemplateAutoConfiguration.class))
|
||||
.run(this::validateDefaultConfig);
|
||||
}
|
||||
|
||||
private void validateDefaultConfig(AssertableWebApplicationContext context) {
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(
|
||||
context, JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository)
|
||||
.getPropertyValue("tableName")).isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class)
|
||||
.getInitializeSchema())
|
||||
JdbcOperationsSessionRepository repository = validateSessionRepository(context,
|
||||
JdbcOperationsSessionRepository.class);
|
||||
assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName"))
|
||||
.isEqualTo("SPRING_SESSION");
|
||||
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
assertThat(context.getBean(JdbcOperations.class)
|
||||
.queryForList("select * from SPRING_SESSION")).isEmpty();
|
||||
|
||||
@@ -50,8 +50,7 @@ public class SessionAutoConfigurationRedisTests
|
||||
|
||||
@Test
|
||||
public void defaultConfig() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.session.store-type=redis")
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=redis")
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.run(validateSpringSessionUsesRedis("spring:session:event:created:",
|
||||
RedisFlushMode.ON_SAVE));
|
||||
@@ -60,9 +59,9 @@ public class SessionAutoConfigurationRedisTests
|
||||
@Test
|
||||
public void defaultConfigWithUniqueStoreImplementation() {
|
||||
this.contextRunner
|
||||
.withClassLoader(new HideClassesClassLoader(
|
||||
HazelcastSessionRepository.class,
|
||||
JdbcOperationsSessionRepository.class))
|
||||
.withClassLoader(
|
||||
new HideClassesClassLoader(HazelcastSessionRepository.class,
|
||||
JdbcOperationsSessionRepository.class))
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.run(validateSpringSessionUsesRedis("spring:session:event:created:",
|
||||
RedisFlushMode.ON_SAVE));
|
||||
|
||||
@@ -66,12 +66,12 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
||||
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure()
|
||||
.hasCauseInstanceOf(SessionRepositoryUnavailableException.class);
|
||||
assertThat(context).getFailure().hasCauseInstanceOf(
|
||||
SessionRepositoryUnavailableException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"No session repository could be auto-configured");
|
||||
assertThat(context).getFailure().hasMessageContaining(
|
||||
"session store type is 'jdbc'");
|
||||
assertThat(context).getFailure()
|
||||
.hasMessageContaining("session store type is 'jdbc'");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,18 +86,17 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
|
||||
public void backOffIfSessionRepositoryIsPresent() {
|
||||
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
|
||||
.withPropertyValues("spring.session.store-type=redis").run((context) -> {
|
||||
MapSessionRepository repository = validateSessionRepository(context,
|
||||
MapSessionRepository.class);
|
||||
assertThat(context).getBean("mySessionRepository")
|
||||
.isSameAs(repository);
|
||||
});
|
||||
MapSessionRepository repository = validateSessionRepository(context,
|
||||
MapSessionRepository.class);
|
||||
assertThat(context).getBean("mySessionRepository")
|
||||
.isSameAs(repository);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springSessionTimeoutIsNotAValidProperty() {
|
||||
this.contextRunner.withUserConfiguration(SessionRepositoryConfiguration.class)
|
||||
.withPropertyValues("spring.session.timeout=3000")
|
||||
.run((context) -> {
|
||||
.withPropertyValues("spring.session.timeout=3000").run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure()
|
||||
.isInstanceOf(BeanCreationException.class);
|
||||
|
||||
Reference in New Issue
Block a user