Fix customization of database name
Previously, the `spring.datasource.name` property was ignored when Spring Boot configures an embedded data source with a connection pool. `EmbeddedDatabaseConnection` is now aligned to the purely embedded case to take that property into account. Closes gh-4586pull/4635/head
parent
e6588dbf70
commit
9d29ab73a4
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link EmbeddedDatabaseConnection}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class EmbeddedDatabaseConnectionTests {
|
||||
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void h2CustomDatabaseName() {
|
||||
assertThat(EmbeddedDatabaseConnection.H2.getUrl("mydb"),
|
||||
is("jdbc:h2:mem:mydb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void derbyCustomDatabaseName() {
|
||||
assertThat(EmbeddedDatabaseConnection.DERBY.getUrl("myderbydb"),
|
||||
is("jdbc:derby:memory:myderbydb;create=true"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hsqlCustomDatabaseName() {
|
||||
assertThat(EmbeddedDatabaseConnection.HSQL.getUrl("myhsql"),
|
||||
is("jdbc:hsqldb:mem:myhsql"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrlWithNoDatabaseName() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
EmbeddedDatabaseConnection.H2.getUrl(" ");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue