5
5
6
6
package io .opentelemetry .javaagent .instrumentation .javalin .v5_0 ;
7
7
8
+ import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .assertThat ;
8
9
import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .equalTo ;
9
10
import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .satisfies ;
10
11
import static io .opentelemetry .semconv .HttpAttributes .HTTP_ROUTE ;
11
- import static org .junit .jupiter .api .Assertions .assertEquals ;
12
- import static org .junit .jupiter .api .Assertions .assertNotEquals ;
13
12
14
13
import io .javalin .Javalin ;
15
14
import io .opentelemetry .api .trace .SpanKind ;
@@ -42,9 +41,7 @@ class JavalinTest {
42
41
@ BeforeAll
43
42
static void setup () {
44
43
port = PortUtils .findOpenPort ();
45
-
46
44
app = TestJavalinJavaApplication .initJavalin (port );
47
-
48
45
client = WebClient .of ("http://localhost:" + port );
49
46
}
50
47
@@ -59,8 +56,8 @@ void testSpanNameAndHttpRouteSpanWithPathParamResponseSuccessful() {
59
56
AggregatedHttpResponse response = client .get ("/param/" + id ).aggregate ().join ();
60
57
String content = response .contentUtf8 ();
61
58
62
- assertNotEquals ( port , 0 );
63
- assertEquals ( content , id );
59
+ assertThat ( content ). isEqualTo ( id );
60
+ assertThat ( response . status (). code ()). isEqualTo ( 200 );
64
61
testing .waitAndAssertTraces (
65
62
trace ->
66
63
trace .hasSpansSatisfyingExactly (
@@ -91,7 +88,6 @@ void testSpanNameAndHttpRouteSpanWithPathParamResponseSuccessful() {
91
88
void testSpanNameAndHttpRouteSpanResponseError () {
92
89
client .get ("/error" ).aggregate ().join ();
93
90
94
- assertNotEquals (port , 0 );
95
91
testing .waitAndAssertTraces (
96
92
trace ->
97
93
trace .hasSpansSatisfyingExactly (
@@ -121,9 +117,9 @@ void testSpanNameAndHttpRouteSpanResponseError() {
121
117
122
118
@ Test
123
119
public void testSpanNameAndHttpRouteSpanAsyncRouteResponseSuccessful () {
124
- client .get ("/async" ).aggregate ().join ();
120
+ AggregatedHttpResponse response = client .get ("/async" ).aggregate ().join ();
125
121
126
- assertNotEquals ( port , 0 );
122
+ assertThat ( response . status (). code ()). isEqualTo ( 200 );
127
123
testing .waitAndAssertTraces (
128
124
trace ->
129
125
trace .hasSpansSatisfyingExactly (
@@ -157,22 +153,18 @@ void testHttpRouteMetricWithPathParamResponseSuccessful() {
157
153
String content = response .contentUtf8 ();
158
154
String instrumentation = "io.opentelemetry.jetty-11.0" ;
159
155
160
- assertNotEquals (port , 0 );
161
- assertEquals (content , id );
162
-
156
+ assertThat (content ).isEqualTo (id );
157
+ assertThat (response .status ().code ()).isEqualTo (200 );
163
158
testing .waitAndAssertMetrics (
164
159
instrumentation ,
165
160
"http.server.request.duration" ,
166
161
metrics ->
167
162
metrics .anySatisfy (
168
- metric -> {
169
- String metricHttpRoute =
170
- metric .getData ().getPoints ().stream ()
171
- .findFirst ()
172
- .get ()
173
- .getAttributes ()
174
- .get (HTTP_ROUTE );
175
- assertEquals ("/param/{id}" , metricHttpRoute );
176
- }));
163
+ metric ->
164
+ assertThat (metric )
165
+ .hasHistogramSatisfying (
166
+ histogram ->
167
+ histogram .hasPointsSatisfying (
168
+ point -> point .hasAttribute (HTTP_ROUTE , "/param/{id}" )))));
177
169
}
178
170
}
0 commit comments