-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce string list attribute value getter method (#41)
- Loading branch information
1 parent
e583ecd
commit 4c4ca17
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
data-model/src/test/java/org/hypertrace/core/datamodel/shared/SpanAttributeUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.hypertrace.core.datamodel.shared; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import org.hypertrace.core.datamodel.AttributeValue; | ||
import org.hypertrace.core.datamodel.Attributes; | ||
import org.hypertrace.core.datamodel.Event; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class SpanAttributeUtilsTest { | ||
@ParameterizedTest | ||
@ValueSource(strings = {"\"Valid String\"", "[\"Valid String\"]"}) | ||
void testGetStringListAttribute(final String attributeValue) { | ||
final Event event = mock(Event.class); | ||
when(event.getAttributes()) | ||
.thenReturn( | ||
Attributes.newBuilder() | ||
.setAttributeMap( | ||
Map.of( | ||
"attributeKey", | ||
AttributeValue.newBuilder().setValue(attributeValue).build())) | ||
.build()); | ||
final List<String> result = SpanAttributeUtils.getStringListAttribute(event, "attributeKey"); | ||
assertEquals(List.of("Valid String"), result); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"Invalid JSON", "[]"}) | ||
void testGetStringListAttribute_emptyList(final String attributeValue) { | ||
final Event event = mock(Event.class); | ||
when(event.getAttributes()) | ||
.thenReturn( | ||
Attributes.newBuilder() | ||
.setAttributeMap( | ||
Map.of( | ||
"attributeKey", | ||
AttributeValue.newBuilder().setValue(attributeValue).build())) | ||
.build()); | ||
final List<String> result = SpanAttributeUtils.getStringListAttribute(event, "attributeKey"); | ||
assertEquals(emptyList(), result); | ||
} | ||
|
||
@Test | ||
void testGetStringListAttribute_multiValuedList() { | ||
final Event event = mock(Event.class); | ||
when(event.getAttributes()) | ||
.thenReturn( | ||
Attributes.newBuilder() | ||
.setAttributeMap( | ||
Map.of( | ||
"attributeKey", | ||
AttributeValue.newBuilder() | ||
.setValue("[\"value1\", \"value2\", 3]") | ||
.build())) | ||
.build()); | ||
final List<String> result = SpanAttributeUtils.getStringListAttribute(event, "attributeKey"); | ||
assertEquals(List.of("value1", "value2", "3"), result); | ||
} | ||
} |