Skip to content

Commit

Permalink
sidam logic change (#638)
Browse files Browse the repository at this point in the history
Co-authored-by: arshinsalim <[email protected]>
  • Loading branch information
prudhvi-maddineni and arshinsalim authored Sep 14, 2023
1 parent 46f2629 commit 231275d
Show file tree
Hide file tree
Showing 41 changed files with 1,196 additions and 171 deletions.
2 changes: 1 addition & 1 deletion charts/rd-judicial-api/values.preview.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ java:
ELINKS_URL: https://judiciary-middleware-futureehr.herokuapp.com/api/v5
LAST_UPDATED: 2014-01-01
SCHEDULER_ENABLED: true
CRON_EXPRESSION: "* 10 15 * * *"
CRON_EXPRESSION: "* 45 12 * * *"
postgresql:
enabled: true
auth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ void verifyDeletedJrdUserProfile() {

List<UserProfile> userprofile = profileRepository.findAll();

assertEquals(12, userprofile.size());
assertEquals("4913085", userprofile.get(10).getPersonalCode());
assertEquals(true, userprofile.get(10).getDeletedFlag());
assertEquals("2023-07-13", userprofile.get(10).getDeletedOn().toLocalDate().toString());
assertEquals(13, userprofile.size());
assertEquals("4913085", userprofile.get(11).getPersonalCode());
assertEquals(true, userprofile.get(11).getDeletedFlag());
assertEquals("2023-07-13", userprofile.get(11).getDeletedOn().toLocalDate().toString());

assertEquals("4913086", userprofile.get(11).getPersonalCode());
assertEquals(false, userprofile.get(11).getDeletedFlag());
assertEquals("2022-07-10", userprofile.get(11).getDeletedOn().toLocalDate().toString());
assertEquals("4913086", userprofile.get(12).getPersonalCode());
assertEquals(false, userprofile.get(12).getDeletedFlag());
assertEquals("2022-07-10", userprofile.get(12).getDeletedOn().toLocalDate().toString());



Expand All @@ -142,14 +142,14 @@ void verifyDeletedJrdAuditFunctionality() {

List<UserProfile> userprofile = profileRepository.findAll();

assertEquals(12, userprofile.size());
assertEquals("4913085", userprofile.get(10).getPersonalCode());
assertEquals(true, userprofile.get(10).getDeletedFlag());
assertEquals("2023-07-13", userprofile.get(10).getDeletedOn().toLocalDate().toString());
assertEquals(13, userprofile.size());
assertEquals("4913085", userprofile.get(11).getPersonalCode());
assertEquals(true, userprofile.get(11).getDeletedFlag());
assertEquals("2023-07-13", userprofile.get(11).getDeletedOn().toLocalDate().toString());

assertEquals("4913086", userprofile.get(11).getPersonalCode());
assertEquals(false, userprofile.get(11).getDeletedFlag());
assertEquals("2022-07-10", userprofile.get(11).getDeletedOn().toLocalDate().toString());
assertEquals("4913086", userprofile.get(12).getPersonalCode());
assertEquals(false, userprofile.get(12).getDeletedFlag());
assertEquals("2022-07-10", userprofile.get(12).getDeletedOn().toLocalDate().toString());


List<ElinkDataSchedularAudit> elinksAudit = elinkSchedularAuditRepository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.APPOINTMENT_TABLE;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.BASE_LOCATION_ID;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.DELETEDAPI;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.ELINKS_ERROR_RESPONSE_BAD_REQUEST;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.ELINKS_ERROR_RESPONSE_FORBIDDEN;
Expand Down Expand Up @@ -375,7 +375,7 @@ void verifyPeoplesJrdExceptionRecordsBaseLocationNotFoundScenario() {

List<ElinkDataExceptionRecords> elinksException = elinkDataExceptionRepository.findAll();
ElinkDataExceptionRecords exceptionEntry = elinksException.get(0);
assertEquals(APPOINTMENT_TABLE, exceptionEntry.getFieldInError());
assertEquals(BASE_LOCATION_ID, exceptionEntry.getFieldInError());
assertNotNull(exceptionEntry.getSchedulerStartTime());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,18 @@ void test_elinks_end_to_end_success_scenario_with_partial_success_return_status_
assertEquals("1722",baseLocationList.get(4).getParentId());

List<UserProfile> userprofile = profileRepository.findAll();
assertEquals(11, userprofile.size());
assertEquals("4913085", userprofile.get(10).getPersonalCode());
assertEquals("Rachel", userprofile.get(10).getKnownAs());
assertEquals("Jones", userprofile.get(10).getSurname());
assertEquals("District Judge Rachel Jones", userprofile.get(10).getFullName());
assertEquals(null, userprofile.get(10).getPostNominals());
assertEquals(12, userprofile.size());
assertEquals("4913085", userprofile.get(11).getPersonalCode());
assertEquals("Rachel", userprofile.get(11).getKnownAs());
assertEquals("Jones", userprofile.get(11).getSurname());
assertEquals("District Judge Rachel Jones", userprofile.get(11).getFullName());
assertEquals(null, userprofile.get(11).getPostNominals());
assertEquals("[email protected]",
userprofile.get(10).getEmailId());
assertTrue(userprofile.get(10).getActiveFlag());
assertEquals("5f8b26ba-0c8b-4192-b5c7-311d737f0cae", userprofile.get(10).getObjectId());
assertNull(userprofile.get(10).getSidamId());
assertEquals("RJ",userprofile.get(10).getInitials());
userprofile.get(11).getEmailId());
assertTrue(userprofile.get(11).getActiveFlag());
assertEquals("5f8b26ba-0c8b-4192-b5c7-311d737f0cae", userprofile.get(11).getObjectId());
assertNull(userprofile.get(11).getSidamId());
assertEquals("RJ",userprofile.get(11).getInitials());


//asserting userprofile data for leaver api
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
package uk.gov.hmcts.reform.judicialapi.elinks;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.nimbusds.jose.JOSEException;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.util.ReflectionTestUtils;
import uk.gov.hmcts.reform.judicialapi.elinks.configuration.IdamTokenConfigProperties;
import uk.gov.hmcts.reform.judicialapi.elinks.domain.BaseLocation;
import uk.gov.hmcts.reform.judicialapi.elinks.domain.DataloadSchedulerJob;
import uk.gov.hmcts.reform.judicialapi.elinks.domain.ElinkDataSchedularAudit;
import uk.gov.hmcts.reform.judicialapi.elinks.domain.Location;
import uk.gov.hmcts.reform.judicialapi.elinks.domain.UserProfile;
import uk.gov.hmcts.reform.judicialapi.elinks.repository.AppointmentsRepository;
import uk.gov.hmcts.reform.judicialapi.elinks.repository.AuthorisationsRepository;
import uk.gov.hmcts.reform.judicialapi.elinks.repository.BaseLocationRepository;
import uk.gov.hmcts.reform.judicialapi.elinks.repository.DataloadSchedulerJobRepository;
import uk.gov.hmcts.reform.judicialapi.elinks.repository.ElinkDataExceptionRepository;
import uk.gov.hmcts.reform.judicialapi.elinks.repository.ElinkSchedularAuditRepository;
import uk.gov.hmcts.reform.judicialapi.elinks.repository.JudicialRoleTypeRepository;
import uk.gov.hmcts.reform.judicialapi.elinks.repository.LocationRepository;
import uk.gov.hmcts.reform.judicialapi.elinks.repository.ProfileRepository;
import uk.gov.hmcts.reform.judicialapi.elinks.response.ElinkLocationWrapperResponse;
import uk.gov.hmcts.reform.judicialapi.elinks.scheduler.ElinksApiJobScheduler;
import uk.gov.hmcts.reform.judicialapi.elinks.service.PublishSidamIdService;
import uk.gov.hmcts.reform.judicialapi.elinks.servicebus.ElinkTopicPublisher;
import uk.gov.hmcts.reform.judicialapi.elinks.util.ElinksEnabledIntegrationTest;
import uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants;
import uk.gov.hmcts.reform.judicialapi.versions.V2;

import java.util.List;
import java.util.Map;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.BASE_LOCATION_DATA_LOAD_SUCCESS;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.LOCATIONAPI;

class ElinksEndToEndIntegrationForSidamIdisPresent extends ElinksEnabledIntegrationTest {

@Autowired
LocationRepository locationRepository;
@Autowired
ProfileRepository profileRepository;
@Autowired
JudicialRoleTypeRepository judicialRoleTypeRepository;
@Autowired
BaseLocationRepository baseLocationRepository;
@Autowired
AuthorisationsRepository authorisationsRepository;
@Autowired
AppointmentsRepository appointmentsRepository;
@Autowired
IdamTokenConfigProperties tokenConfigProperties;


@Autowired
private ElinkSchedularAuditRepository elinkSchedularAuditRepository;

@Autowired
private ElinksApiJobScheduler elinksApiJobScheduler;

@Autowired
private DataloadSchedulerJobRepository dataloadSchedulerJobRepository;

@Autowired
PublishSidamIdService publishSidamIdService;

@MockBean
ElinkTopicPublisher elinkTopicPublisher;

@Autowired
ElinkDataExceptionRepository elinkDataExceptionRepository;



@BeforeAll
void loadElinksResponse() throws Exception {

cleanupData();

String locationResponseValidationJson =
loadJson("src/integrationTest/resources/wiremock_responses/location.json");
String baselocationResponseValidationJson =
loadJson("src/integrationTest/resources/wiremock_responses/base_location.json");
String peopleResponseValidationJson =
loadJson("src/integrationTest/resources/wiremock_responses/testpeople_withoutsidam.json");

elinks.stubFor(get(urlPathMatching("/reference_data/location"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", V2.MediaType.SERVICE)
.withHeader("Connection", "close")
.withBody(locationResponseValidationJson)));

elinks.stubFor(get(urlPathMatching("/reference_data/base_location"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", V2.MediaType.SERVICE)
.withHeader("Connection", "close")
.withBody(baselocationResponseValidationJson)
.withTransformers("user-token-response")));

elinks.stubFor(get(urlPathMatching("/people"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", V2.MediaType.SERVICE)
.withHeader("Connection", "close")
.withBody(peopleResponseValidationJson)));
}

@BeforeEach
void before() {
cleanupData();
}

@AfterEach
void cleanUp() {
cleanupData();
}

@DisplayName("Elinks end to test sidam is not updated")
@Test
void test_elinks_end_to_end_success_scenario_with_partial_success_return_status_200()
throws JOSEException, JsonProcessingException {

ReflectionTestUtils.setField(elinksApiJobScheduler, "isSchedulerEnabled", true);
ReflectionTestUtils.setField(publishSidamIdService, "elinkTopicPublisher", elinkTopicPublisher);

dataloadSchedulerJobRepository.deleteAll();
elinksApiJobScheduler.loadElinksJob();

List<DataloadSchedulerJob> audits = dataloadSchedulerJobRepository.findAll();
DataloadSchedulerJob jobDetails = audits.get(0);

//assserting scheduler data
assertThat(jobDetails).isNotNull();
assertThat(jobDetails.getPublishingStatus()).isNotNull();
Assert.assertEquals(RefDataElinksConstants.JobStatus.SUCCESS.getStatus(),jobDetails.getPublishingStatus());

// asserting location data
List<ElinkDataSchedularAudit> elinksAudit = elinkSchedularAuditRepository.findAll();
Map<String, Object> locationResponse = elinksReferenceDataClient.getLocations();
ElinkLocationWrapperResponse locations = (ElinkLocationWrapperResponse) locationResponse.get("body");
ElinkDataSchedularAudit locationAuditEntry = elinksAudit.get(0);

assertThat(locationResponse).containsEntry("http_status", "200 OK");
assertEquals(BASE_LOCATION_DATA_LOAD_SUCCESS, locations.getMessage());
assertEquals(LOCATIONAPI,locationAuditEntry.getApiName());
assertEquals(RefDataElinksConstants.JobStatus.SUCCESS.getStatus(), locationAuditEntry.getStatus());


List<Location> locationsList = locationRepository.findAll();
assertEquals(11, locationsList.size());
assertEquals("1", locationsList.get(1).getRegionId());
assertEquals("London", locationsList.get(1).getRegionDescEn());


//asserting baselocation data
List<BaseLocation> baseLocationList = baseLocationRepository.findAll();
assertEquals(12, baseLocationList.size());
assertEquals("Aberconwy",baseLocationList.get(4).getName());
assertEquals("1",baseLocationList.get(4).getBaseLocationId());
assertEquals("1722",baseLocationList.get(4).getParentId());

List<UserProfile> userprofile = profileRepository.findAll();
assertEquals(11, userprofile.size());
assertEquals("123454", userprofile.get(10).getPersonalCode());
assertEquals("Rachel", userprofile.get(10).getKnownAs());
assertEquals("Jones", userprofile.get(10).getSurname());
assertEquals("District Judge Rachel Jones", userprofile.get(10).getFullName());
assertEquals(null, userprofile.get(10).getPostNominals());
assertEquals("[email protected]",
userprofile.get(10).getEmailId());
assertTrue(userprofile.get(10).getActiveFlag());
assertEquals("5f8b26ba-0c8b-4192-b5c7-311d737f0cae", userprofile.get(10).getObjectId());
assertEquals("3333333",userprofile.get(10).getSidamId());
assertEquals("RJ",userprofile.get(10).getInitials());



//asserting userprofile data for leaver api

//asserting userprofile data for deleted api

}

private void cleanupData() {
elinkSchedularAuditRepository.deleteAll();
dataloadSchedulerJobRepository.deleteAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.powermock.api.mockito.PowerMockito.doNothing;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.DELETEDAPI;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.LEAVERSAPI;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.LOCATION;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.LOCATIONAPI;
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.PEOPLEAPI;

public class ElinksFailedApiPublishingStatusEndToEndIntegrationTest extends ElinksEnabledIntegrationTest {

Expand Down Expand Up @@ -150,10 +150,10 @@ void test_end_to_end_load_elinks_job_status_failure()
//asserting userprofile data for people api
Map<String, Object> peopleResponse = elinksReferenceDataClient.getPeoples();
ElinkPeopleWrapperResponse profiles = (ElinkPeopleWrapperResponse) peopleResponse.get("body");
ElinkDataSchedularAudit peopleAuditEntry = elinksAudit.get(1);
ElinkDataSchedularAudit peopleAuditEntry = elinksAudit.get(2);

assertThat(peopleResponse).containsEntry("http_status", "400");
assertEquals(PEOPLEAPI,peopleAuditEntry.getApiName());
assertEquals(LEAVERSAPI,peopleAuditEntry.getApiName());
assertEquals(RefDataElinksConstants.JobStatus.FAILED.getStatus(), peopleAuditEntry.getStatus());

List<UserProfile> userprofile = profileRepository.findAll();
Expand All @@ -162,10 +162,10 @@ void test_end_to_end_load_elinks_job_status_failure()
//asserting userprofile data for leaver api
Map<String, Object> leaversResponse = elinksReferenceDataClient.getLeavers();
ElinkLeaversWrapperResponse leaversProfiles = (ElinkLeaversWrapperResponse) leaversResponse.get("body");
ElinkDataSchedularAudit leaversAuditEntry = elinksAudit.get(2);
ElinkDataSchedularAudit leaversAuditEntry = elinksAudit.get(3);

assertThat(leaversResponse).containsEntry("http_status", "400");
assertEquals(LEAVERSAPI,leaversAuditEntry.getApiName());
assertEquals(DELETEDAPI,leaversAuditEntry.getApiName());
assertEquals(RefDataElinksConstants.JobStatus.FAILED.getStatus(), leaversAuditEntry.getStatus());

List<UserProfile> leaverUserProfile = profileRepository.findAll();
Expand All @@ -174,7 +174,7 @@ void test_end_to_end_load_elinks_job_status_failure()
//assert elastic search api

Map<String, Object> idamResponses = elinksReferenceDataClient.getIdamElasticSearch();
assertEquals("403",idamResponses.get("http_status"));
assertEquals("500",idamResponses.get("http_status"));

// asserting SIDAM publishing
Map<String, Object> idamResponse = elinksReferenceDataClient.publishSidamIds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void test_elinks_end_to_end_success_scenario_with_return_status_200()
assertEquals(RefDataElinksConstants.JobStatus.PARTIAL_SUCCESS.getStatus(), peopleAuditEntry.getStatus());

List<ElinkDataExceptionRecords> elinksException = elinkDataExceptionRepository.findAll();
assertEquals("PageNumber:2-Personal Code : 4925319 is already loaded",
assertEquals("Personal Code : 4925319 is already loaded",
elinksException.get(1).getErrorDescription());
assertThat(elinksException.size()).isEqualTo(2);

Expand Down
Loading

0 comments on commit 231275d

Please sign in to comment.