|
| 1 | +package io.opentelemetry.exporter.internal; |
| 2 | + |
| 3 | +import io.opentelemetry.sdk.internal.SemConvAttributes; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | + |
| 6 | +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; |
| 7 | + |
| 8 | +public class ServerAttributesUtilTest { |
| 9 | + |
| 10 | + @Test |
| 11 | + public void invalidUrl() { |
| 12 | + assertThat(ServerAttributesUtil.extractServerAttributes("^")) |
| 13 | + .isEmpty(); |
| 14 | + } |
| 15 | + |
| 16 | + @Test |
| 17 | + public void emptyUrl() { |
| 18 | + assertThat(ServerAttributesUtil.extractServerAttributes("")) |
| 19 | + .isEmpty(); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void testHttps() { |
| 24 | + assertThat(ServerAttributesUtil.extractServerAttributes("https://example.com/foo/bar?a=b")) |
| 25 | + .hasSize(2) |
| 26 | + .containsEntry(SemConvAttributes.SERVER_ADDRESS, "example.com") |
| 27 | + .containsEntry(SemConvAttributes.SERVER_PORT, 443); |
| 28 | + |
| 29 | + assertThat(ServerAttributesUtil.extractServerAttributes("https://example.com:1234/foo/bar?a=b")) |
| 30 | + .hasSize(2) |
| 31 | + .containsEntry(SemConvAttributes.SERVER_ADDRESS, "example.com") |
| 32 | + .containsEntry(SemConvAttributes.SERVER_PORT, 1234); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testHttp() { |
| 37 | + assertThat(ServerAttributesUtil.extractServerAttributes("http://example.com/foo/bar?a=b")) |
| 38 | + .hasSize(2) |
| 39 | + .containsEntry(SemConvAttributes.SERVER_ADDRESS, "example.com") |
| 40 | + .containsEntry(SemConvAttributes.SERVER_PORT, 80); |
| 41 | + |
| 42 | + assertThat(ServerAttributesUtil.extractServerAttributes("http://example.com:1234/foo/bar?a=b")) |
| 43 | + .hasSize(2) |
| 44 | + .containsEntry(SemConvAttributes.SERVER_ADDRESS, "example.com") |
| 45 | + .containsEntry(SemConvAttributes.SERVER_PORT, 1234); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void unknownScheme() { |
| 50 | + assertThat(ServerAttributesUtil.extractServerAttributes("custom://foo")) |
| 51 | + .hasSize(1) |
| 52 | + .containsEntry(SemConvAttributes.SERVER_ADDRESS, "foo"); |
| 53 | + |
| 54 | + assertThat(ServerAttributesUtil.extractServerAttributes("custom://foo:1234")) |
| 55 | + .hasSize(2) |
| 56 | + .containsEntry(SemConvAttributes.SERVER_ADDRESS, "foo") |
| 57 | + .containsEntry(SemConvAttributes.SERVER_PORT, 1234); |
| 58 | + } |
| 59 | +} |
0 commit comments