Search in sources :

Example 1 with JdbcOperationsSessionRepository

use of org.springframework.session.jdbc.JdbcOperationsSessionRepository in project spring-boot by spring-projects.

the class SessionAutoConfigurationJdbcTests method disableDatabaseInitializer.

@Test
public void disableDatabaseInitializer() {
    load(Arrays.asList(EmbeddedDataSourceConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class), "spring.session.store-type=jdbc", "spring.session.jdbc.initializer.enabled=false");
    JdbcOperationsSessionRepository repository = validateSessionRepository(JdbcOperationsSessionRepository.class);
    assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")).isEqualTo("SPRING_SESSION");
    assertThat(this.context.getBean(SessionProperties.class).getJdbc().getInitializer().isEnabled()).isFalse();
    this.thrown.expect(BadSqlGrammarException.class);
    assertThat(this.context.getBean(JdbcOperations.class).queryForList("select * from SPRING_SESSION")).isEmpty();
}
Also used : EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) JdbcOperationsSessionRepository(org.springframework.session.jdbc.JdbcOperationsSessionRepository) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) DataSourceTransactionManagerAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration) Test(org.junit.Test)

Example 2 with JdbcOperationsSessionRepository

use of org.springframework.session.jdbc.JdbcOperationsSessionRepository in project spring-boot by spring-projects.

the class SessionAutoConfigurationJdbcTests method defaultConfig.

@Test
public void defaultConfig() {
    load(Arrays.asList(EmbeddedDataSourceConfiguration.class, JdbcTemplateAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class), "spring.session.store-type=jdbc");
    JdbcOperationsSessionRepository repository = validateSessionRepository(JdbcOperationsSessionRepository.class);
    assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")).isEqualTo("SPRING_SESSION");
    assertThat(this.context.getBean(SessionProperties.class).getJdbc().getInitializer().isEnabled()).isTrue();
    assertThat(this.context.getBean(JdbcOperations.class).queryForList("select * from SPRING_SESSION")).isEmpty();
}
Also used : EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) JdbcOperationsSessionRepository(org.springframework.session.jdbc.JdbcOperationsSessionRepository) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JdbcTemplateAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) DataSourceTransactionManagerAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration) Test(org.junit.Test)

Example 3 with JdbcOperationsSessionRepository

use of org.springframework.session.jdbc.JdbcOperationsSessionRepository in project spring-boot by spring-projects.

the class SessionAutoConfigurationJdbcTests method customTableName.

@Test
public void customTableName() {
    load(Arrays.asList(EmbeddedDataSourceConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class), "spring.session.store-type=jdbc", "spring.session.jdbc.table-name=FOO_BAR", "spring.session.jdbc.schema=classpath:session/custom-schema-h2.sql");
    JdbcOperationsSessionRepository repository = validateSessionRepository(JdbcOperationsSessionRepository.class);
    assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")).isEqualTo("FOO_BAR");
    assertThat(this.context.getBean(SessionProperties.class).getJdbc().getInitializer().isEnabled()).isTrue();
    assertThat(this.context.getBean(JdbcOperations.class).queryForList("select * from FOO_BAR")).isEmpty();
}
Also used : EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) JdbcOperationsSessionRepository(org.springframework.session.jdbc.JdbcOperationsSessionRepository) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) DataSourceTransactionManagerAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration) Test(org.junit.Test)

Example 4 with JdbcOperationsSessionRepository

use of org.springframework.session.jdbc.JdbcOperationsSessionRepository in project spring-boot by spring-projects.

the class SessionAutoConfigurationJdbcTests method customTableNameWithDefaultSchemaDisablesInitializer.

@Test
public void customTableNameWithDefaultSchemaDisablesInitializer() {
    load(Arrays.asList(EmbeddedDataSourceConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class), "spring.session.store-type=jdbc", "spring.session.jdbc.table-name=FOO_BAR");
    JdbcOperationsSessionRepository repository = validateSessionRepository(JdbcOperationsSessionRepository.class);
    assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")).isEqualTo("FOO_BAR");
    assertThat(this.context.getBean(SessionProperties.class).getJdbc().getInitializer().isEnabled()).isFalse();
    this.thrown.expect(BadSqlGrammarException.class);
    assertThat(this.context.getBean(JdbcOperations.class).queryForList("select * from SPRING_SESSION")).isEmpty();
}
Also used : EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) JdbcOperationsSessionRepository(org.springframework.session.jdbc.JdbcOperationsSessionRepository) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) DataSourceTransactionManagerAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 DataSourceTransactionManagerAutoConfiguration (org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration)4 EmbeddedDataSourceConfiguration (org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration)4 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)4 JdbcOperationsSessionRepository (org.springframework.session.jdbc.JdbcOperationsSessionRepository)4 JdbcTemplateAutoConfiguration (org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration)1