|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2012-2024 the original author or authors. |
|
|
|
|
* Copyright 2012-2025 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -20,13 +20,9 @@ import com.datastax.oss.driver.api.core.CqlSession;
@@ -20,13 +20,9 @@ import com.datastax.oss.driver.api.core.CqlSession;
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration; |
|
|
|
|
import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator; |
|
|
|
|
import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator; |
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations; |
|
|
|
|
import org.springframework.boot.test.context.FilteredClassLoader; |
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
|
|
|
|
import org.springframework.data.cassandra.core.CassandraOperations; |
|
|
|
|
import org.springframework.data.cassandra.core.ReactiveCassandraOperations; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
@ -44,41 +40,21 @@ class CassandraReactiveHealthContributorAutoConfigurationTests {
@@ -44,41 +40,21 @@ class CassandraReactiveHealthContributorAutoConfigurationTests {
|
|
|
|
|
CassandraHealthContributorAutoConfiguration.class, HealthContributorAutoConfiguration.class)); |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void runWithoutCqlSessionOrReactiveCassandraOperationsShouldNotCreateIndicator() { |
|
|
|
|
void runWithoutCqlSessionShouldNotCreateIndicator() { |
|
|
|
|
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor") |
|
|
|
|
.doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void runWithCqlSessionOnlyShouldCreateDriverIndicator() { |
|
|
|
|
void runWithCqlSessionShouldCreateIndicator() { |
|
|
|
|
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) |
|
|
|
|
.run((context) -> assertThat(context).hasBean("cassandraHealthContributor") |
|
|
|
|
.hasSingleBean(CassandraDriverReactiveHealthIndicator.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void runWithCqlSessionAndReactiveCassandraOperationsShouldCreateDriverIndicator() { |
|
|
|
|
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) |
|
|
|
|
.withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) |
|
|
|
|
.withBean(CassandraOperations.class, () -> mock(CassandraOperations.class)) |
|
|
|
|
.run((context) -> assertThat(context).hasBean("cassandraHealthContributor") |
|
|
|
|
.hasSingleBean(CassandraDriverReactiveHealthIndicator.class) |
|
|
|
|
.doesNotHaveBean(CassandraDriverHealthIndicator.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@SuppressWarnings("resource") |
|
|
|
|
void runWithCqlSessionAndSpringDataAbsentShouldCreateDriverIndicator() { |
|
|
|
|
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) |
|
|
|
|
.withClassLoader(new FilteredClassLoader("org.springframework.data")) |
|
|
|
|
.run((context) -> assertThat(context).hasBean("cassandraHealthContributor") |
|
|
|
|
.hasSingleBean(CassandraDriverReactiveHealthIndicator.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void runWhenDisabledShouldNotCreateIndicator() { |
|
|
|
|
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) |
|
|
|
|
.withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) |
|
|
|
|
.withPropertyValues("management.health.cassandra.enabled:false") |
|
|
|
|
.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor")); |
|
|
|
|
} |
|
|
|
|
|