Commit 98b0b6c4 authored by izeye's avatar izeye Committed by Stephane Nicoll

Fix MongoMetricsAutoConfigurationTests

See gh-25952
parent 719d10b6
...@@ -46,6 +46,7 @@ import static org.mockito.Mockito.mock; ...@@ -46,6 +46,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link MongoMetricsAutoConfiguration}. * Tests for {@link MongoMetricsAutoConfiguration}.
* *
* @author Chris Bono * @author Chris Bono
* @author Johnny Lim
*/ */
class MongoMetricsAutoConfigurationTests { class MongoMetricsAutoConfigurationTests {
...@@ -80,13 +81,13 @@ class MongoMetricsAutoConfigurationTests { ...@@ -80,13 +81,13 @@ class MongoMetricsAutoConfigurationTests {
@Test @Test
void whenThereIsNoMeterRegistryThenNoMetricsCommandListenerIsAdded() { void whenThereIsNoMeterRegistryThenNoMetricsCommandListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class)) this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.run((context) -> assertThatMetricsCommandListenerNotAdded()); .run(assertThatMetricsCommandListenerNotAdded());
} }
@Test @Test
void whenThereIsNoMeterRegistryThenNoMetricsConnectionPoolListenerIsAdded() { void whenThereIsNoMeterRegistryThenNoMetricsConnectionPoolListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class)) this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.run((context) -> assertThatMetricsConnectionPoolListenerNotAdded()); .run(assertThatMetricsConnectionPoolListenerNotAdded());
} }
@Test @Test
...@@ -112,44 +113,50 @@ class MongoMetricsAutoConfigurationTests { ...@@ -112,44 +113,50 @@ class MongoMetricsAutoConfigurationTests {
@Test @Test
void whenThereIsNoMongoClientSettingsOnClasspathThenNoMetricsCommandListenerIsAdded() { void whenThereIsNoMongoClientSettingsOnClasspathThenNoMetricsCommandListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class)) this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withClassLoader(new FilteredClassLoader(MongoClientSettings.class)) .withClassLoader(new FilteredClassLoader(MongoClientSettings.class))
.run((context) -> assertThatMetricsCommandListenerNotAdded()); .run(assertThatMetricsCommandListenerNotAdded());
} }
@Test @Test
void whenThereIsNoMongoClientSettingsOnClasspathThenNoMetricsConnectionPoolListenerIsAdded() { void whenThereIsNoMongoClientSettingsOnClasspathThenNoMetricsConnectionPoolListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class)) this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withClassLoader(new FilteredClassLoader(MongoClientSettings.class)) .withClassLoader(new FilteredClassLoader(MongoClientSettings.class))
.run((context) -> assertThatMetricsConnectionPoolListenerNotAdded()); .run(assertThatMetricsConnectionPoolListenerNotAdded());
} }
@Test @Test
void whenThereIsNoMongoMetricsCommandListenerOnClasspathThenNoMetricsCommandListenerIsAdded() { void whenThereIsNoMongoMetricsCommandListenerOnClasspathThenNoMetricsCommandListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class)) this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withClassLoader(new FilteredClassLoader(MongoMetricsCommandListener.class)) .withClassLoader(new FilteredClassLoader(MongoMetricsCommandListener.class))
.run((context) -> assertThatMetricsCommandListenerNotAdded()); .run(assertThatMetricsCommandListenerNotAdded());
} }
@Test @Test
void whenThereIsNoMongoMetricsConnectionPoolListenerOnClasspathThenNoMetricsConnectionPoolListenerIsAdded() { void whenThereIsNoMongoMetricsConnectionPoolListenerOnClasspathThenNoMetricsConnectionPoolListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class)) this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withClassLoader(new FilteredClassLoader(MongoMetricsConnectionPoolListener.class)) .withClassLoader(new FilteredClassLoader(MongoMetricsConnectionPoolListener.class))
.run((context) -> assertThatMetricsConnectionPoolListenerNotAdded()); .run(assertThatMetricsConnectionPoolListenerNotAdded());
} }
@Test @Test
void whenMetricsCommandListenerEnabledPropertyFalseThenNoMetricsCommandListenerIsAdded() { void whenMetricsCommandListenerEnabledPropertyFalseThenNoMetricsCommandListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class)) this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withPropertyValues("management.metrics.mongo.command.enabled:false") .withPropertyValues("management.metrics.mongo.command.enabled:false")
.run((context) -> assertThatMetricsCommandListenerNotAdded()); .run(assertThatMetricsCommandListenerNotAdded());
} }
@Test @Test
void whenMetricsConnectionPoolListenerEnabledPropertyFalseThenNoMetricsConnectionPoolListenerIsAdded() { void whenMetricsConnectionPoolListenerEnabledPropertyFalseThenNoMetricsConnectionPoolListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class)) this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withPropertyValues("management.metrics.mongo.connectionpool.enabled:false") .withPropertyValues("management.metrics.mongo.connectionpool.enabled:false")
.run((context) -> assertThatMetricsConnectionPoolListenerNotAdded()); .run(assertThatMetricsConnectionPoolListenerNotAdded());
} }
private ContextConsumer<AssertableApplicationContext> assertThatMetricsCommandListenerNotAdded() { private ContextConsumer<AssertableApplicationContext> assertThatMetricsCommandListenerNotAdded() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment