|
| 1 | +/* |
| 2 | + * © SolarWinds Worldwide, LLC. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.solarwinds.opentelemetry.extensions.config; |
| 18 | + |
| 19 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 20 | +import static org.mockito.ArgumentMatchers.eq; |
| 21 | +import static org.mockito.Mockito.when; |
| 22 | + |
| 23 | +import com.solarwinds.joboe.config.ConfigManager; |
| 24 | +import com.solarwinds.joboe.config.ConfigProperty; |
| 25 | +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; |
| 26 | +import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; |
| 27 | +import io.opentelemetry.sdk.extension.incubator.ExtendedOpenTelemetrySdk; |
| 28 | +import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration; |
| 29 | +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalLanguageSpecificInstrumentationPropertyModel; |
| 30 | +import org.junit.jupiter.api.AfterAll; |
| 31 | +import org.junit.jupiter.api.Test; |
| 32 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 33 | +import org.mockito.InjectMocks; |
| 34 | +import org.mockito.Mock; |
| 35 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 36 | + |
| 37 | +@ExtendWith(MockitoExtension.class) |
| 38 | +class DeclarativeLoaderTest { |
| 39 | + |
| 40 | + @InjectMocks private DeclarativeLoader tested; |
| 41 | + |
| 42 | + @Mock private AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdkMock; |
| 43 | + |
| 44 | + @Mock private ExtendedOpenTelemetrySdk extendedOpenTelemetrySdkMock; |
| 45 | + |
| 46 | + private final ExperimentalLanguageSpecificInstrumentationPropertyModel solarwinds = |
| 47 | + new ExperimentalLanguageSpecificInstrumentationPropertyModel() |
| 48 | + .withAdditionalProperty( |
| 49 | + ConfigProperty.AGENT_SERVICE_KEY.getConfigFileKey(), "token:service") |
| 50 | + .withAdditionalProperty( |
| 51 | + ConfigProperty.AGENT_COLLECTOR.getConfigFileKey(), "apm.collector.com"); |
| 52 | + |
| 53 | + @AfterAll |
| 54 | + public static void clearConfig() { |
| 55 | + ConfigManager.reset(); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testBeforeAgent() { |
| 60 | + DeclarativeConfigProperties configProperties = |
| 61 | + DeclarativeConfiguration.toConfigProperties(solarwinds); |
| 62 | + when(autoConfiguredOpenTelemetrySdkMock.getOpenTelemetrySdk()) |
| 63 | + .thenReturn(extendedOpenTelemetrySdkMock); |
| 64 | + when(extendedOpenTelemetrySdkMock.getInstrumentationConfig(eq("solarwinds"))) |
| 65 | + .thenReturn(configProperties); |
| 66 | + tested.beforeAgent(autoConfiguredOpenTelemetrySdkMock); |
| 67 | + |
| 68 | + assertNotNull(ConfigManager.getConfig(ConfigProperty.AGENT_COLLECTOR)); |
| 69 | + assertNotNull(ConfigManager.getConfig(ConfigProperty.AGENT_SERVICE_KEY)); |
| 70 | + } |
| 71 | +} |
0 commit comments