|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
27 | 27 | import java.util.Properties;
|
28 | 28 | import java.util.Random;
|
29 | 29 | import java.util.function.Consumer;
|
| 30 | +import java.util.function.Function; |
30 | 31 | import java.util.logging.Logger;
|
31 | 32 |
|
32 | 33 | import javax.sql.DataSource;
|
@@ -143,15 +144,19 @@ public void testEmbeddedTypeDefaultsUsername() {
|
143 | 144 | });
|
144 | 145 | }
|
145 | 146 |
|
| 147 | + @Test |
| 148 | + public void dataSourceWhenNoConnectionPoolsAreAvailableWithUrlDoesNotCreateDataSource() { |
| 149 | + this.contextRunner.with(hideConnectionPools()) |
| 150 | + .run((context) -> assertThat(context).doesNotHaveBean(DataSource.class)); |
| 151 | + } |
| 152 | + |
146 | 153 | /**
|
147 | 154 | * This test makes sure that if no supported data source is present, a datasource is
|
148 | 155 | * still created if "spring.datasource.type" is present.
|
149 | 156 | */
|
150 | 157 | @Test
|
151 |
| - public void explicitTypeNoSupportedDataSource() { |
152 |
| - this.contextRunner |
153 |
| - .withClassLoader(new FilteredClassLoader("org.apache.tomcat", "com.zaxxer.hikari", |
154 |
| - "org.apache.commons.dbcp", "org.apache.commons.dbcp2")) |
| 158 | + public void dataSourceWhenNoConnectionPoolsAreAvailableWithUrlAndTypeCreatesDataSource() { |
| 159 | + this.contextRunner.with(hideConnectionPools()) |
155 | 160 | .withPropertyValues("spring.datasource.driverClassName:org.hsqldb.jdbcDriver",
|
156 | 161 | "spring.datasource.url:jdbc:hsqldb:mem:testdb",
|
157 | 162 | "spring.datasource.type:" + SimpleDriverDataSource.class.getName())
|
@@ -197,6 +202,11 @@ public void testDataSourceIsInitializedEarly() {
|
197 | 202 | .isTrue());
|
198 | 203 | }
|
199 | 204 |
|
| 205 | + private static Function<ApplicationContextRunner, ApplicationContextRunner> hideConnectionPools() { |
| 206 | + return (runner) -> runner.withClassLoader(new FilteredClassLoader("org.apache.tomcat", "com.zaxxer.hikari", |
| 207 | + "org.apache.commons.dbcp", "org.apache.commons.dbcp2")); |
| 208 | + } |
| 209 | + |
200 | 210 | private <T extends DataSource> void assertDataSource(Class<T> expectedType, List<String> hiddenPackages,
|
201 | 211 | Consumer<T> consumer) {
|
202 | 212 | FilteredClassLoader classLoader = new FilteredClassLoader(StringUtils.toStringArray(hiddenPackages));
|
|
0 commit comments