Skip to content

Commit 5fb0c4d

Browse files
committed
Improve JDBC integration tests
1 parent 6fbce6e commit 5fb0c4d

13 files changed

+403
-404
lines changed

gradle/dependency-management.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dependencyManagement {
55
mavenBom 'org.springframework:spring-framework-bom:5.1.0.RELEASE'
66
mavenBom 'org.springframework.data:spring-data-releasetrain:Lovelace-RELEASE'
77
mavenBom 'org.springframework.security:spring-security-bom:5.1.0.RELEASE'
8-
mavenBom 'org.testcontainers:testcontainers-bom:1.9.0-rc2'
8+
mavenBom 'org.testcontainers:testcontainers-bom:1.9.0'
99
}
1010

1111
dependencies {
@@ -16,6 +16,7 @@ dependencyManagement {
1616

1717
dependency 'com.h2database:h2:1.4.197'
1818
dependency 'com.microsoft.sqlserver:mssql-jdbc:7.0.0.jre8'
19+
dependency 'com.zaxxer:HikariCP:3.2.0'
1920
dependency 'edu.umd.cs.mtc:multithreadedtc:1.01'
2021
dependency 'io.lettuce:lettuce-core:5.1.0.RELEASE'
2122
dependency 'javax.annotation:javax.annotation-api:1.3.2'

spring-session-jdbc/spring-session-jdbc.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies {
1313

1414
integrationTestCompile "com.h2database:h2"
1515
integrationTestCompile "com.microsoft.sqlserver:mssql-jdbc"
16+
integrationTestCompile "com.zaxxer:HikariCP"
1617
integrationTestCompile "mysql:mysql-connector-java"
1718
integrationTestCompile "org.apache.derby:derby"
1819
integrationTestCompile "org.hsqldb:hsqldb"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2014-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.session.jdbc;
18+
19+
import javax.sql.DataSource;
20+
21+
import com.zaxxer.hikari.HikariDataSource;
22+
import org.testcontainers.containers.JdbcDatabaseContainer;
23+
24+
import org.springframework.context.annotation.Bean;
25+
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
26+
import org.springframework.jdbc.datasource.init.DatabasePopulator;
27+
28+
/**
29+
* Abstract base class for Testcontainers based {@link JdbcOperationsSessionRepository}
30+
* integration tests.
31+
*
32+
* @author Vedran Pavic
33+
*/
34+
public abstract class AbstractContainerJdbcOperationsSessionRepositoryITests
35+
extends AbstractJdbcOperationsSessionRepositoryITests {
36+
37+
static class BaseContainerConfig extends BaseConfig {
38+
39+
@Bean
40+
public HikariDataSource dataSource(JdbcDatabaseContainer databaseContainer) {
41+
HikariDataSource dataSource = new HikariDataSource();
42+
dataSource.setJdbcUrl(databaseContainer.getJdbcUrl());
43+
dataSource.setUsername(databaseContainer.getUsername());
44+
dataSource.setPassword(databaseContainer.getPassword());
45+
return dataSource;
46+
}
47+
48+
@Bean
49+
public DataSourceInitializer dataSourceInitializer(DataSource dataSource,
50+
DatabasePopulator databasePopulator) {
51+
DataSourceInitializer initializer = new DataSourceInitializer();
52+
initializer.setDataSource(dataSource);
53+
initializer.setDatabasePopulator(databasePopulator);
54+
return initializer;
55+
}
56+
57+
}
58+
59+
}

0 commit comments

Comments
 (0)