@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"); }
@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.validation-query:SELECT from FOOBAR", "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(1, beans.size()); HealthIndicator healthIndicator = beans.values().iterator().next(); assertEquals(DataSourceHealthIndicator.class, healthIndicator.getClass()); DataSourceHealthIndicator dataSourceHealthIndicator = (DataSourceHealthIndicator) healthIndicator; assertEquals("SELECT from FOOBAR", dataSourceHealthIndicator.getQuery()); }
@Test public void dataSourceHealthIndicator() { this.context.register(EmbeddedDataSourceConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertThat(beans).hasSize(1); assertThat(beans.values().iterator().next().getClass()) .isEqualTo(DataSourceHealthIndicator.class); }
@Test public void dataSourceHealthIndicator() { this.context.register(EmbeddedDataSourceConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(1, beans.size()); assertEquals(DataSourceHealthIndicator.class, beans.values().iterator().next().getClass()); }
@Bean public HealthIndicator dbHealthIndicator(final DataSource dataSource) { DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(dataSource); indicator.setQuery("SELECT COUNT(1) id FROM mentors"); return indicator; }
@Override protected DataSourceHealthIndicator createHealthIndicator(DataSource source) { return new DataSourceHealthIndicator(source, getValidationQuery(source)); }