From d5a1421bbe0e73ad4ceb31b5d728ce2bc75e4cb1 Mon Sep 17 00:00:00 2001 From: desainidhi99 <62072571+desainidhi99@users.noreply.github.com> Date: Thu, 1 Oct 2020 18:04:27 -0400 Subject: [PATCH 1/2] Deprecate EmbeddedDatabaseConnection#HSQL in favor of HSQLDB See gh-23565 --- .../boot/jdbc/EmbeddedDatabaseConnection.java | 11 ++++++++-- .../jdbc/EmbeddedDatabaseConnectionTests.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java index 3eb8505c3d..1148817a3d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java @@ -59,7 +59,14 @@ public enum EmbeddedDatabaseConnection { /** * HSQL Database Connection. */ + @Deprecated HSQL(EmbeddedDatabaseType.HSQL, DatabaseDriver.HSQLDB.getDriverClassName(), "org.hsqldb.jdbcDriver", + "jdbc:hsqldb:mem:%s"), + + /** + * HSQL Database Connection. + */ + HSQLDB(EmbeddedDatabaseType.HSQL, DatabaseDriver.HSQLDB.getDriverClassName(), "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:%s"); private final EmbeddedDatabaseType type; @@ -114,8 +121,8 @@ public enum EmbeddedDatabaseConnection { * @return true if the driver class is one of the embedded types */ public static boolean isEmbedded(String driverClass) { - return driverClass != null - && (matches(HSQL, driverClass) || matches(H2, driverClass) || matches(DERBY, driverClass)); + return driverClass != null && (matches(HSQL, driverClass) || matches(H2, driverClass) + || matches(DERBY, driverClass) || matches(HSQLDB, driverClass)); } private static boolean matches(EmbeddedDatabaseConnection candidate, String driverClass) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java index bf7511c549..45da7a7734 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java @@ -40,21 +40,42 @@ class EmbeddedDatabaseConnectionTests { .isEqualTo("jdbc:derby:memory:myderbydb;create=true"); } + @Deprecated @Test void hsqlCustomDatabaseName() { assertThat(EmbeddedDatabaseConnection.HSQL.getUrl("myhsql")).isEqualTo("jdbc:hsqldb:mem:myhsql"); } + @Deprecated @Test void getUrlWithNullDatabaseName() { assertThatIllegalArgumentException().isThrownBy(() -> EmbeddedDatabaseConnection.HSQL.getUrl(null)) .withMessageContaining("DatabaseName must not be empty"); } + @Deprecated @Test void getUrlWithEmptyDatabaseName() { assertThatIllegalArgumentException().isThrownBy(() -> EmbeddedDatabaseConnection.HSQL.getUrl(" ")) .withMessageContaining("DatabaseName must not be empty"); } +// HSQLDB connection tests added + @Test + void hsqldbCustomDatabaseName() { + assertThat(EmbeddedDatabaseConnection.HSQLDB.getUrl("myhsqldb")).isEqualTo("jdbc:hsqldb:mem:myhsqldb"); + } + + @Test + void getUrlWithNullDatabaseNameForHsqldb() { + assertThatIllegalArgumentException().isThrownBy(() -> EmbeddedDatabaseConnection.HSQLDB.getUrl(null)) + .withMessageContaining("DatabaseName must not be empty"); + } + + @Test + void getUrlWithEmptyDatabaseNameForHsqldb() { + assertThatIllegalArgumentException().isThrownBy(() -> EmbeddedDatabaseConnection.HSQLDB.getUrl(" ")) + .withMessageContaining("DatabaseName must not be empty"); + } + } From 7c22e71753fa8722b878ba9eaae44fca903f07f8 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Thu, 1 Oct 2020 16:56:48 -0700 Subject: [PATCH 2/2] Polish "Deprecate EmbeddedDatabaseConnection#HSQL" See gh-23565 --- .../boot/actuate/jdbc/DataSourceHealthIndicatorTests.java | 2 +- .../boot/actuate/liquibase/LiquibaseEndpointTests.java | 2 +- ...TestDatabaseReplaceAutoConfiguredIntegrationTests.java | 2 +- ...figureTestDatabaseReplaceExplicitIntegrationTests.java | 2 +- ...ureTestDatabaseReplacePropertyAnyIntegrationTests.java | 2 +- ...baseReplacePropertyAutoConfiguredIntegrationTests.java | 2 +- .../boot/jdbc/EmbeddedDatabaseConnection.java | 2 ++ .../boot/jdbc/EmbeddedDatabaseConnectionTests.java | 8 ++++---- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jdbc/DataSourceHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jdbc/DataSourceHealthIndicatorTests.java index 6e7352e08f..c7af6e5e1f 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jdbc/DataSourceHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/jdbc/DataSourceHealthIndicatorTests.java @@ -52,7 +52,7 @@ class DataSourceHealthIndicatorTests { @BeforeEach void init() { - EmbeddedDatabaseConnection db = EmbeddedDatabaseConnection.HSQL; + EmbeddedDatabaseConnection db = EmbeddedDatabaseConnection.HSQLDB; this.dataSource = new SingleConnectionDataSource(db.getUrl("testdb") + ";shutdown=true", "sa", "", false); this.dataSource.setDriverClassName(db.getDriverClassName()); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java index 58bf4fa26c..caf9d3c43b 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java @@ -163,7 +163,7 @@ class LiquibaseEndpointTests { private DataSource createEmbeddedDatabase() { return new EmbeddedDatabaseBuilder().generateUniqueName(true) - .setType(EmbeddedDatabaseConnection.HSQL.getType()).build(); + .setType(EmbeddedDatabaseConnection.HSQLDB.getType()).build(); } private SpringLiquibase createSpringLiquibase(String changeLog, DataSource dataSource) { diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java index 98a8ec7b56..79f9cb7c5f 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @JdbcTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.AUTO_CONFIGURED, - connection = EmbeddedDatabaseConnection.HSQL) + connection = EmbeddedDatabaseConnection.HSQLDB) class JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests { @Autowired diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java index 6804216558..ebd0c24550 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Stephane Nicoll */ @JdbcTest -@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.HSQL) +@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.HSQLDB) class JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests { @Autowired diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java index e737e2f379..88657acf12 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests.java @@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Stephane Nicoll */ @JdbcTest -@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.HSQL) +@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.HSQLDB) @TestPropertySource(properties = "spring.test.database.replace=ANY") class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAnyIntegrationTests { diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java index 2f20d40794..850f098a3b 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests.java @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Stephane Nicoll */ @JdbcTest -@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.HSQL) +@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.HSQLDB) @TestPropertySource(properties = "spring.test.database.replace=AUTO_CONFIGURED") class JdbcTestWithAutoConfigureTestDatabaseReplacePropertyAutoConfiguredIntegrationTests { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java index 1148817a3d..d879aa9ab2 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java @@ -35,6 +35,7 @@ import org.springframework.util.ClassUtils; * @author Phillip Webb * @author Dave Syer * @author Stephane Nicoll + * @author Nidhi Desai * @since 1.0.0 * @see #get(ClassLoader) */ @@ -58,6 +59,7 @@ public enum EmbeddedDatabaseConnection { /** * HSQL Database Connection. + * @deprecated since 2.4.0 in favor of {@link EmbeddedDatabaseConnection#HSQLDB}. */ @Deprecated HSQL(EmbeddedDatabaseType.HSQL, DatabaseDriver.HSQLDB.getDriverClassName(), "org.hsqldb.jdbcDriver", diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java index 45da7a7734..9155d293fe 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnectionTests.java @@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * Tests for {@link EmbeddedDatabaseConnection}. * * @author Stephane Nicoll + * @author Nidhi Desai */ class EmbeddedDatabaseConnectionTests { @@ -40,27 +41,26 @@ class EmbeddedDatabaseConnectionTests { .isEqualTo("jdbc:derby:memory:myderbydb;create=true"); } - @Deprecated @Test + @Deprecated void hsqlCustomDatabaseName() { assertThat(EmbeddedDatabaseConnection.HSQL.getUrl("myhsql")).isEqualTo("jdbc:hsqldb:mem:myhsql"); } - @Deprecated @Test + @Deprecated void getUrlWithNullDatabaseName() { assertThatIllegalArgumentException().isThrownBy(() -> EmbeddedDatabaseConnection.HSQL.getUrl(null)) .withMessageContaining("DatabaseName must not be empty"); } - @Deprecated @Test + @Deprecated void getUrlWithEmptyDatabaseName() { assertThatIllegalArgumentException().isThrownBy(() -> EmbeddedDatabaseConnection.HSQL.getUrl(" ")) .withMessageContaining("DatabaseName must not be empty"); } -// HSQLDB connection tests added @Test void hsqldbCustomDatabaseName() { assertThat(EmbeddedDatabaseConnection.HSQLDB.getUrl("myhsqldb")).isEqualTo("jdbc:hsqldb:mem:myhsqldb");