|
23 | 23 | import io.micrometer.registry.otlp.HistogramFlavor;
|
24 | 24 | import org.junit.jupiter.api.BeforeEach;
|
25 | 25 | import org.junit.jupiter.api.Test;
|
26 |
| -import uk.org.webcompere.systemstubs.SystemStubs; |
27 | 26 |
|
28 | 27 | import org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpMetricsExportAutoConfiguration.PropertiesOtlpMetricsConnectionDetails;
|
29 | 28 | import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryProperties;
|
30 | 29 | import org.springframework.mock.env.MockEnvironment;
|
31 | 30 |
|
32 | 31 | import static org.assertj.core.api.Assertions.assertThat;
|
| 32 | +import static org.mockito.BDDMockito.given; |
| 33 | +import static org.mockito.Mockito.spy; |
33 | 34 |
|
34 | 35 | /**
|
35 | 36 | * Tests for {@link OtlpMetricsPropertiesConfigAdapter}.
|
@@ -57,19 +58,16 @@ void setUp() {
|
57 | 58 |
|
58 | 59 | @Test
|
59 | 60 | void whenPropertiesUrlIsNotSetAdapterUrlReturnsDefault() {
|
| 61 | + assertThat(this.properties.getUrl()).isNull(); |
60 | 62 | assertThat(createAdapter().url()).isEqualTo("http://localhost:4318/v1/metrics");
|
61 | 63 | }
|
62 | 64 |
|
63 | 65 | @Test
|
64 |
| - void whenPropertiesUrlIsNotSetAndOtelExporterOtlpEndpointIsSetAdapterUrlUsesIt() throws Exception { |
65 |
| - SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", "https://my-endpoint") |
66 |
| - .execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics")); |
67 |
| - } |
68 |
| - |
69 |
| - @Test |
70 |
| - void whenPropertiesUrlIsNotSetAndOtelExporterOtlpMetricsEndpointIsSetAdapterUrlUsesIt() throws Exception { |
71 |
| - SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://my-endpoint") |
72 |
| - .execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics")); |
| 66 | + void whenPropertiesUrlIsNotSetThanUseOtlpConfigUrlAsFallback() { |
| 67 | + assertThat(this.properties.getUrl()).isNull(); |
| 68 | + OtlpMetricsPropertiesConfigAdapter adapter = spy(createAdapter()); |
| 69 | + given(adapter.get("management.otlp.metrics.export.url")).willReturn("https://my-endpoint/v1/metrics"); |
| 70 | + assertThat(adapter.url()).isEqualTo("https://my-endpoint/v1/metrics"); |
73 | 71 | }
|
74 | 72 |
|
75 | 73 | @Test
|
|
0 commit comments