|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.api.incubator.common; |
| 7 | + |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
| 9 | + |
| 10 | +import io.opentelemetry.api.common.AttributeKey; |
| 11 | +import java.util.stream.Stream; |
| 12 | +import javax.annotation.Nullable; |
| 13 | +import org.junit.jupiter.params.ParameterizedTest; |
| 14 | +import org.junit.jupiter.params.provider.Arguments; |
| 15 | +import org.junit.jupiter.params.provider.MethodSource; |
| 16 | + |
| 17 | +public class ExtendedAttributeKeyTest { |
| 18 | + |
| 19 | + @ParameterizedTest |
| 20 | + @MethodSource("attributeKeyArgs") |
| 21 | + void test( |
| 22 | + ExtendedAttributeKey<?> key, |
| 23 | + String expectedKey, |
| 24 | + ExtendedAttributeType expectedType, |
| 25 | + @Nullable AttributeKey<?> expectedAttributeKey) { |
| 26 | + assertThat(key.getKey()).isEqualTo(expectedKey); |
| 27 | + assertThat(key.getType()).isEqualTo(expectedType); |
| 28 | + assertThat(key.asAttributeKey()).isEqualTo(expectedAttributeKey); |
| 29 | + |
| 30 | + if (expectedAttributeKey != null) { |
| 31 | + ExtendedAttributeKey<?> extendedAttributeKey = |
| 32 | + ExtendedAttributeKey.fromAttributeKey(expectedAttributeKey); |
| 33 | + assertThat(extendedAttributeKey).isEqualTo(key); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + private static Stream<Arguments> attributeKeyArgs() { |
| 38 | + return Stream.of( |
| 39 | + Arguments.of( |
| 40 | + ExtendedAttributeKey.stringKey("key"), |
| 41 | + "key", |
| 42 | + ExtendedAttributeType.STRING, |
| 43 | + AttributeKey.stringKey("key")), |
| 44 | + Arguments.of( |
| 45 | + ExtendedAttributeKey.booleanKey("key"), |
| 46 | + "key", |
| 47 | + ExtendedAttributeType.BOOLEAN, |
| 48 | + AttributeKey.booleanKey("key")), |
| 49 | + Arguments.of( |
| 50 | + ExtendedAttributeKey.longKey("key"), |
| 51 | + "key", |
| 52 | + ExtendedAttributeType.LONG, |
| 53 | + AttributeKey.longKey("key")), |
| 54 | + Arguments.of( |
| 55 | + ExtendedAttributeKey.doubleKey("key"), |
| 56 | + "key", |
| 57 | + ExtendedAttributeType.DOUBLE, |
| 58 | + AttributeKey.doubleKey("key")), |
| 59 | + Arguments.of( |
| 60 | + ExtendedAttributeKey.stringArrayKey("key"), |
| 61 | + "key", |
| 62 | + ExtendedAttributeType.STRING_ARRAY, |
| 63 | + AttributeKey.stringArrayKey("key")), |
| 64 | + Arguments.of( |
| 65 | + ExtendedAttributeKey.booleanArrayKey("key"), |
| 66 | + "key", |
| 67 | + ExtendedAttributeType.BOOLEAN_ARRAY, |
| 68 | + AttributeKey.booleanArrayKey("key")), |
| 69 | + Arguments.of( |
| 70 | + ExtendedAttributeKey.longArrayKey("key"), |
| 71 | + "key", |
| 72 | + ExtendedAttributeType.LONG_ARRAY, |
| 73 | + AttributeKey.longArrayKey("key")), |
| 74 | + Arguments.of( |
| 75 | + ExtendedAttributeKey.doubleArrayKey("key"), |
| 76 | + "key", |
| 77 | + ExtendedAttributeType.DOUBLE_ARRAY, |
| 78 | + AttributeKey.doubleArrayKey("key")), |
| 79 | + Arguments.of( |
| 80 | + ExtendedAttributeKey.extendedAttributesKey("key"), |
| 81 | + "key", |
| 82 | + ExtendedAttributeType.EXTENDED_ATTRIBUTES, |
| 83 | + null)); |
| 84 | + } |
| 85 | +} |
0 commit comments