|
5 | 5 |
|
6 | 6 | package io.opentelemetry.javaagent.instrumentation.spring.gateway.v2_0; |
7 | 7 |
|
8 | | -import static org.assertj.core.api.Assertions.assertThat; |
9 | | - |
10 | | -import io.opentelemetry.api.trace.SpanKind; |
11 | 8 | import io.opentelemetry.instrumentation.spring.gateway.common.AbstractRouteMappingTest; |
12 | | -import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse; |
13 | | -import org.junit.jupiter.api.Test; |
| 9 | +import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; |
| 10 | +import java.util.List; |
14 | 11 | import org.junit.jupiter.api.extension.ExtendWith; |
15 | 12 | import org.springframework.boot.test.context.SpringBootTest; |
16 | 13 | import org.springframework.test.context.junit.jupiter.SpringExtension; |
17 | 14 |
|
18 | 15 | @ExtendWith(SpringExtension.class) |
19 | 16 | @SpringBootTest( |
20 | 17 | webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, |
21 | | - classes = { |
22 | | - GatewayTestApplication.class, |
23 | | - GatewayRouteMappingTest.ForceNettyAutoConfiguration.class |
24 | | - }) |
| 18 | + classes = {GatewayTestApplication.class}) |
25 | 19 | class GatewayRouteMappingTest extends AbstractRouteMappingTest { |
26 | 20 |
|
27 | | - @Test |
28 | | - void gatewayRouteMappingTest() { |
29 | | - String requestBody = "gateway"; |
30 | | - AggregatedHttpResponse response = client.post("/gateway/echo", requestBody).aggregate().join(); |
31 | | - assertThat(response.status().code()).isEqualTo(200); |
32 | | - assertThat(response.contentUtf8()).isEqualTo(requestBody); |
33 | | - testing.waitAndAssertTraces( |
34 | | - trace -> |
35 | | - trace.hasSpansSatisfyingExactly( |
36 | | - span -> |
37 | | - span.hasName("POST path_route") |
38 | | - .hasKind(SpanKind.SERVER) |
39 | | - .hasAttributesSatisfying( |
40 | | - buildAttributeAssertions("path_route", "h1c://mock.response", 0, 1)), |
41 | | - span -> span.hasName(WEBFLUX_SPAN_NAME).hasKind(SpanKind.INTERNAL))); |
| 21 | + @Override |
| 22 | + protected String getSpanName() { |
| 23 | + return "POST path_route"; |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + protected List<AttributeAssertion> getExpectedAttributes() { |
| 28 | + return buildAttributeAssertions("path_route", "h1c://mock.response", 0, 1); |
42 | 29 | } |
43 | 30 |
|
44 | | - @Test |
45 | | - void gatewayRandomUuidRouteMappingTest() { |
46 | | - String requestBody = "gateway"; |
47 | | - AggregatedHttpResponse response = client.post("/uuid/echo", requestBody).aggregate().join(); |
48 | | - assertThat(response.status().code()).isEqualTo(200); |
49 | | - assertThat(response.contentUtf8()).isEqualTo(requestBody); |
50 | | - testing.waitAndAssertTraces( |
51 | | - trace -> |
52 | | - trace.hasSpansSatisfyingExactly( |
53 | | - span -> |
54 | | - span.hasName("POST") |
55 | | - .hasKind(SpanKind.SERVER) |
56 | | - .hasAttributesSatisfying(buildAttributeAssertions("h1c://mock.uuid", 0, 1)), |
57 | | - span -> span.hasName(WEBFLUX_SPAN_NAME).hasKind(SpanKind.INTERNAL))); |
| 31 | + @Override |
| 32 | + protected List<AttributeAssertion> getRandomUuidExpectedAttributes() { |
| 33 | + return buildAttributeAssertions("h1c://mock.uuid", 0, 1); |
58 | 34 | } |
59 | 35 |
|
60 | | - @Test |
61 | | - void gatewayFakeUuidRouteMappingTest() { |
62 | | - String requestBody = "gateway"; |
63 | | - String routeId = "ffffffff-ffff-ffff-ffff-ffff"; |
64 | | - AggregatedHttpResponse response = client.post("/fake/echo", requestBody).aggregate().join(); |
65 | | - assertThat(response.status().code()).isEqualTo(200); |
66 | | - assertThat(response.contentUtf8()).isEqualTo(requestBody); |
67 | | - testing.waitAndAssertTraces( |
68 | | - trace -> |
69 | | - trace.hasSpansSatisfyingExactly( |
70 | | - span -> |
71 | | - span.hasName("POST " + routeId) |
72 | | - .hasKind(SpanKind.SERVER) |
73 | | - .hasAttributesSatisfying( |
74 | | - buildAttributeAssertions(routeId, "h1c://mock.fake", 0, 1)), |
75 | | - span -> span.hasName(WEBFLUX_SPAN_NAME).hasKind(SpanKind.INTERNAL))); |
| 36 | + @Override |
| 37 | + protected List<AttributeAssertion> getFakeUuidExpectedAttributes(String routeId) { |
| 38 | + return buildAttributeAssertions(routeId, "h1c://mock.fake", 0, 1); |
76 | 39 | } |
77 | 40 | } |
0 commit comments