From 7b1b18cd77c3904641709273325b77c77e0134de Mon Sep 17 00:00:00 2001 From: Leo Li <269739606@qq.com> Date: Tue, 19 Nov 2019 13:49:56 +0800 Subject: [PATCH 1/2] Add support for test containers jdbc url See gh-19044 --- .../springframework/boot/jdbc/DatabaseDriver.java | 12 ++++++++++++ .../boot/jdbc/DatabaseDriverClassNameTests.java | 6 +++--- .../boot/jdbc/DatabaseDriverTests.java | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java index fa134ddef4..3470154b5a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java @@ -196,6 +196,18 @@ public enum DatabaseDriver { return Arrays.asList("informix-sqli", "informix-direct"); } + }, + + /** + * Testcontainers. + */ + TESTCONTAINERS(null, "org.testcontainers.jdbc.ContainerDatabaseDriver") { + + @Override + protected Collection getUrlPrefixes() { + return Collections.singleton("tc"); + } + }; private final String productName; diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverClassNameTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverClassNameTests.java index 92272c0b0a..82cfbf564b 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverClassNameTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverClassNameTests.java @@ -44,9 +44,9 @@ import static org.assertj.core.api.Assertions.assertThat; */ class DatabaseDriverClassNameTests { - private static final Set EXCLUDED_DRIVERS = Collections - .unmodifiableSet(EnumSet.of(DatabaseDriver.UNKNOWN, DatabaseDriver.DB2_AS400, DatabaseDriver.INFORMIX, - DatabaseDriver.HANA, DatabaseDriver.TERADATA, DatabaseDriver.REDSHIFT)); + private static final Set EXCLUDED_DRIVERS = Collections.unmodifiableSet( + EnumSet.of(DatabaseDriver.UNKNOWN, DatabaseDriver.DB2_AS400, DatabaseDriver.INFORMIX, DatabaseDriver.HANA, + DatabaseDriver.TERADATA, DatabaseDriver.REDSHIFT, DatabaseDriver.TESTCONTAINERS)); @ParameterizedTest(name = "{0} {2}") @MethodSource diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java index ce870dfb01..7d03ae8339 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java @@ -112,6 +112,8 @@ class DatabaseDriverTests { assertThat(DatabaseDriver.fromJdbcUrl("jdbc:informix-sqli://localhost:1533/sample")) .isEqualTo(DatabaseDriver.INFORMIX); assertThat(DatabaseDriver.fromJdbcUrl("jdbc:informix-direct://sample")).isEqualTo(DatabaseDriver.INFORMIX); + assertThat(DatabaseDriver.fromJdbcUrl("jdbc:tc:sample://localhost:3306/sample")) + .isEqualTo(DatabaseDriver.TESTCONTAINERS); } } From 4c7896b936c5933e43f32208d7aa35595e9049ee Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 27 Nov 2019 11:01:56 +0100 Subject: [PATCH 2/2] Polish "Add support for test containers jdbc url" See gh-19044 --- spring-boot-project/spring-boot/pom.xml | 15 +++++++++++++++ .../boot/jdbc/DatabaseDriverClassNameTests.java | 6 +++--- .../boot/jdbc/DatabaseDriverTests.java | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot/pom.xml b/spring-boot-project/spring-boot/pom.xml index cb3d81a582..e42cf62672 100644 --- a/spring-boot-project/spring-boot/pom.xml +++ b/spring-boot-project/spring-boot/pom.xml @@ -472,6 +472,21 @@ spring-data-redis test + + org.testcontainers + jdbc + test + + + javax.annotation + javax.annotation-api + + + javax.xml.bind + jaxb-api + + + org.xerial sqlite-jdbc diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverClassNameTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverClassNameTests.java index 82cfbf564b..92272c0b0a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverClassNameTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverClassNameTests.java @@ -44,9 +44,9 @@ import static org.assertj.core.api.Assertions.assertThat; */ class DatabaseDriverClassNameTests { - private static final Set EXCLUDED_DRIVERS = Collections.unmodifiableSet( - EnumSet.of(DatabaseDriver.UNKNOWN, DatabaseDriver.DB2_AS400, DatabaseDriver.INFORMIX, DatabaseDriver.HANA, - DatabaseDriver.TERADATA, DatabaseDriver.REDSHIFT, DatabaseDriver.TESTCONTAINERS)); + private static final Set EXCLUDED_DRIVERS = Collections + .unmodifiableSet(EnumSet.of(DatabaseDriver.UNKNOWN, DatabaseDriver.DB2_AS400, DatabaseDriver.INFORMIX, + DatabaseDriver.HANA, DatabaseDriver.TERADATA, DatabaseDriver.REDSHIFT)); @ParameterizedTest(name = "{0} {2}") @MethodSource diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java index 7d03ae8339..0307a3a550 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DatabaseDriverTests.java @@ -112,7 +112,7 @@ class DatabaseDriverTests { assertThat(DatabaseDriver.fromJdbcUrl("jdbc:informix-sqli://localhost:1533/sample")) .isEqualTo(DatabaseDriver.INFORMIX); assertThat(DatabaseDriver.fromJdbcUrl("jdbc:informix-direct://sample")).isEqualTo(DatabaseDriver.INFORMIX); - assertThat(DatabaseDriver.fromJdbcUrl("jdbc:tc:sample://localhost:3306/sample")) + assertThat(DatabaseDriver.fromJdbcUrl("jdbc:tc:mysql://localhost:3306/sample")) .isEqualTo(DatabaseDriver.TESTCONTAINERS); }