This commit is contained in:
Phillip Webb
2017-01-25 16:45:59 -08:00
parent daf6be46f6
commit 2cf93f89f5
11 changed files with 28 additions and 40 deletions

View File

@@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for {@link BasicDataSourceExample}.
*
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)

View File

@@ -47,12 +47,10 @@ public class CompleteTwoDataSourcesExampleTests {
@Test
public void validateConfiguration() throws SQLException {
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(2);
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(this.context.getBean("fooDataSource")).isSameAs(dataSource);
assertThat(dataSource.getConnection().getMetaData().getURL())
.startsWith("jdbc:h2:mem:");
DataSource barDataSource = this.context.getBean("barDataSource",
DataSource.class);
assertThat(barDataSource.getConnection().getMetaData().getURL())

View File

@@ -23,8 +23,8 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
* A sample {@link SpringBootConfiguration} that only enables the auto-configuration
* for the {@link DataSource}.
* A sample {@link SpringBootConfiguration} that only enables the auto-configuration for
* the {@link DataSource}.
*
* @author Stephane Nicoll
*/

View File

@@ -38,8 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
*/
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {
"app.datasource.bar.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1",
@SpringBootTest(properties = { "app.datasource.bar.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1",
"app.datasource.bar.max-total=42" })
@Import(SimpleTwoDataSourcesExample.SimpleDataSourcesConfiguration.class)
public class SimpleTwoDataSourcesExampleTests {
@@ -50,16 +49,13 @@ public class SimpleTwoDataSourcesExampleTests {
@Test
public void validateConfiguration() throws SQLException {
assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(2);
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(this.context.getBean("fooDataSource")).isSameAs(dataSource);
assertThat(dataSource.getConnection().getMetaData().getURL())
.startsWith("jdbc:h2:mem:");
BasicDataSource barDataSource = this.context.getBean("barDataSource",
BasicDataSource.class);
assertThat(barDataSource.getUrl())
.isEqualTo("jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1");
assertThat(barDataSource.getUrl()).isEqualTo("jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1");
assertThat(barDataSource.getMaxTotal()).isEqualTo(42);
}