3
3
import stroom .test .common .TestUtil ;
4
4
5
5
import io .vavr .Tuple ;
6
- import org .assertj .core .api .Assertions ;
7
6
import org .junit .jupiter .api .DynamicTest ;
8
7
import org .junit .jupiter .api .Test ;
9
8
import org .junit .jupiter .api .TestFactory ;
10
9
11
10
import java .io .ByteArrayInputStream ;
12
11
import java .io .IOException ;
13
12
import java .nio .charset .StandardCharsets ;
13
+ import java .time .Duration ;
14
+ import java .time .Instant ;
14
15
import java .util .Arrays ;
15
16
import java .util .Collections ;
16
17
import java .util .HashSet ;
@@ -208,7 +209,7 @@ void testEquality1() {
208
209
"FOO" , "123" ,
209
210
"BAR" , "456" ));
210
211
211
- Assertions . assertThat (attributeMap1 )
212
+ assertThat (attributeMap1 )
212
213
.isEqualTo (attributeMap2 );
213
214
}
214
215
@@ -223,7 +224,7 @@ void testEquality2() {
223
224
"FOO" , "123" ,
224
225
"BAR" , "456" ));
225
226
226
- Assertions . assertThat (attributeMap1 )
227
+ assertThat (attributeMap1 )
227
228
.isNotEqualTo (attributeMap2 );
228
229
}
229
230
@@ -239,7 +240,7 @@ void testEquality3() {
239
240
"bar" , "VALUE2" ));
240
241
241
242
// Value cases not same
242
- Assertions . assertThat (attributeMap1 )
243
+ assertThat (attributeMap1 )
243
244
.isNotEqualTo (attributeMap2 );
244
245
}
245
246
@@ -330,33 +331,118 @@ Stream<DynamicTest> testContainsValue() {
330
331
void testPut () {
331
332
final AttributeMap attributeMap1 = new AttributeMap ();
332
333
333
- Assertions . assertThat (attributeMap1 )
334
+ assertThat (attributeMap1 )
334
335
.isEmpty ();
335
336
336
337
attributeMap1 .put ("foo" , "value1a" );
337
- Assertions . assertThat (attributeMap1 )
338
+ assertThat (attributeMap1 )
338
339
.hasSize (1 );
339
- Assertions . assertThat (attributeMap1 .get ("Foo" ))
340
+ assertThat (attributeMap1 .get ("Foo" ))
340
341
.isEqualTo ("value1a" );
341
342
342
343
attributeMap1 .put ("FOO" , "value1b" ); // 'same' key, new val
343
- Assertions . assertThat (attributeMap1 )
344
+ assertThat (attributeMap1 )
344
345
.hasSize (1 );
345
- Assertions . assertThat (attributeMap1 .get ("Foo" ))
346
+ assertThat (attributeMap1 .get ("Foo" ))
346
347
.isEqualTo ("value1b" );
347
348
348
349
attributeMap1 .put ("bar" , "value2a" );
349
- Assertions . assertThat (attributeMap1 )
350
+ assertThat (attributeMap1 )
350
351
.hasSize (2 );
351
- Assertions . assertThat (attributeMap1 .get ("BAR" ))
352
+ assertThat (attributeMap1 .get ("BAR" ))
352
353
.isEqualTo ("value2a" );
353
354
}
354
355
356
+ @ Test
357
+ void testPut_withDateNormalisation () {
358
+ final AttributeMap attributeMap1 = new AttributeMap ();
359
+ final String dateStrIn = "2010-01-01T23:59:59.123456+00:00" ;
360
+ final String dateStrOut = "2010-01-01T23:59:59.123Z" ;
361
+
362
+ for (final String key : StandardHeaderArguments .DATE_HEADER_KEYS ) {
363
+ attributeMap1 .clear ();
364
+ assertThat (attributeMap1 )
365
+ .isEmpty ();
366
+
367
+ attributeMap1 .put (key , dateStrIn );
368
+
369
+ assertThat (attributeMap1 )
370
+ .hasSize (1 );
371
+
372
+ assertThat (attributeMap1 .get (key ))
373
+ .isEqualTo (dateStrOut );
374
+ }
375
+ }
376
+
377
+ @ Test
378
+ void testPutDateTime1 () {
379
+ final AttributeMap attributeMap1 = new AttributeMap ();
380
+ final String dateStrIn = "2010-01-01T23:59:59.123456+00:00" ;
381
+ final String dateStrOut = "2010-01-01T23:59:59.123Z" ;
382
+ final long epochMs = Instant .parse (dateStrIn ).toEpochMilli ();
383
+ final String key = "foo" ;
384
+
385
+ assertThat (attributeMap1 )
386
+ .isEmpty ();
387
+
388
+ attributeMap1 .putDateTime (key , epochMs );
389
+
390
+ assertThat (attributeMap1 )
391
+ .hasSize (1 );
392
+
393
+ assertThat (attributeMap1 .get (key ))
394
+ .isEqualTo (dateStrOut );
395
+ }
396
+
397
+ @ Test
398
+ void testPutDateTime2 () {
399
+ final AttributeMap attributeMap1 = new AttributeMap ();
400
+ final String dateStrIn = "2010-01-01T23:59:59.123456+00:00" ;
401
+ final String dateStrOut = "2010-01-01T23:59:59.123Z" ;
402
+ final Instant instant = Instant .parse (dateStrIn );
403
+ final String key = "foo" ;
404
+
405
+ assertThat (attributeMap1 )
406
+ .isEmpty ();
407
+
408
+ attributeMap1 .putDateTime (key , instant );
409
+
410
+ assertThat (attributeMap1 )
411
+ .hasSize (1 );
412
+
413
+ assertThat (attributeMap1 .get (key ))
414
+ .isEqualTo (dateStrOut );
415
+ }
416
+
417
+ @ Test
418
+ void testPutCurrentDateTime () {
419
+ final AttributeMap attributeMap1 = new AttributeMap ();
420
+ final String dateStrIn = "2010-01-01T23:59:59.123456+00:00" ;
421
+ final String dateStrOut = "2010-01-01T23:59:59.123Z" ;
422
+ final String key = "foo" ;
423
+
424
+ assertThat (attributeMap1 )
425
+ .isEmpty ();
426
+
427
+ final Instant now = Instant .now ();
428
+ attributeMap1 .putCurrentDateTime (key );
429
+
430
+ assertThat (attributeMap1 )
431
+ .hasSize (1 );
432
+
433
+ final String val = attributeMap1 .get (key );
434
+ assertThat (val )
435
+ .isNotNull ();
436
+ final Instant instant = Instant .parse (val );
437
+ assertThat (Duration .between (now , instant ))
438
+ .isLessThan (Duration .ofMillis (100 ));
439
+ }
440
+
355
441
@ Test
356
442
void testComputeIfAbsent1 () {
357
443
358
444
final AttributeMap attributeMap1 = new AttributeMap ();
359
- Assertions . assertThat (attributeMap1 )
445
+ assertThat (attributeMap1 )
360
446
.isEmpty ();
361
447
final AtomicInteger callCount = new AtomicInteger ();
362
448
@@ -365,9 +451,9 @@ void testComputeIfAbsent1() {
365
451
return "value(" + k + ")" ;
366
452
});
367
453
368
- Assertions . assertThat (computedVal )
454
+ assertThat (computedVal )
369
455
.isEqualTo ("value(foo)" );
370
- Assertions . assertThat (callCount )
456
+ assertThat (callCount )
371
457
.hasValue (1 );
372
458
}
373
459
@@ -376,7 +462,7 @@ void testComputeIfAbsent2() {
376
462
377
463
final AttributeMap attributeMap1 = new AttributeMap ();
378
464
attributeMap1 .put ("foo" , "value(initial)" );
379
- Assertions . assertThat (attributeMap1 )
465
+ assertThat (attributeMap1 )
380
466
.hasSize (1 );
381
467
final AtomicInteger callCount = new AtomicInteger ();
382
468
@@ -385,9 +471,9 @@ void testComputeIfAbsent2() {
385
471
return "value(" + k + ")" ;
386
472
});
387
473
388
- Assertions . assertThat (computedVal )
474
+ assertThat (computedVal )
389
475
.isEqualTo ("value(initial)" );
390
- Assertions . assertThat (callCount )
476
+ assertThat (callCount )
391
477
.hasValue (0 );
392
478
}
393
479
}
0 commit comments