|  | 
| 16 | 16 | 
 | 
| 17 | 17 | package org.springframework.boot.actuate.autoconfigure.cassandra; | 
| 18 | 18 | 
 | 
|  | 19 | +import com.datastax.oss.driver.api.core.CqlSession; | 
| 19 | 20 | import org.junit.jupiter.api.Test; | 
| 20 | 21 | 
 | 
| 21 |  | -import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorAutoConfigurationTests.CassandraConfiguration; | 
| 22 | 22 | import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration; | 
|  | 23 | +import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator; | 
|  | 24 | +import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator; | 
| 23 | 25 | import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator; | 
| 24 | 26 | import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator; | 
| 25 | 27 | import org.springframework.boot.autoconfigure.AutoConfigurations; | 
|  | 28 | +import org.springframework.boot.test.context.FilteredClassLoader; | 
| 26 | 29 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; | 
|  | 30 | +import org.springframework.data.cassandra.core.CassandraOperations; | 
| 27 | 31 | import org.springframework.data.cassandra.core.ReactiveCassandraOperations; | 
| 28 | 32 | 
 | 
| 29 | 33 | import static org.assertj.core.api.Assertions.assertThat; | 
|  | 
| 37 | 41 |  */ | 
| 38 | 42 | class CassandraReactiveHealthContributorAutoConfigurationTests { | 
| 39 | 43 | 
 | 
| 40 |  | -	private ApplicationContextRunner contextRunner = new ApplicationContextRunner() | 
| 41 |  | -			.withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) | 
|  | 44 | +	private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() | 
| 42 | 45 | 			.withConfiguration(AutoConfigurations.of(CassandraReactiveHealthContributorAutoConfiguration.class, | 
| 43 |  | -					HealthContributorAutoConfiguration.class)); | 
|  | 46 | +					CassandraHealthContributorAutoConfiguration.class, HealthContributorAutoConfiguration.class)); | 
| 44 | 47 | 
 | 
| 45 | 48 | 	@Test | 
| 46 |  | -	void runShouldCreateIndicator() { | 
| 47 |  | -		this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class) | 
| 48 |  | -				.hasBean("cassandraHealthContributor")); | 
|  | 49 | +	void runWithoutCqlSessionOrReactiveCassandraOperationsShouldNotCreateIndicator() { | 
|  | 50 | +		this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor") | 
|  | 51 | +				.doesNotHaveBean(CassandraReactiveHealthIndicator.class) | 
|  | 52 | +				.doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class)); | 
| 49 | 53 | 	} | 
| 50 | 54 | 
 | 
| 51 | 55 | 	@Test | 
| 52 |  | -	void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() { | 
| 53 |  | -		this.contextRunner | 
| 54 |  | -				.withConfiguration(AutoConfigurations.of(CassandraConfiguration.class, | 
| 55 |  | -						CassandraHealthContributorAutoConfiguration.class)) | 
| 56 |  | -				.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class) | 
| 57 |  | -						.hasBean("cassandraHealthContributor").doesNotHaveBean(CassandraHealthIndicator.class)); | 
|  | 56 | +	void runWithReactiveCassandraOperationsShouldOnlyCreateReactiveIndicator() { | 
|  | 57 | +		this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) | 
|  | 58 | +				.withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) | 
|  | 59 | +				.withBean(CassandraOperations.class, () -> mock(CassandraOperations.class)) | 
|  | 60 | +				.run((context) -> assertThat(context).hasBean("cassandraHealthContributor") | 
|  | 61 | +						.hasSingleBean(CassandraReactiveHealthIndicator.class) | 
|  | 62 | +						.doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class) | 
|  | 63 | +						.doesNotHaveBean(CassandraHealthIndicator.class) | 
|  | 64 | +						.doesNotHaveBean(CassandraDriverHealthIndicator.class)); | 
|  | 65 | +	} | 
|  | 66 | + | 
|  | 67 | +	@Test | 
|  | 68 | +	void runWithCqlSessionShouldCreateDriverIndicator() { | 
|  | 69 | +		this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) | 
|  | 70 | +				.run((context) -> assertThat(context).hasBean("cassandraHealthContributor") | 
|  | 71 | +						.hasSingleBean(CassandraDriverReactiveHealthIndicator.class) | 
|  | 72 | +						.doesNotHaveBean(CassandraReactiveHealthIndicator.class)); | 
|  | 73 | +	} | 
|  | 74 | + | 
|  | 75 | +	@Test | 
|  | 76 | +	void runWithCqlSessionAndSpringDataAbsentShouldACreateDriverIndicator() { | 
|  | 77 | +		this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) | 
|  | 78 | +				.withClassLoader(new FilteredClassLoader("org.springframework.data")) | 
|  | 79 | +				.run((context) -> assertThat(context).hasBean("cassandraHealthContributor") | 
|  | 80 | +						.hasSingleBean(CassandraDriverReactiveHealthIndicator.class) | 
|  | 81 | +						.doesNotHaveBean(CassandraReactiveHealthIndicator.class)); | 
| 58 | 82 | 	} | 
| 59 | 83 | 
 | 
| 60 | 84 | 	@Test | 
| 61 | 85 | 	void runWhenDisabledShouldNotCreateIndicator() { | 
| 62 |  | -		this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false") | 
| 63 |  | -				.run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class) | 
| 64 |  | -						.doesNotHaveBean("cassandraHealthContributor")); | 
|  | 86 | +		this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) | 
|  | 87 | +				.withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) | 
|  | 88 | +				.withPropertyValues("management.health.cassandra.enabled:false") | 
|  | 89 | +				.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor") | 
|  | 90 | +						.doesNotHaveBean(CassandraReactiveHealthIndicator.class)); | 
| 65 | 91 | 	} | 
| 66 | 92 | 
 | 
| 67 | 93 | } | 
0 commit comments