|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic;
|
18 | 18 |
|
19 | 19 | import io.micrometer.core.instrument.Clock;
|
| 20 | +import io.micrometer.newrelic.NewRelicClientProvider; |
20 | 21 | import io.micrometer.newrelic.NewRelicConfig;
|
21 | 22 | import io.micrometer.newrelic.NewRelicMeterRegistry;
|
22 | 23 | import org.junit.jupiter.api.Test;
|
|
28 | 29 | import org.springframework.context.annotation.Import;
|
29 | 30 |
|
30 | 31 | import static org.assertj.core.api.Assertions.assertThat;
|
| 32 | +import static org.mockito.Mockito.mock; |
31 | 33 |
|
32 | 34 | /**
|
33 | 35 | *
|
34 | 36 | * Tests for {@link NewRelicMetricsExportAutoConfiguration}.
|
35 | 37 | *
|
36 | 38 | * @author Andy Wilkinson
|
| 39 | + * @author Stephane Nicoll |
37 | 40 | */
|
38 | 41 | class NewRelicMetricsExportAutoConfigurationTests {
|
39 | 42 |
|
@@ -69,7 +72,7 @@ void failsToAutoConfigureWithoutEventType() {
|
69 | 72 | }
|
70 | 73 |
|
71 | 74 | @Test
|
72 |
| - void autoConfiguresWithEventTypeOverriden() { |
| 75 | + void autoConfiguresWithEventTypeOverridden() { |
73 | 76 | this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
74 | 77 | .withPropertyValues("management.metrics.export.newrelic.api-key=abcde",
|
75 | 78 | "management.metrics.export.newrelic.account-id=12345",
|
@@ -123,6 +126,18 @@ void allowsRegistryToBeCustomized() {
|
123 | 126 | .hasBean("customRegistry"));
|
124 | 127 | }
|
125 | 128 |
|
| 129 | + @Test |
| 130 | + void allowsClientProviderToBeCustomized() { |
| 131 | + this.contextRunner.withUserConfiguration(CustomClientProviderConfiguration.class) |
| 132 | + .withPropertyValues("management.metrics.export.newrelic.api-key=abcde", |
| 133 | + "management.metrics.export.newrelic.account-id=12345") |
| 134 | + .run((context) -> { |
| 135 | + assertThat(context).hasSingleBean(NewRelicMeterRegistry.class); |
| 136 | + assertThat(context.getBean(NewRelicMeterRegistry.class)) |
| 137 | + .hasFieldOrPropertyWithValue("clientProvider", context.getBean("customClientProvider")); |
| 138 | + }); |
| 139 | + } |
| 140 | + |
126 | 141 | @Test
|
127 | 142 | void stopsMeterRegistryWhenContextIsClosed() {
|
128 | 143 | this.contextRunner
|
@@ -176,4 +191,15 @@ NewRelicMeterRegistry customRegistry(NewRelicConfig config, Clock clock) {
|
176 | 191 |
|
177 | 192 | }
|
178 | 193 |
|
| 194 | + @Configuration(proxyBeanMethods = false) |
| 195 | + @Import(BaseConfiguration.class) |
| 196 | + static class CustomClientProviderConfiguration { |
| 197 | + |
| 198 | + @Bean |
| 199 | + NewRelicClientProvider customClientProvider() { |
| 200 | + return mock(NewRelicClientProvider.class); |
| 201 | + } |
| 202 | + |
| 203 | + } |
| 204 | + |
179 | 205 | }
|
0 commit comments