diff --git a/charts/rd-profile-sync/Chart.yaml b/charts/rd-profile-sync/Chart.yaml index a1b1e394..5b731620 100644 --- a/charts/rd-profile-sync/Chart.yaml +++ b/charts/rd-profile-sync/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: "0.1" description: Reference data service for professional users name: rd-profile-sync -version: 0.0.21 +version: 0.0.22 dependencies: - name: java version: 4.0.13 diff --git a/charts/rd-profile-sync/values.yaml b/charts/rd-profile-sync/values.yaml index ad4ee975..4607562f 100644 --- a/charts/rd-profile-sync/values.yaml +++ b/charts/rd-profile-sync/values.yaml @@ -11,6 +11,7 @@ java: S2S_URL: http://rpe-service-auth-provider-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal IDAM_URL: https://idam-api.{{ .Values.global.environment }}.platform.hmcts.net USER_PROFILE_URL: http://rd-user-profile-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal + CASEWORKER_REF_URL: http://rd-caseworker-ref-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal OAUTH2_REDIRECT_URI: https://rd-professional-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal/oauth2redirect AUTH_IDAM_CLIENT_BASEURL: https://idam-api.{{ .Values.global.environment }}.platform.hmcts.net diff --git a/config/owasp/suppressions.xml b/config/owasp/suppressions.xml index d9ca68cc..9808867a 100644 --- a/config/owasp/suppressions.xml +++ b/config/owasp/suppressions.xml @@ -40,7 +40,8 @@ Temporary suppression for commons-fileupload-1.4.jar - CVE-2023-24998 + CVE-2023-24998 + CVE-2023-20883 { - assertThat(profileSyncAuditDetails.getStatusCode()).isEqualTo(201); + assertThat(profileSyncAuditDetails.getStatusCode()).isEqualTo(200); assertThat(profileSyncAuditDetails.getErrorDescription()).isEqualTo("success"); }); }); @@ -74,10 +74,25 @@ void whenSearchUserAndUpServiceCallSuccessAndSyncBatchStatusShouldBeSuccess() { assertThat(syncAuditThirdRes.getSchedulerId()).isPositive(); assertThat(syncAuditThirdRes.getProfileSyncAuditDetails()).isNotNull(); syncAuditThirdRes.getProfileSyncAuditDetails().forEach(profileSyncAuditDetails -> { - assertThat(profileSyncAuditDetails.getStatusCode()).isEqualTo(201); + assertThat(profileSyncAuditDetails.getStatusCode()).isEqualTo(200); assertThat(profileSyncAuditDetails.getErrorDescription()).isEqualTo("success"); }); + + caseWorkerUserSyncWireMock(HttpStatus.OK); + profileSyncJobScheduler.updateIdamDataWithUserProfile(); + ProfileSyncAudit syncAuditFourthRes = profileSyncAuditRepository + .findFirstBySchedulerStatusOrderBySchedulerEndTimeDesc("success"); + assertThat(syncAuditFourthRes).isNotNull(); + assertThat(syncAuditFourthRes.getSchedulerStatus()).isEqualTo("success"); + assertThat(syncAuditFourthRes.getSchedulerEndTime()).isNotNull(); + assertThat(syncAuditFourthRes.getSchedulerStartTime()).isNotNull(); + assertThat(syncAuditFourthRes.getSchedulerId()).isPositive(); + assertThat(syncAuditFourthRes.getProfileSyncAuditDetails()).isNotNull(); + syncAuditFourthRes.getProfileSyncAuditDetails().forEach(profileSyncAuditDetails -> { + assertThat(profileSyncAuditDetails.getStatusCode()).isEqualTo(200); + assertThat(profileSyncAuditDetails.getErrorDescription()).isEqualTo("success"); + }); } @Test @@ -103,6 +118,28 @@ void whenSearchUserSucessAndUpServiceCallsFailScheduledIsCalledAtLeastOneTimes() } + @Test + void whenSyncCaseWorkerReturns400StatusCodeAndInsertFailStatusForSycnBatch() { + + caseWorkerUserSyncWireMock(HttpStatus.BAD_REQUEST); + jobScheduler.updateIdamDataWithUserProfile(); + List syncAuditSecondRes = profileSyncAuditRepository.findAll(); + assertThat(syncAuditSecondRes).isNotEmpty(); + syncAuditSecondRes.forEach(syncAudit -> { + assertThat(syncAudit.getSchedulerStatus()).isEqualTo("fail"); + assertThat(syncAudit.getSchedulerEndTime()).isNotNull(); + assertThat(syncAudit.getSchedulerStartTime()).isNotNull(); + assertThat(syncAudit.getSchedulerId()).isPositive(); + assertThat(syncAudit.getProfileSyncAuditDetails()).isNotNull(); + syncAudit.getProfileSyncAuditDetails().forEach(profileSyncAuditDetails -> { + assertThat(profileSyncAuditDetails.getStatusCode()).isEqualTo(404); + assertThat(profileSyncAuditDetails.getErrorDescription()) + .isEqualTo("the case worker failed while updating the status"); + }); + }); + + } + @Test void whenSearchUserReturns400StatusCodeAndInsertFailStatusForSycnBatch() { diff --git a/src/integrationTest/resources/application.yaml b/src/integrationTest/resources/application.yaml index a26dd011..ef47b631 100644 --- a/src/integrationTest/resources/application.yaml +++ b/src/integrationTest/resources/application.yaml @@ -53,6 +53,8 @@ exui.role: ## user profile feign connection userprofile.api.url: ${USER_PROFILE_URL:http://127.0.0.1:8091} +caseworker.api.url: ${CASEWORKER_REF_URL:http://127.0.0.1:8095} + loggingComponentName: RD_Profile_Sync recordsPerPage: 100 \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/profilesync/client/CaseWorkerRefApiClient.java b/src/main/java/uk/gov/hmcts/reform/profilesync/client/CaseWorkerRefApiClient.java new file mode 100644 index 00000000..7432bf4b --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/profilesync/client/CaseWorkerRefApiClient.java @@ -0,0 +1,22 @@ +package uk.gov.hmcts.reform.profilesync.client; + +import feign.Headers; +import feign.Response; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import uk.gov.hmcts.reform.profilesync.domain.CaseWorkerProfile; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +@FeignClient(name = "caseWorkerRefApiClient", url = "${caseworker.api.url}") +public interface CaseWorkerRefApiClient { + + @PutMapping(value = "/refdata/case-worker/users/sync", consumes = {APPLICATION_JSON_VALUE}, + produces = {APPLICATION_JSON_VALUE}) + @Headers({"authorization: {authorization}", "serviceauthorization: {serviceauthorization}"}) + public Response syncCaseWorkerUserStatus(@RequestHeader("authorization") String authorization, + @RequestHeader("serviceauthorization") String serviceAuthorization, + @RequestBody CaseWorkerProfile body); +} diff --git a/src/main/java/uk/gov/hmcts/reform/profilesync/domain/CaseWorkerProfile.java b/src/main/java/uk/gov/hmcts/reform/profilesync/domain/CaseWorkerProfile.java new file mode 100644 index 00000000..eb29c9f1 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/profilesync/domain/CaseWorkerProfile.java @@ -0,0 +1,26 @@ +package uk.gov.hmcts.reform.profilesync.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CaseWorkerProfile { + + + @JsonProperty("suspended") + private boolean idamStatus; + + @JsonProperty("email_id") + private String email; + + @JsonProperty("first_name") + private String firstName; + + @JsonProperty("last_name") + private String lastName; + + @JsonProperty("case_worker_id") + private String userId; +} diff --git a/src/main/java/uk/gov/hmcts/reform/profilesync/schedular/UserProfileSyncJobScheduler.java b/src/main/java/uk/gov/hmcts/reform/profilesync/schedular/UserProfileSyncJobScheduler.java index 7193b2e8..3333517d 100644 --- a/src/main/java/uk/gov/hmcts/reform/profilesync/schedular/UserProfileSyncJobScheduler.java +++ b/src/main/java/uk/gov/hmcts/reform/profilesync/schedular/UserProfileSyncJobScheduler.java @@ -46,7 +46,8 @@ public class UserProfileSyncJobScheduler { public void updateIdamDataWithUserProfile() { String searchQuery = "(roles:pui-case-manager OR roles:pui-user-manager OR roles:pui-organisation-manager OR " - + "roles:pui-finance-manager OR roles:pui-caa OR roles:cwd-user) AND lastModified:>now-"; + + "roles:pui-finance-manager OR roles:pui-caa OR roles:cwd-user) " + + "AND lastModified:>now-"; LocalDateTime startTime = LocalDateTime.now(); SyncJobConfig syncJobConfig = profileSyncConfigRepository.findByConfigName("firstsearchquery"); diff --git a/src/main/java/uk/gov/hmcts/reform/profilesync/service/impl/ProfileUpdateServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/profilesync/service/impl/ProfileUpdateServiceImpl.java index a12a835f..bf06f832 100644 --- a/src/main/java/uk/gov/hmcts/reform/profilesync/service/impl/ProfileUpdateServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/profilesync/service/impl/ProfileUpdateServiceImpl.java @@ -15,9 +15,11 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.profilesync.advice.UserProfileSyncException; +import uk.gov.hmcts.reform.profilesync.client.CaseWorkerRefApiClient; import uk.gov.hmcts.reform.profilesync.client.IdamClient; import uk.gov.hmcts.reform.profilesync.client.UserProfileClient; import uk.gov.hmcts.reform.profilesync.constants.IdamStatus; +import uk.gov.hmcts.reform.profilesync.domain.CaseWorkerProfile; import uk.gov.hmcts.reform.profilesync.domain.ProfileSyncAudit; import uk.gov.hmcts.reform.profilesync.domain.ProfileSyncAuditDetails; import uk.gov.hmcts.reform.profilesync.domain.ProfileSyncAuditDetailsId; @@ -38,6 +40,9 @@ public class ProfileUpdateServiceImpl implements ProfileUpdateService { @Autowired private UserProfileClient userProfileClient; + @Autowired + private CaseWorkerRefApiClient caseWorkerRefApiClient; + @Value("${loggingComponentName}") private String loggingComponentName; @@ -46,6 +51,11 @@ public ProfileSyncAudit updateUserProfile(String searchQuery, String bearerToken throws UserProfileSyncException { log.info("{}:: Inside updateUserProfile::{}", loggingComponentName); List profileSyncAuditDetails = new ArrayList<>(); + List caseWorkerSyncAuditDetails = new ArrayList<>(); + + + + users.forEach(user -> { Optional userProfile = userAcquisitionService.findUser(bearerToken, s2sToken, user.getId()); @@ -64,17 +74,47 @@ public ProfileSyncAudit updateUserProfile(String searchQuery, String bearerToken try { //to update user profile details for matching user ids are collecting and storing in the list // from syncUser method. - profileSyncAuditDetails.add(syncUser(bearerToken, s2sToken, user.getId(), updatedUserProfile, - syncAudit)); + profileSyncAuditDetails.add(syncUser(bearerToken, s2sToken, user.getId(), + updatedUserProfile, syncAudit)); } catch (UserProfileSyncException e) { syncAudit.setSchedulerStatus("fail"); - log.error("{}:: User Not updated : - {}",loggingComponentName, e.getErrorMessage()); + log.error("{}:: User Not updated : - {}", loggingComponentName, e.getErrorMessage()); } log.info("{}:: User Status updated in User Profile::{}", loggingComponentName); } + }); + + users.forEach(user -> { + StringBuilder sb = new StringBuilder(); + sb.append(user.isActive()); + sb.append(user.isPending()); + + CaseWorkerProfile updateCaseWorkerProfile = CaseWorkerProfile.builder() + .email(user.getEmail()) + .userId(user.getId()) + .firstName(user.getForename()) + .lastName(user.getSurname()) + .idamStatus(resolveIdamStatusForCaseWorker(sb)) + .build(); + + try { + //to update caseworker profile details for matching user ids are collecting and storing in the list + // from syncCaseWorkerUser method. + caseWorkerSyncAuditDetails.add(syncCaseWorkerUser(bearerToken, s2sToken, user.getId(), + updateCaseWorkerProfile, syncAudit)); + + } catch (UserProfileSyncException e) { + syncAudit.setSchedulerStatus("fail"); + log.error("{}:: User Not updated : - {}", loggingComponentName, e.getErrorMessage()); + } + + + }); + syncAudit.setProfileSyncAuditDetails(profileSyncAuditDetails); + syncAudit.setProfileSyncAuditDetails(caseWorkerSyncAuditDetails); return syncAudit; } @@ -96,6 +136,28 @@ private ProfileSyncAuditDetails syncUser(String bearerToken, String s2sToken, LocalDateTime.now()); } + + private ProfileSyncAuditDetails syncCaseWorkerUser(String bearerToken, String s2sToken, + String userId, CaseWorkerProfile caseWorkerProfile, + ProfileSyncAudit syncAudit) + throws UserProfileSyncException { + + log.info("{}:: Inside syncCaseWorkerUser method ::{}", loggingComponentName); + Response response = caseWorkerRefApiClient + .syncCaseWorkerUserStatus(bearerToken, s2sToken, caseWorkerProfile); + String message = "success"; + if (response.status() > 300) { + log.error("{}:: Exception occurred while updating the case worker profile: Status - {}" + + response.status(), loggingComponentName); + message = "the case worker failed while updating the status"; + syncAudit.setSchedulerStatus("fail"); + } + + log.info("{}:: CaseWorker Status updated in Case Worker DB::{}", loggingComponentName); + return new ProfileSyncAuditDetails(new ProfileSyncAuditDetailsId(syncAudit,userId),response.status(),message, + LocalDateTime.now()); + } + public String resolveIdamStatus(StringBuilder stringBuilder) { if (stringBuilder.toString().equalsIgnoreCase("falsetrue")) { @@ -107,4 +169,15 @@ public String resolveIdamStatus(StringBuilder stringBuilder) { } } + public boolean resolveIdamStatusForCaseWorker(StringBuilder stringBuilder) { + + if (stringBuilder.toString().equalsIgnoreCase("falsetrue")) { + return false; + } else if (stringBuilder.toString().equalsIgnoreCase("truefalse")) { + return false; + } else { + return true; + } + } + } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 18119046..7d0156de 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -90,6 +90,12 @@ userprofile: api: url: ${USER_PROFILE_URL:http://rd-user-profile-api-aat.service.core-compute-aat.internal} +caseworker: + api: + url: ${CASEWORKER_REF_URL:http://rd-caseworker-ref-api-aat.service.core-compute-aat.internal} + + + loggingComponentName: RD_Profile_Sync recordsPerPage: 100 \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/reform/profilesync/domain/CaseWorkerProfileTest.java b/src/test/java/uk/gov/hmcts/reform/profilesync/domain/CaseWorkerProfileTest.java new file mode 100644 index 00000000..8367a8c1 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/profilesync/domain/CaseWorkerProfileTest.java @@ -0,0 +1,63 @@ +package uk.gov.hmcts.reform.profilesync.domain; + +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertTrue; +import static uk.gov.hmcts.reform.profilesync.helper.MockDataProvider.getCaseWorkerProfile; +import static uk.gov.hmcts.reform.profilesync.helper.MockDataProvider.EMAIL; +import static uk.gov.hmcts.reform.profilesync.helper.MockDataProvider.FIRST_NAME; +import static uk.gov.hmcts.reform.profilesync.helper.MockDataProvider.IDAM_ID; +import static uk.gov.hmcts.reform.profilesync.helper.MockDataProvider.LAST_NAME; + +public class CaseWorkerProfileTest { + + private final CaseWorkerProfile cwp = getCaseWorkerProfile(); + + @Test + void getIdamId() { + assertThat(cwp.isIdamStatus()).isEqualTo(true); + } + + @Test + void getEmail() { + assertThat(cwp.getEmail()).isEqualTo(EMAIL); + } + + @Test + void getFirstName() { + assertThat(cwp.getFirstName()).isEqualTo(FIRST_NAME); + } + + @Test + void getLastName() { + assertThat(cwp.getLastName()).isEqualTo(LAST_NAME); + } + + + @Test + void getCaseWorkerId() { + assertThat(cwp.getUserId()).isEqualTo(IDAM_ID); + } + + @Test + void builderToString() { + String profile = CaseWorkerProfile.builder().toString(); + + assertThat(profile).isNotEmpty(); + } + + @Test + void setGetValues() { + CaseWorkerProfile profile = CaseWorkerProfile.builder().userId(UUID.randomUUID().toString()) + .email("email@org.com") + .firstName("firstName") + .lastName("lastName") + .idamStatus(true) + .build(); + + assertTrue(profile.isIdamStatus()); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/profilesync/helper/MockDataProvider.java b/src/test/java/uk/gov/hmcts/reform/profilesync/helper/MockDataProvider.java index 1b33ed4c..0c064705 100644 --- a/src/test/java/uk/gov/hmcts/reform/profilesync/helper/MockDataProvider.java +++ b/src/test/java/uk/gov/hmcts/reform/profilesync/helper/MockDataProvider.java @@ -8,12 +8,14 @@ import java.util.List; import uk.gov.hmcts.reform.profilesync.client.IdamClient; +import uk.gov.hmcts.reform.profilesync.domain.CaseWorkerProfile; import uk.gov.hmcts.reform.profilesync.domain.UserProfile; import uk.gov.hmcts.reform.profilesync.domain.response.GetUserProfileResponse; public class MockDataProvider { private static UserProfile userProfile; + private static CaseWorkerProfile caseWorkerProfile; private static IdamClient.User idamUser; private static GetUserProfileResponse getUserProfileResponse; @@ -46,6 +48,14 @@ private MockDataProvider() { .idamStatus(STATUS) .idamRegistrationResponse(IDAM_REGISTRATION_RESPONSE) .build(); + + caseWorkerProfile = CaseWorkerProfile.builder() + .userId(IDAM_ID) + .email(EMAIL) + .firstName(FIRST_NAME) + .lastName(LAST_NAME) + .idamStatus(true) + .build(); } public static UserProfile getUserProfile() { @@ -55,6 +65,13 @@ public static UserProfile getUserProfile() { return userProfile; } + public static CaseWorkerProfile getCaseWorkerProfile() { + if (caseWorkerProfile == null) { + caseWorkerProfile = new MockDataProvider().caseWorkerProfile; + } + return caseWorkerProfile; + } + public static IdamClient.User getIdamUser() { if (idamUser == null) { idamUser = new IdamClient.User(); diff --git a/src/test/java/uk/gov/hmcts/reform/profilesync/service/impl/ProfileUpdateServiceImplTest.java b/src/test/java/uk/gov/hmcts/reform/profilesync/service/impl/ProfileUpdateServiceImplTest.java index 8de57f9e..3e94b7d8 100644 --- a/src/test/java/uk/gov/hmcts/reform/profilesync/service/impl/ProfileUpdateServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/profilesync/service/impl/ProfileUpdateServiceImplTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator; +import uk.gov.hmcts.reform.profilesync.client.CaseWorkerRefApiClient; import uk.gov.hmcts.reform.profilesync.client.IdamClient; import uk.gov.hmcts.reform.profilesync.client.UserProfileClient; import uk.gov.hmcts.reform.profilesync.constants.IdamStatus; @@ -16,8 +17,10 @@ import uk.gov.hmcts.reform.profilesync.service.UserAcquisitionService; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -34,8 +37,10 @@ class ProfileUpdateServiceImplTest { private final UserProfileClient userProfileClientMock = Mockito.mock(UserProfileClient.class); private final AuthTokenGenerator tokenGeneratorMock = Mockito.mock(AuthTokenGenerator.class); private final UserAcquisitionService userAcquisitionServiceMock = Mockito.mock(UserAcquisitionService.class); + + private final CaseWorkerRefApiClient caseWorkerRefApiClientMock = Mockito.mock(CaseWorkerRefApiClient.class); private final ProfileUpdateServiceImpl sut = new ProfileUpdateServiceImpl(userAcquisitionServiceMock, - userProfileClientMock, "RD_Profile_Sync"); + userProfileClientMock, caseWorkerRefApiClientMock,"RD_Profile_Sync"); private ProfileSyncAudit profileSyncAuditMock = mock(ProfileSyncAudit.class); private Set users; @@ -43,7 +48,7 @@ class ProfileUpdateServiceImplTest { private UserProfile userProfile; private GetUserProfileResponse getUserProfileResponse; private ObjectMapper mapper; - private final String searchQuery = "lastModified:>now-24h"; + private final String searchQuery = "(roles:prd-admin) AND lastModified:>now-24h"; private final String bearerToken = "foobar"; private final String s2sToken = "ey0somes2stoken"; @@ -60,6 +65,12 @@ public void setUp() { profile.setActive(true); profile.setSurname("kotla"); + List roles = new ArrayList<>(); + roles.add("prd-admin"); + roles.add("staff-admin"); + + profile.setRoles(roles); + users = new HashSet<>(); users.add(profile); } @@ -73,11 +84,15 @@ void updateUserProfile() throws Exception { null)).body(body, Charset.defaultCharset()).status(200).build()); when(tokenGeneratorMock.generate()).thenReturn(s2sToken); + when(caseWorkerRefApiClientMock.syncCaseWorkerUserStatus(any(), any(), any())).thenReturn(Response.builder() + .request(Request.create(Request.HttpMethod.PUT, "", new HashMap<>(), Request.Body.empty(), + null)).body(body, Charset.defaultCharset()).status(201).build()); + ProfileSyncAudit profileSyncAudit = sut.updateUserProfile(searchQuery, bearerToken, s2sToken, users, profileSyncAuditMock); assertThat(profileSyncAudit).isNotNull(); verify(userAcquisitionServiceMock, times(1)).findUser(any(), any(), any()); - verify(profileSyncAuditMock, times(1)).setProfileSyncAuditDetails(any()); + verify(profileSyncAuditMock, times(2)).setProfileSyncAuditDetails(any()); } @Test @@ -91,6 +106,10 @@ void updateUserProfileForOptional() throws Exception { .request(Request.create(Request.HttpMethod.PUT, "", new HashMap<>(), Request.Body.empty(), null)).body(body, Charset.defaultCharset()).status(201).build()); + when(caseWorkerRefApiClientMock.syncCaseWorkerUserStatus(any(), any(), any())).thenReturn(Response.builder() + .request(Request.create(Request.HttpMethod.PUT, "", new HashMap<>(), Request.Body.empty(), + null)).body(body, Charset.defaultCharset()).status(201).build()); + sut.updateUserProfile(searchQuery, bearerToken, s2sToken, users, profileSyncAuditMock); verify(userAcquisitionServiceMock, times(1)).findUser(bearerToken, s2sToken, @@ -108,6 +127,10 @@ void updateUserProfileForOptionalThrowandCatchExp() throws Exception { .request(Request.create(Request.HttpMethod.PUT, "", new HashMap<>(), Request.Body.empty(), null)).body(body, Charset.defaultCharset()).status(400).build()); + when(caseWorkerRefApiClientMock.syncCaseWorkerUserStatus(any(), any(), any())).thenReturn(Response.builder() + .request(Request.create(Request.HttpMethod.PUT, "", new HashMap<>(), Request.Body.empty(), + null)).body(body, Charset.defaultCharset()).status(400).build()); + sut.updateUserProfile(searchQuery, bearerToken, s2sToken, users, profileSyncAuditMock); verify(userAcquisitionServiceMock, times(1)).findUser(any(), any(), any()); @@ -125,6 +148,10 @@ void updateUserProfileForOptionalWithStatus300() throws Exception { .request(Request.create(Request.HttpMethod.PUT, "", new HashMap<>(), Request.Body.empty(), null)).body(body, Charset.defaultCharset()).status(300).build()); + when(caseWorkerRefApiClientMock.syncCaseWorkerUserStatus(any(), any(), any())).thenReturn(Response.builder() + .request(Request.create(Request.HttpMethod.PUT, "", new HashMap<>(), Request.Body.empty(), + null)).body(body, Charset.defaultCharset()).status(300).build()); + sut.updateUserProfile(searchQuery, bearerToken, s2sToken, users, profileSyncAuditMock); verify(userAcquisitionServiceMock, times(1)).findUser(bearerToken, s2sToken, @@ -141,10 +168,14 @@ void updateUserProfileForOptionalWithStatus401() throws Exception { null)).body(null, Charset.defaultCharset()).status(401) .reason("Un Authorized").build()); + when(caseWorkerRefApiClientMock.syncCaseWorkerUserStatus(any(), any(), any())).thenReturn(Response.builder() + .request(Request.create(Request.HttpMethod.PUT, "", new HashMap<>(), Request.Body.empty(), + null)).body(null, Charset.defaultCharset()).status(401).build()); + profileSyncAuditMock = sut.updateUserProfile(searchQuery, bearerToken, s2sToken, users, profileSyncAuditMock); assertThat(profileSyncAuditMock).isNotNull(); - verify(profileSyncAuditMock, times(1)).setSchedulerStatus(any()); + verify(profileSyncAuditMock, times(2)).setSchedulerStatus(any()); verify(userAcquisitionServiceMock, times(1)).findUser(bearerToken, s2sToken, profile.getId()); }