-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
6 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
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
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
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
43 changes: 43 additions & 0 deletions
43
...otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp/ResourceEntityTest.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,43 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.internal.otlp; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.sdk.resources.Entity; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import java.io.ByteArrayOutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ResourceEntityTest { | ||
@Test | ||
void toJsonResourceWithEntity() throws Exception { | ||
Resource resource = | ||
Resource.builder() | ||
.add( | ||
Entity.builder() | ||
.setSchemaUrl("http://example.com/1.0") | ||
.setEntityType("test") | ||
.withIdentifying(attr -> attr.put("test.id", 1)) | ||
.withDescriptive(attr -> attr.put("test.name", "one")) | ||
.build()) | ||
.build(); | ||
|
||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
try { | ||
ResourceMarshaler.create(resource).writeJsonTo(out); | ||
} finally { | ||
out.close(); | ||
} | ||
|
||
String json = new String(out.toByteArray(), StandardCharsets.UTF_8); | ||
assertThat(json) | ||
.isEqualTo( | ||
"{\"attributes\":[{\"key\":\"test.id\",\"value\":{\"intValue\":\"1\"}},{\"key\":\"test.name\",\"value\":{\"stringValue\":\"one\"}}]," | ||
+ "\"entityRefs\":[{\"schemaUrl\":\"http://example.com/1.0\",\"type\":\"test\",\"idAttrKeys\":[\"test.id\"],\"descrAttrKeys\":[\"test.name\"]}]}"); | ||
} | ||
} |