Align New Relic and Signal FX tests with those for other exporters

Closes gh-11970
pull/12011/head
Andy Wilkinson 7 years ago
parent 384a4ed6a9
commit b0e86bd7ac

@ -17,15 +17,16 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic;
import io.micrometer.core.instrument.Clock;
import io.micrometer.influx.InfluxMeterRegistry;
import io.micrometer.newrelic.NewRelicConfig;
import io.micrometer.newrelic.NewRelicMeterRegistry;
import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import static org.assertj.core.api.Assertions.assertThat;
@ -39,29 +40,31 @@ public class NewRelicMetricsExportAutoConfigurationTests {
private final ApplicationContextRunner runner = new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(NewRelicMetricsExportAutoConfiguration.class,
MetricsAutoConfiguration.class));
AutoConfigurations.of(NewRelicMetricsExportAutoConfiguration.class));
@Test
public void backsOffWithoutAClock() {
this.runner.run((context) -> assertThat(context)
.doesNotHaveBean(InfluxMeterRegistry.class));
}
@Test
public void failsWithoutAnApiKey() {
this.runner
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.newrelic.account-id=12345")
.run((context) -> assertThat(context).hasFailed());
}
@Test
public void failsWithoutAnAccountId() {
this.runner
.withConfiguration(AutoConfigurations.of(
NewRelicMetricsExportAutoConfiguration.class,
MetricsAutoConfiguration.class))
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde")
.run((context) -> assertThat(context).hasFailed());
}
@Test
public void autoConfiguresWithAccountIdAndApiKey() {
this.runner
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde",
"management.metrics.export.newrelic.account-id=12345")
.run((context) -> assertThat(context)
@ -71,7 +74,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
@Test
public void autoConfigurationCanBeDisabled() {
this.runner
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.newrelic.enabled=false",
"management.metrics.export.newrelic.api-key=abcde",
"management.metrics.export.newrelic.account-id=12345")
@ -80,15 +83,6 @@ public class NewRelicMetricsExportAutoConfigurationTests {
.doesNotHaveBean(NewRelicConfig.class));
}
@Test
public void allowsClockToBeCustomized() {
this.runner.withUserConfiguration(CustomClockConfiguration.class)
.withPropertyValues("management.metrics.export.newrelic.api-key=abcde",
"management.metrics.export.newrelic.account-id=12345")
.run((context) -> assertThat(context).hasSingleBean(Clock.class)
.hasBean("customClock"));
}
@Test
public void allowsConfigToBeCustomized() {
this.runner.withUserConfiguration(CustomConfigConfiguration.class)
@ -109,7 +103,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
}
@Configuration
static class CustomClockConfiguration {
static class BaseConfiguration {
@Bean
public Clock customClock() {
@ -119,6 +113,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
}
@Configuration
@Import(BaseConfiguration.class)
static class CustomConfigConfiguration {
@Bean
@ -142,6 +137,7 @@ public class NewRelicMetricsExportAutoConfigurationTests {
}
@Configuration
@Import(BaseConfiguration.class)
static class CustomRegistryConfiguration {
@Bean

@ -17,15 +17,16 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx;
import io.micrometer.core.instrument.Clock;
import io.micrometer.influx.InfluxMeterRegistry;
import io.micrometer.signalfx.SignalFxConfig;
import io.micrometer.signalfx.SignalFxMeterRegistry;
import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import static org.assertj.core.api.Assertions.assertThat;
@ -38,17 +39,23 @@ public class SignalFxMetricsExportAutoConfigurationTests {
private final ApplicationContextRunner runner = new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(SignalFxMetricsExportAutoConfiguration.class,
MetricsAutoConfiguration.class));
AutoConfigurations.of(SignalFxMetricsExportAutoConfiguration.class));
@Test
public void backsOffWithoutAClock() {
this.runner.run((context) -> assertThat(context)
.doesNotHaveBean(InfluxMeterRegistry.class));
}
@Test
public void failsWithoutAnAccessToken() {
this.runner.run((context) -> assertThat(context).hasFailed());
this.runner.withUserConfiguration(BaseConfiguration.class)
.run((context) -> assertThat(context).hasFailed());
}
@Test
public void autoConfiguresWithAnAccessToken() {
this.runner
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues(
"management.metrics.export.signalfx.access-token=abcde")
.run((context) -> assertThat(context)
@ -58,7 +65,7 @@ public class SignalFxMetricsExportAutoConfigurationTests {
@Test
public void autoConfigurationCanBeDisabled() {
this.runner
this.runner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues(
"management.metrics.export.signalfx.access-token=abcde",
"management.metrics.export.signalfx.enabled=false")
@ -67,16 +74,6 @@ public class SignalFxMetricsExportAutoConfigurationTests {
.doesNotHaveBean(SignalFxConfig.class));
}
@Test
public void allowsClockToBeCustomized() {
this.runner
.withPropertyValues(
"management.metrics.export.signalfx.access-token=abcde")
.withUserConfiguration(CustomClockConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(Clock.class)
.hasBean("customClock"));
}
@Test
public void allowsConfigToBeCustomized() {
this.runner
@ -101,7 +98,7 @@ public class SignalFxMetricsExportAutoConfigurationTests {
}
@Configuration
static class CustomClockConfiguration {
static class BaseConfiguration {
@Bean
public Clock customClock() {
@ -111,6 +108,7 @@ public class SignalFxMetricsExportAutoConfigurationTests {
}
@Configuration
@Import(BaseConfiguration.class)
static class CustomConfigConfiguration {
@Bean
@ -131,6 +129,7 @@ public class SignalFxMetricsExportAutoConfigurationTests {
}
@Configuration
@Import(BaseConfiguration.class)
static class CustomRegistryConfiguration {
@Bean

Loading…
Cancel
Save