1
+ package org .jboss .pnc .dingrogu .common ;
2
+
3
+ import org .jboss .pnc .api .constants .MDCHeaderKeys ;
4
+ import org .jboss .pnc .api .dto .Request ;
5
+ import org .junit .jupiter .api .Test ;
6
+ import org .slf4j .MDC ;
7
+
8
+ import java .util .List ;
9
+ import java .util .Map ;
10
+ import java .util .Optional ;
11
+
12
+ import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
13
+ import static org .junit .jupiter .api .Assertions .*;
14
+
15
+ class TaskHelperTest {
16
+
17
+ @ Test
18
+ void getHTTPHeadersBasic () {
19
+ List <Request .Header > headers = TaskHelper .getHTTPHeaders ();
20
+
21
+ Optional <Request .Header > headerContentType = headers .stream ()
22
+ .filter (header -> header .getName ().equals ("Content-Type" ))
23
+ .findAny ();
24
+ assertThat (headerContentType ).isPresent ();
25
+
26
+ Optional <Request .Header > headerAccept = headers .stream ()
27
+ .filter (header -> header .getName ().equals ("Accept" ))
28
+ .findAny ();
29
+ assertThat (headerAccept ).isPresent ();
30
+ }
31
+
32
+ @ Test
33
+ void getHttpHeadersWithMdc () {
34
+ Map <String , String > contextMap = Map .of (
35
+ MDCHeaderKeys .USER_ID .getMdcKey (),
36
+ "dustin" ,
37
+ MDCHeaderKeys .PROCESS_CONTEXT .getMdcKey (),
38
+ "process-context" );
39
+ MDC .setContextMap (contextMap );
40
+ List <Request .Header > headers = TaskHelper .getHTTPHeaders ();
41
+ Optional <Request .Header > headerUserId = headers .stream ()
42
+ .filter (header -> header .getName ().equals (MDCHeaderKeys .USER_ID .getHeaderName ()))
43
+ .findAny ();
44
+ assertThat (headerUserId ).isPresent ();
45
+ assertThat (headerUserId .get ().getValue ()).isEqualTo ("dustin" );
46
+
47
+ Optional <Request .Header > headerProcessContext = headers .stream ()
48
+ .filter (header -> header .getName ().equals (MDCHeaderKeys .PROCESS_CONTEXT .getHeaderName ()))
49
+ .findAny ();
50
+ assertThat (headerProcessContext ).isPresent ();
51
+ assertThat (headerProcessContext .get ().getValue ()).isEqualTo ("process-context" );
52
+ }
53
+ }
0 commit comments