From beffc4da9f66d261a6adf012fa148bf789853625 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 10 Dec 2018 14:57:39 +0000 Subject: [PATCH] Remove ordering dependence from tests that create embedded databases Closes gh-15423 --- .../data/jdbc/JdbcRepositoriesAutoConfigurationTests.java | 6 ++++-- .../autoconfigure/flyway/FlywayAutoConfigurationTests.java | 4 +++- .../liquibase/LiquibaseAutoConfigurationTests.java | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java index dc09561173..c3742a68af 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java @@ -75,7 +75,8 @@ public class JdbcRepositoriesAutoConfigurationTests { EmbeddedDataSourceConfiguration.class) .withPropertyValues( "spring.datasource.schema=classpath:data-jdbc-schema.sql", - "spring.datasource.data=classpath:city.sql") + "spring.datasource.data=classpath:city.sql", + "spring.datasource.generate-unique-name:true") .run((context) -> { assertThat(context).hasSingleBean(JdbcConfiguration.class); assertThat(context).hasSingleBean(CityRepository.class); @@ -107,7 +108,8 @@ public class JdbcRepositoriesAutoConfigurationTests { EmbeddedDataSourceConfiguration.class) .withPropertyValues( "spring.datasource.schema=classpath:data-jdbc-schema.sql", - "spring.datasource.data=classpath:city.sql") + "spring.datasource.data=classpath:city.sql", + "spring.datasource.generate-unique-name:true") .run((context) -> { assertThat(context).hasSingleBean(JdbcConfiguration.class); assertThat(context).hasSingleBean(CityRepository.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index a850783271..b29a914126 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -20,6 +20,7 @@ import java.sql.Connection; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import javax.sql.DataSource; @@ -93,7 +94,8 @@ public class FlywayAutoConfigurationTests { @Test public void createDataSourceWithUser() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) - .withPropertyValues("spring.datasource.url:jdbc:hsqldb:mem:normal", + .withPropertyValues( + "spring.datasource.url:jdbc:hsqldb:mem:" + UUID.randomUUID(), "spring.flyway.user:sa") .run((context) -> { assertThat(context).hasSingleBean(Flyway.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index 8321b57866..7ec9bcac7d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -205,14 +205,15 @@ public class LiquibaseAutoConfigurationTests { @Test public void overrideUser() { + String jdbcUrl = "jdbc:hsqldb:mem:normal"; this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) - .withPropertyValues("spring.datasource.url:jdbc:hsqldb:mem:normal", + .withPropertyValues("spring.datasource.url:" + jdbcUrl, "spring.datasource.username:not-sa", "spring.liquibase.user:sa") .run(assertLiquibase((liquibase) -> { DataSource dataSource = liquibase.getDataSource(); assertThat(((HikariDataSource) dataSource).isClosed()).isTrue(); assertThat(((HikariDataSource) dataSource).getJdbcUrl()) - .isEqualTo("jdbc:hsqldb:mem:normal"); + .isEqualTo(jdbcUrl); assertThat(((HikariDataSource) dataSource).getUsername()) .isEqualTo("sa"); }));