Default spring.datasource.generate-unique-name to true
This change ensures that each test in a test suite that shares an application context gets a unique embedded database, to prevent inconsistent embedded database state between tests. Closes gh-16747
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,6 +44,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Stephane Nicoll
|
||||
* @author Benedikt Ritter
|
||||
* @author Eddú Meléndez
|
||||
* @author Scott Frederick
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.datasource")
|
||||
@@ -59,7 +60,7 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
|
||||
/**
|
||||
* Whether to generate a random datasource name.
|
||||
*/
|
||||
private boolean generateUniqueName;
|
||||
private boolean generateUniqueName = true;
|
||||
|
||||
/**
|
||||
* Fully qualified name of the connection pool implementation to use. By default, it
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Maciej Walkowiak
|
||||
* @author Stephane Nicoll
|
||||
* @author Eddú Meléndez
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
class DataSourcePropertiesTests {
|
||||
|
||||
@@ -51,8 +52,9 @@ class DataSourcePropertiesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void determineUrl() throws Exception {
|
||||
void determineUrlWithoutGenerateUniqueName() throws Exception {
|
||||
DataSourceProperties properties = new DataSourceProperties();
|
||||
properties.setGenerateUniqueName(false);
|
||||
properties.afterPropertiesSet();
|
||||
assertThat(properties.getUrl()).isNull();
|
||||
assertThat(properties.determineUrl()).isEqualTo(EmbeddedDatabaseConnection.H2.getUrl("testdb"));
|
||||
@@ -79,7 +81,6 @@ class DataSourcePropertiesTests {
|
||||
@Test
|
||||
void determineUrlWithGenerateUniqueName() throws Exception {
|
||||
DataSourceProperties properties = new DataSourceProperties();
|
||||
properties.setGenerateUniqueName(true);
|
||||
properties.afterPropertiesSet();
|
||||
assertThat(properties.determineUrl()).isEqualTo(properties.determineUrl());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user