-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigPropertiesBackedConfigProviderTest.java
More file actions
67 lines (53 loc) · 2.33 KB
/
Copy pathConfigPropertiesBackedConfigProviderTest.java
File metadata and controls
67 lines (53 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.config.bridge;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.incubator.config.ConfigProvider;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
class ConfigPropertiesBackedConfigProviderTest {
@Test
void testBuilderWithMappings() {
Map<String, String> properties = new HashMap<>();
properties.put("my.custom.property", "custom-value");
// ConfigProperties has "my.custom.property"
// We want to map declarative "my.declarative.prop" to "my.custom.property"
ConfigProvider provider =
ConfigPropertiesBackedConfigProvider.builder()
.addMapping("my.declarative.prop", "my.custom.property")
.build(DefaultConfigProperties.createFromMap(properties));
DeclarativeConfigProperties config = provider.getInstrumentationConfig();
// DeclarativeConfigProperties structure lookup
// pathWithName("my.declarative.prop") should map to "my.custom.property"
// However, structure is hierarchical.
// getStructured("my").getStructured("declarative").getString("prop") ->
// "my.declarative.prop"
assertThat(config.getStructured("my").getStructured("declarative").getString("prop"))
.isEqualTo("custom-value");
}
@Test
void testCreateUsesDefaults() {
// Verify that create() still supports the default mappings (e.g.
// otel.instrumentation...)
// e.g. "java.common.http.known_methods" ->
// "otel.instrumentation.http.known-methods"
Map<String, String> properties = new HashMap<>();
properties.put("otel.instrumentation.http.known-methods", "GET,POST");
ConfigProvider provider =
ConfigPropertiesBackedConfigProvider.create(
DefaultConfigProperties.createFromMap(properties));
DeclarativeConfigProperties config = provider.getInstrumentationConfig();
assertThat(
config
.getStructured("java")
.getStructured("common")
.getStructured("http")
.getString("known_methods"))
.isEqualTo("GET,POST");
}
}