|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.logging; |
| 7 | + |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
| 9 | + |
| 10 | +import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter; |
| 11 | +import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; |
| 12 | +import org.junit.jupiter.api.DisplayName; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | +import org.springframework.boot.autoconfigure.AutoConfigurations; |
| 15 | +import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 16 | + |
| 17 | +/** Spring Boot auto configuration test for {@link SystemOutLogRecordExporter}. */ |
| 18 | +class SystemOutLogRecordExporterAutoConfigurationTest { |
| 19 | + |
| 20 | + private final ApplicationContextRunner contextRunner = |
| 21 | + new ApplicationContextRunner() |
| 22 | + .withConfiguration( |
| 23 | + AutoConfigurations.of( |
| 24 | + OpenTelemetryAutoConfiguration.class, |
| 25 | + SystemOutLogRecordExporterAutoConfiguration.class)); |
| 26 | + |
| 27 | + @Test |
| 28 | + void loggingEnabledNew() { |
| 29 | + contextRunner |
| 30 | + .withPropertyValues("otel.logs.exporter=logging") |
| 31 | + .run( |
| 32 | + context -> |
| 33 | + assertThat( |
| 34 | + context.getBean( |
| 35 | + "otelSystemOutLogRecordExporter", SystemOutLogRecordExporter.class)) |
| 36 | + .isNotNull()); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + @DisplayName("when exporters are ENABLED should initialize SystemOutLogRecordExporter bean") |
| 41 | + void loggingEnabled() { |
| 42 | + contextRunner |
| 43 | + .withPropertyValues("otel.exporter.logging.enabled=true") |
| 44 | + .run( |
| 45 | + context -> |
| 46 | + assertThat( |
| 47 | + context.getBean( |
| 48 | + "otelSystemOutLogRecordExporter", SystemOutLogRecordExporter.class)) |
| 49 | + .isNotNull()); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + void loggingLogsEnabled() { |
| 54 | + contextRunner |
| 55 | + .withPropertyValues("otel.exporter.logging.logs.enabled=true") |
| 56 | + .run( |
| 57 | + context -> |
| 58 | + assertThat( |
| 59 | + context.getBean( |
| 60 | + "otelSystemOutLogRecordExporter", SystemOutLogRecordExporter.class)) |
| 61 | + .isNotNull()); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + @DisplayName("when exporters are DISABLED should NOT initialize SystemOutLogRecordExporter bean") |
| 66 | + void loggingDisabled() { |
| 67 | + contextRunner |
| 68 | + .withPropertyValues("otel.exporter.logging.enabled=false") |
| 69 | + .run( |
| 70 | + context -> |
| 71 | + assertThat(context.containsBean("otelSystemOutLogRecordExporter")).isFalse()); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + @DisplayName("when exporters are DISABLED should NOT initialize SystemOutLogRecordExporter bean") |
| 76 | + void loggingLogsDisabled() { |
| 77 | + contextRunner |
| 78 | + .withPropertyValues("otel.exporter.logging.logs.enabled=false") |
| 79 | + .run( |
| 80 | + context -> |
| 81 | + assertThat(context.containsBean("otelSystemOutLogRecordExporter")).isFalse()); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + @DisplayName( |
| 86 | + "when exporter enabled property is MISSING should initialize SystemOutLogRecordExporter bean") |
| 87 | + void exporterPresentByDefault() { |
| 88 | + contextRunner.run( |
| 89 | + context -> assertThat(context.containsBean("otelSystemOutLogRecordExporter")).isFalse()); |
| 90 | + } |
| 91 | +} |
0 commit comments