use of org.springframework.boot.actuate.health.DataSourceHealthIndicator in project spring-boot by spring-projects.
the class HealthIndicatorAutoConfigurationTests method dataSourceHealthIndicatorWithCustomValidationQuery.
@Test
public void dataSourceHealthIndicatorWithCustomValidationQuery() {
this.context.register(PropertyPlaceholderAutoConfiguration.class, ManagementServerProperties.class, DataSourceProperties.class, DataSourceConfig.class, DataSourcePoolMetadataProvidersConfiguration.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.test.validation-query:SELECT from FOOBAR", "management.health.diskspace.enabled:false");
this.context.refresh();
Map<String, HealthIndicator> beans = this.context.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
HealthIndicator healthIndicator = beans.values().iterator().next();
assertThat(healthIndicator.getClass()).isEqualTo(DataSourceHealthIndicator.class);
DataSourceHealthIndicator dataSourceHealthIndicator = (DataSourceHealthIndicator) healthIndicator;
assertThat(dataSourceHealthIndicator.getQuery()).isEqualTo("SELECT from FOOBAR");
}
Aggregations