5
5
6
6
package io .opentelemetry .sdk .testing .assertj ;
7
7
8
+ import static io .opentelemetry .api .common .AttributeKey .booleanArrayKey ;
9
+ import static io .opentelemetry .api .common .AttributeKey .booleanKey ;
10
+ import static io .opentelemetry .api .common .AttributeKey .doubleArrayKey ;
11
+ import static io .opentelemetry .api .common .AttributeKey .doubleKey ;
12
+ import static io .opentelemetry .api .common .AttributeKey .longArrayKey ;
13
+ import static io .opentelemetry .api .common .AttributeKey .longKey ;
14
+ import static io .opentelemetry .api .common .AttributeKey .stringArrayKey ;
15
+ import static io .opentelemetry .api .common .AttributeKey .stringKey ;
8
16
import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .assertThat ;
9
17
import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .attributeEntry ;
10
18
import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .equalTo ;
@@ -40,7 +48,7 @@ public class LogAssertionsTest {
40
48
private static final String TRACE_ID = "00000000000000010000000000000002" ;
41
49
private static final String SPAN_ID = "0000000000000003" ;
42
50
43
- private static final AttributeKey <String > DOG = AttributeKey . stringKey ("dog" );
51
+ private static final AttributeKey <String > DOG = stringKey ("dog" );
44
52
private static final Attributes ATTRIBUTES =
45
53
Attributes .builder ()
46
54
.put ("bear" , "mya" )
@@ -86,7 +94,7 @@ void passing() {
86
94
attributes ->
87
95
assertThat (attributes )
88
96
.hasSize (2 )
89
- .containsEntry (AttributeKey . stringKey ("dog" ), "bark" )
97
+ .containsEntry (stringKey ("dog" ), "bark" )
90
98
.hasEntrySatisfying (DOG , value -> assertThat (value ).hasSize (4 ))
91
99
.hasEntrySatisfying (
92
100
AttributeKey .booleanKey ("dog is cute" ),
@@ -125,14 +133,13 @@ void passing() {
125
133
attributes ->
126
134
OpenTelemetryAssertions .assertThat (attributes )
127
135
.hasSize (8 )
128
- .containsEntry (AttributeKey .stringKey ("bear" ), "mya" )
129
- .hasEntrySatisfying (
130
- AttributeKey .stringKey ("bear" ), value -> assertThat (value ).hasSize (3 ))
136
+ .containsEntry (stringKey ("bear" ), "mya" )
137
+ .hasEntrySatisfying (stringKey ("bear" ), value -> assertThat (value ).hasSize (3 ))
131
138
.containsEntry ("bear" , "mya" )
132
139
.containsEntry ("warm" , true )
133
140
.containsEntry ("temperature" , 30 )
134
- .containsEntry (AttributeKey . longKey ("temperature" ), 30L )
135
- .containsEntry (AttributeKey . longKey ("temperature" ), 30 )
141
+ .containsEntry (longKey ("temperature" ), 30L )
142
+ .containsEntry (longKey ("temperature" ), 30 )
136
143
.containsEntry ("length" , 1.2 )
137
144
.containsEntry ("colors" , "red" , "blue" )
138
145
.containsEntryWithStringValuesOf ("colors" , Arrays .asList ("red" , "blue" ))
@@ -142,7 +149,7 @@ void passing() {
142
149
.containsEntryWithLongValuesOf ("scores" , Arrays .asList (0L , 1L ))
143
150
.containsEntry ("coins" , 0.01 , 0.05 , 0.1 )
144
151
.containsEntryWithDoubleValuesOf ("coins" , Arrays .asList (0.01 , 0.05 , 0.1 ))
145
- .containsKey (AttributeKey . stringKey ("bear" ))
152
+ .containsKey (stringKey ("bear" ))
146
153
.containsKey ("bear" )
147
154
.containsOnly (
148
155
attributeEntry ("bear" , "mya" ),
@@ -154,12 +161,12 @@ void passing() {
154
161
attributeEntry ("scores" , 0L , 1L ),
155
162
attributeEntry ("coins" , 0.01 , 0.05 , 0.1 )))
156
163
.hasAttributesSatisfying (
157
- equalTo (AttributeKey . stringKey ("bear" ), "mya" ),
164
+ equalTo (stringKey ("bear" ), "mya" ),
158
165
equalTo (AttributeKey .booleanArrayKey ("conditions" ), Arrays .asList (false , true )))
159
166
.hasAttributesSatisfyingExactly (
160
- equalTo (AttributeKey . stringKey ("bear" ), "mya" ),
167
+ equalTo (stringKey ("bear" ), "mya" ),
161
168
equalTo (AttributeKey .booleanKey ("warm" ), true ),
162
- equalTo (AttributeKey . longKey ("temperature" ), 30L ),
169
+ equalTo (longKey ("temperature" ), 30L ),
163
170
equalTo (AttributeKey .doubleKey ("length" ), 1.2 ),
164
171
equalTo (AttributeKey .stringArrayKey ("colors" ), Arrays .asList ("red" , "blue" )),
165
172
equalTo (AttributeKey .booleanArrayKey ("conditions" ), Arrays .asList (false , true )),
@@ -235,7 +242,7 @@ void failure() {
235
242
.hasAttributesSatisfying (
236
243
attributes ->
237
244
OpenTelemetryAssertions .assertThat (attributes )
238
- .containsKey (AttributeKey . stringKey ("cat" ))))
245
+ .containsKey (stringKey ("cat" ))))
239
246
.isInstanceOf (AssertionError .class );
240
247
assertThatThrownBy (
241
248
() ->
@@ -263,21 +270,18 @@ void failure() {
263
270
attributes ->
264
271
OpenTelemetryAssertions .assertThat (attributes )
265
272
.hasEntrySatisfying (
266
- AttributeKey .stringKey ("bear" ),
267
- value -> assertThat (value ).hasSize (2 ))))
273
+ stringKey ("bear" ), value -> assertThat (value ).hasSize (2 ))))
268
274
.isInstanceOf (AssertionError .class );
269
275
assertThatThrownBy (
270
- () ->
271
- assertThat (LOG_DATA )
272
- .hasAttributesSatisfying (equalTo (AttributeKey .stringKey ("bear" ), "moo" )))
276
+ () -> assertThat (LOG_DATA ).hasAttributesSatisfying (equalTo (stringKey ("bear" ), "moo" )))
273
277
.isInstanceOf (AssertionError .class );
274
278
assertThatThrownBy (
275
279
() ->
276
280
assertThat (LOG_DATA )
277
281
.hasAttributesSatisfyingExactly (
278
- equalTo (AttributeKey . stringKey ("bear" ), "mya" ),
282
+ equalTo (stringKey ("bear" ), "mya" ),
279
283
equalTo (AttributeKey .booleanKey ("warm" ), true ),
280
- equalTo (AttributeKey . longKey ("temperature" ), 30L ),
284
+ equalTo (longKey ("temperature" ), 30L ),
281
285
equalTo (AttributeKey .doubleKey ("length" ), 1.2 )))
282
286
.isInstanceOf (AssertionError .class );
283
287
assertThatThrownBy (() -> assertThat (LOG_DATA ).hasTotalAttributeCount (11 ))
@@ -296,25 +300,41 @@ void eventBodyAssertions() {
296
300
.builder ("foo" )
297
301
.put ("foostr" , "bar" )
298
302
.put ("foobool" , true )
299
- .put ("foolong" , 12 )
303
+ .put ("foolong" , 12L )
300
304
.put ("foodbl" , 12.0 )
301
305
.put ("foostra" , "bar" , "baz" , "buzz" )
302
306
.put ("foolonga" , 9 , 0 , 2 , 1 , 0 )
303
307
.put ("foodbla" , 9.1 , 0.2 , 2.3 , 1.4 , 0.5 )
304
308
.put ("fooboola" , true , true , true , false )
305
309
.put ("fooany" , AnyValue .of ("grim" ))
310
+ .put (stringKey ("ak_str" ), "bar" )
311
+ .put (booleanKey ("ak_bool" ), true )
312
+ .put (longKey ("ak_long" ), 12L )
313
+ .put (doubleKey ("ak_dbl" ), 12.0 )
314
+ .put (stringArrayKey ("ak_stra" ), Arrays .asList ("bar" , "baz" , "buzz" ))
315
+ .put (longArrayKey ("ak_longa" ), Arrays .asList (9L , 0L , 2L , 1L , 0L ))
316
+ .put (doubleArrayKey ("ak_dbla" ), Arrays .asList (9.1 , 0.2 , 2.3 , 1.4 , 0.5 ))
317
+ .put (booleanArrayKey ("ak_boola" ), Arrays .asList (true , true , true , false ))
306
318
.emit ();
307
319
List <LogRecordData > logs = exporter .getFinishedLogRecordItems ();
308
320
assertThat (logs ).hasSize (1 );
309
321
assertThat (logs .get (0 ))
310
322
.hasBodyField ("foostr" , "bar" )
311
323
.hasBodyField ("foobool" , true )
312
- .hasBodyField ("foolong" , 12 )
324
+ .hasBodyField ("foolong" , 12L )
313
325
.hasBodyField ("foodbl" , 12.0 )
314
326
.hasBodyField ("foostra" , "bar" , "baz" , "buzz" )
315
327
.hasBodyField ("foolonga" , 9 , 0 , 2 , 1 , 0 )
316
328
.hasBodyField ("foodbla" , 9.1 , 0.2 , 2.3 , 1.4 , 0.5 )
317
329
.hasBodyField ("fooboola" , true , true , true , false )
318
- .hasBodyField ("fooany" , AnyValue .of ("grim" ));
330
+ .hasBodyField ("fooany" , AnyValue .of ("grim" ))
331
+ .hasBodyField (stringKey ("ak_str" ), "bar" )
332
+ .hasBodyField (booleanKey ("ak_bool" ), true )
333
+ .hasBodyField (longKey ("ak_long" ), 12L )
334
+ .hasBodyField (doubleKey ("ak_dbl" ), 12.0 )
335
+ .hasBodyField (stringArrayKey ("ak_stra" ), Arrays .asList ("bar" , "baz" , "buzz" ))
336
+ .hasBodyField (longArrayKey ("ak_longa" ), Arrays .asList (9L , 0L , 2L , 1L , 0L ))
337
+ .hasBodyField (doubleArrayKey ("ak_dbla" ), Arrays .asList (9.1 , 0.2 , 2.3 , 1.4 , 0.5 ))
338
+ .hasBodyField (booleanArrayKey ("ak_boola" ), Arrays .asList (true , true , true , false ));
319
339
}
320
340
}
0 commit comments