@Test public void singleTransactionManager() { load(DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class); PlatformTransactionManager transactionManager = this.context .getBean(PlatformTransactionManager.class); TransactionTemplate transactionTemplate = this.context .getBean(TransactionTemplate.class); assertThat(transactionTemplate.getTransactionManager()) .isSameAs(transactionManager); }
@Test public void defaultConfig() { load(Arrays.asList(EmbeddedDataSourceConfiguration.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(JdbcOperations.class) .queryForList("select * from SPRING_SESSION")).isEmpty(); }
@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"); this.thrown.expect(BadSqlGrammarException.class); assertThat(this.context.getBean(JdbcOperations.class) .queryForList("select * from SPRING_SESSION")).isEmpty(); }
@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(JdbcOperations.class) .queryForList("select * from FOO_BAR")).isEmpty(); }
@Test public void testDataSourceTransactionManagerNotCreated() throws Exception { this.context.register(DataSourceTransactionManagerAutoConfiguration.class); setupTestConfiguration(); this.context.refresh(); assertThat(this.context.getBean(DataSource.class)).isNotNull(); assertThat(this.context.getBean("transactionManager")) .isInstanceOf(JpaTransactionManager.class); }
@Test public void jdbcSessionStore() { load(Arrays.asList(EmbeddedDataSourceConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class), "spring.session.store-type=jdbc"); JdbcOperationsSessionRepository repository = validateSessionRepository( JdbcOperationsSessionRepository.class); assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")) .isEqualTo("SPRING_SESSION"); }
@Test public void jdbcSessionStoreCustomTableName() { 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"); }
@Test public void singleTransactionManager() { load(DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class); PlatformTransactionManager transactionManager = this.context .getBean(PlatformTransactionManager.class); TransactionTemplate transactionTemplate = this.context .getBean(TransactionTemplate.class); assertSame(transactionManager, transactionTemplate.getTransactionManager()); }
@Test public void testDataSourceTransactionManagerNotCreated() throws Exception { this.context.register(DataSourceTransactionManagerAutoConfiguration.class); setupTestConfiguration(); this.context.refresh(); assertNotNull(this.context.getBean(DataSource.class)); assertTrue(this.context .getBean("transactionManager") instanceof JpaTransactionManager); }