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] 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); } }