use of org.springframework.session.jdbc.JdbcIndexedSessionRepository in project spring-boot by spring-projects.
the class SessionAutoConfigurationJdbcTests method sessionDataSourceIsUsedWhenAvailable.
@Test
void sessionDataSourceIsUsedWhenAvailable() {
this.contextRunner.withUserConfiguration(SessionDataSourceConfiguration.class).withPropertyValues("spring.session.store-type=jdbc").run((context) -> {
JdbcIndexedSessionRepository repository = validateSessionRepository(context, JdbcIndexedSessionRepository.class);
DataSource sessionDataSource = context.getBean("sessionDataSource", DataSource.class);
assertThat(repository).extracting("jdbcOperations.dataSource").isEqualTo(sessionDataSource);
assertThat(context.getBean(JdbcSessionDataSourceScriptDatabaseInitializer.class)).hasFieldOrPropertyWithValue("dataSource", sessionDataSource);
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() -> context.getBean(JdbcOperations.class).queryForList("select * from SPRING_SESSION"));
});
}
use of org.springframework.session.jdbc.JdbcIndexedSessionRepository in project spring-boot by spring-projects.
the class SessionAutoConfigurationJdbcTests method customTimeout.
@Test
void customTimeout() {
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc", "spring.session.timeout=1m").run((context) -> {
JdbcIndexedSessionRepository repository = validateSessionRepository(context, JdbcIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", 60);
});
}
use of org.springframework.session.jdbc.JdbcIndexedSessionRepository in project spring-boot by spring-projects.
the class SessionAutoConfigurationJdbcTests method validateDefaultConfig.
private void validateDefaultConfig(AssertableWebApplicationContext context) {
JdbcIndexedSessionRepository repository = validateSessionRepository(context, JdbcIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", (int) new ServerProperties().getServlet().getSession().getTimeout().getSeconds());
assertThat(repository).hasFieldOrPropertyWithValue("tableName", "SPRING_SESSION");
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema()).isEqualTo(DatabaseInitializationMode.EMBEDDED);
assertThat(context.getBean(JdbcOperations.class).queryForList("select * from SPRING_SESSION")).isEmpty();
SpringBootJdbcHttpSessionConfiguration configuration = context.getBean(SpringBootJdbcHttpSessionConfiguration.class);
assertThat(configuration).hasFieldOrPropertyWithValue("cleanupCron", "0 * * * * *");
}
use of org.springframework.session.jdbc.JdbcIndexedSessionRepository in project spring-boot by spring-projects.
the class SessionAutoConfigurationJdbcTests method disableDataSourceInitializer.
@Test
void disableDataSourceInitializer() {
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc", "spring.session.jdbc.initialize-schema=never").run((context) -> {
assertThat(context).doesNotHaveBean(JdbcSessionDataSourceScriptDatabaseInitializer.class);
JdbcIndexedSessionRepository repository = validateSessionRepository(context, JdbcIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("tableName", "SPRING_SESSION");
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema()).isEqualTo(DatabaseInitializationMode.NEVER);
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() -> context.getBean(JdbcOperations.class).queryForList("select * from SPRING_SESSION"));
});
}
use of org.springframework.session.jdbc.JdbcIndexedSessionRepository in project spring-boot by spring-projects.
the class SessionAutoConfigurationJdbcTests method customTableName.
@Test
void customTableName() {
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc", "spring.session.jdbc.table-name=FOO_BAR", "spring.session.jdbc.schema=classpath:session/custom-schema-h2.sql").run((context) -> {
JdbcIndexedSessionRepository repository = validateSessionRepository(context, JdbcIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("tableName", "FOO_BAR");
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema()).isEqualTo(DatabaseInitializationMode.EMBEDDED);
assertThat(context.getBean(JdbcOperations.class).queryForList("select * from FOO_BAR")).isEmpty();
});
}
Aggregations