Skip to content

Commit 1e89aa1

Browse files
committed
fixed test case failure
1 parent 6ca58eb commit 1e89aa1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

api/src/test/java/ca/bc/gov/educ/api/course/service/RESTServicePOSTTest.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package ca.bc.gov.educ.api.course.service;
22

33
import ca.bc.gov.educ.api.course.exception.ServiceException;
4+
import ca.bc.gov.educ.api.course.util.ThreadLocalStateUtil;
45
import org.junit.Assert;
56
import org.junit.Before;
67
import org.junit.Test;
78
import org.junit.jupiter.api.extension.ExtendWith;
89
import org.junit.runner.RunWith;
10+
import org.mockito.Mockito;
911
import org.mockito.junit.jupiter.MockitoExtension;
1012
import org.springframework.beans.factory.annotation.Autowired;
1113
import org.springframework.boot.test.context.SpringBootTest;
@@ -61,9 +63,11 @@ public class RESTServicePOSTTest {
6163

6264
@Before
6365
public void setUp(){
66+
Mockito.reset(webClient, responseMock, requestHeadersMock, requestBodyMock, requestBodyUriMock);
67+
ThreadLocalStateUtil.clear();
6468
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);
6771
when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock);
6872
when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock);
6973
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
@@ -72,13 +76,17 @@ public void setUp(){
7276

7377
@Test
7478
public void testPost_GivenProperData_Expect200Response(){
79+
ThreadLocalStateUtil.setCorrelationID("test-correlation-id");
80+
ThreadLocalStateUtil.setCurrentUser("test-user");
7581
when(this.responseMock.onStatus(any(), any())).thenReturn(this.responseMock);
7682
byte[] response = this.restService.post(TEST_URL, TEST_BODY, byte[].class);
7783
Assert.assertArrayEquals(TEST_BYTES, response);
7884
}
7985

8086
@Test
8187
public void testPostOverride_GivenProperData_Expect200Response(){
88+
ThreadLocalStateUtil.setCorrelationID("test-correlation-id");
89+
ThreadLocalStateUtil.setCurrentUser("test-user");
8290
when(this.responseMock.onStatus(any(), any())).thenReturn(this.responseMock);
8391
byte[] response = this.restService.post(TEST_URL, TEST_BODY, byte[].class);
8492
Assert.assertArrayEquals(TEST_BYTES, response);

0 commit comments

Comments
 (0)