1
1
package ca .bc .gov .educ .api .course .service ;
2
2
3
3
import ca .bc .gov .educ .api .course .exception .ServiceException ;
4
+ import ca .bc .gov .educ .api .course .util .ThreadLocalStateUtil ;
4
5
import org .junit .Assert ;
5
6
import org .junit .Before ;
6
7
import org .junit .Test ;
7
8
import org .junit .jupiter .api .extension .ExtendWith ;
8
9
import org .junit .runner .RunWith ;
10
+ import org .mockito .Mockito ;
9
11
import org .mockito .junit .jupiter .MockitoExtension ;
10
12
import org .springframework .beans .factory .annotation .Autowired ;
11
13
import org .springframework .boot .test .context .SpringBootTest ;
@@ -61,9 +63,11 @@ public class RESTServicePOSTTest {
61
63
62
64
@ Before
63
65
public void setUp (){
66
+ Mockito .reset (webClient , responseMock , requestHeadersMock , requestBodyMock , requestBodyUriMock );
67
+ ThreadLocalStateUtil .clear ();
64
68
when (this .webClient .post ()).thenReturn (this .requestBodyUriMock );
65
- when (this .requestBodyUriMock .uri (any (String .class ))).thenReturn (this .requestBodyUriMock );
66
- when (this .requestBodyUriMock .headers (any (Consumer .class ))).thenReturn (this .requestBodyMock );
69
+ when (this .requestBodyUriMock .uri (any (String .class ))).thenReturn (this .requestBodyMock );
70
+ when (this .requestBodyMock .headers (any (Consumer .class ))).thenReturn (this .requestBodyMock );
67
71
when (this .requestBodyMock .contentType (any ())).thenReturn (this .requestBodyMock );
68
72
when (this .requestBodyMock .body (any (BodyInserter .class ))).thenReturn (this .requestHeadersMock );
69
73
when (this .requestHeadersMock .retrieve ()).thenReturn (this .responseMock );
@@ -72,13 +76,17 @@ public void setUp(){
72
76
73
77
@ Test
74
78
public void testPost_GivenProperData_Expect200Response (){
79
+ ThreadLocalStateUtil .setCorrelationID ("test-correlation-id" );
80
+ ThreadLocalStateUtil .setCurrentUser ("test-user" );
75
81
when (this .responseMock .onStatus (any (), any ())).thenReturn (this .responseMock );
76
82
byte [] response = this .restService .post (TEST_URL , TEST_BODY , byte [].class );
77
83
Assert .assertArrayEquals (TEST_BYTES , response );
78
84
}
79
85
80
86
@ Test
81
87
public void testPostOverride_GivenProperData_Expect200Response (){
88
+ ThreadLocalStateUtil .setCorrelationID ("test-correlation-id" );
89
+ ThreadLocalStateUtil .setCurrentUser ("test-user" );
82
90
when (this .responseMock .onStatus (any (), any ())).thenReturn (this .responseMock );
83
91
byte [] response = this .restService .post (TEST_URL , TEST_BODY , byte [].class );
84
92
Assert .assertArrayEquals (TEST_BYTES , response );
0 commit comments