|
|
|
|
@ -17,11 +17,13 @@
@@ -17,11 +17,13 @@
|
|
|
|
|
package org.springframework.boot.autoconfigure.h2; |
|
|
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource; |
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
|
|
import org.mockito.BDDMockito; |
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeansException; |
|
|
|
|
import org.springframework.beans.factory.BeanCreationException; |
|
|
|
|
@ -31,8 +33,11 @@ import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
@@ -31,8 +33,11 @@ import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
|
|
|
|
import org.springframework.boot.test.system.CapturedOutput; |
|
|
|
|
import org.springframework.boot.test.system.OutputCaptureExtension; |
|
|
|
|
import org.springframework.boot.web.servlet.ServletRegistrationBean; |
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Tests for {@link H2ConsoleAutoConfiguration} |
|
|
|
|
@ -117,4 +122,25 @@ class H2ConsoleAutoConfigurationTests {
@@ -117,4 +122,25 @@ class H2ConsoleAutoConfigurationTests {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void testDataSource() { |
|
|
|
|
this.contextRunner.withUserConfiguration(DataSourceAvailable.class) |
|
|
|
|
.withPropertyValues("spring.h2.console.enabled=true").run((context) -> { |
|
|
|
|
assertThat(context.isRunning()).isTrue(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false) |
|
|
|
|
static class DataSourceAvailable { |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public DataSource dataSource() throws SQLException { |
|
|
|
|
DataSource dataSource = mock(DataSource.class); |
|
|
|
|
BDDMockito.when(dataSource.getConnection()).thenThrow(IllegalStateException.class); |
|
|
|
|
return dataSource; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|