Skip to content

Commit 231275d

Browse files
sidam logic change (#638)
Co-authored-by: arshinsalim <arshin.salim@hmcts.net>
1 parent 46f2629 commit 231275d

File tree

41 files changed

+1196
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1196
-171
lines changed

charts/rd-judicial-api/values.preview.template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ java:
1919
ELINKS_URL: https://judiciary-middleware-futureehr.herokuapp.com/api/v5
2020
LAST_UPDATED: 2014-01-01
2121
SCHEDULER_ENABLED: true
22-
CRON_EXPRESSION: "* 10 15 * * *"
22+
CRON_EXPRESSION: "* 45 12 * * *"
2323
postgresql:
2424
enabled: true
2525
auth:

src/integrationTest/java/uk/gov/hmcts/reform/judicialapi/elinks/DeletedIntegrationTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ void verifyDeletedJrdUserProfile() {
116116

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

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

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

128128

129129

@@ -142,14 +142,14 @@ void verifyDeletedJrdAuditFunctionality() {
142142

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

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

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

154154

155155
List<ElinkDataSchedularAudit> elinksAudit = elinkSchedularAuditRepository.findAll();

src/integrationTest/java/uk/gov/hmcts/reform/judicialapi/elinks/ElinkClientsCommonIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import static org.junit.jupiter.api.Assertions.assertEquals;
2929
import static org.junit.jupiter.api.Assertions.assertNotNull;
3030
import static org.junit.jupiter.api.Assertions.assertTrue;
31-
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.APPOINTMENT_TABLE;
31+
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.BASE_LOCATION_ID;
3232
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.DELETEDAPI;
3333
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.ELINKS_ERROR_RESPONSE_BAD_REQUEST;
3434
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.ELINKS_ERROR_RESPONSE_FORBIDDEN;
@@ -375,7 +375,7 @@ void verifyPeoplesJrdExceptionRecordsBaseLocationNotFoundScenario() {
375375

376376
List<ElinkDataExceptionRecords> elinksException = elinkDataExceptionRepository.findAll();
377377
ElinkDataExceptionRecords exceptionEntry = elinksException.get(0);
378-
assertEquals(APPOINTMENT_TABLE, exceptionEntry.getFieldInError());
378+
assertEquals(BASE_LOCATION_ID, exceptionEntry.getFieldInError());
379379
assertNotNull(exceptionEntry.getSchedulerStartTime());
380380

381381
}

src/integrationTest/java/uk/gov/hmcts/reform/judicialapi/elinks/ElinksEndToEndIntegrationForExistingObjectId.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,18 @@ void test_elinks_end_to_end_success_scenario_with_partial_success_return_status_
182182
assertEquals("1722",baseLocationList.get(4).getParentId());
183183

184184
List<UserProfile> userprofile = profileRepository.findAll();
185-
assertEquals(11, userprofile.size());
186-
assertEquals("4913085", userprofile.get(10).getPersonalCode());
187-
assertEquals("Rachel", userprofile.get(10).getKnownAs());
188-
assertEquals("Jones", userprofile.get(10).getSurname());
189-
assertEquals("District Judge Rachel Jones", userprofile.get(10).getFullName());
190-
assertEquals(null, userprofile.get(10).getPostNominals());
185+
assertEquals(12, userprofile.size());
186+
assertEquals("4913085", userprofile.get(11).getPersonalCode());
187+
assertEquals("Rachel", userprofile.get(11).getKnownAs());
188+
assertEquals("Jones", userprofile.get(11).getSurname());
189+
assertEquals("District Judge Rachel Jones", userprofile.get(11).getFullName());
190+
assertEquals(null, userprofile.get(11).getPostNominals());
191191
assertEquals("DJ.Rachel.Jones@ejudiciary.net",
192-
userprofile.get(10).getEmailId());
193-
assertTrue(userprofile.get(10).getActiveFlag());
194-
assertEquals("5f8b26ba-0c8b-4192-b5c7-311d737f0cae", userprofile.get(10).getObjectId());
195-
assertNull(userprofile.get(10).getSidamId());
196-
assertEquals("RJ",userprofile.get(10).getInitials());
192+
userprofile.get(11).getEmailId());
193+
assertTrue(userprofile.get(11).getActiveFlag());
194+
assertEquals("5f8b26ba-0c8b-4192-b5c7-311d737f0cae", userprofile.get(11).getObjectId());
195+
assertNull(userprofile.get(11).getSidamId());
196+
assertEquals("RJ",userprofile.get(11).getInitials());
197197

198198

199199
//asserting userprofile data for leaver api
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
package uk.gov.hmcts.reform.judicialapi.elinks;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.nimbusds.jose.JOSEException;
5+
import org.junit.Assert;
6+
import org.junit.jupiter.api.AfterEach;
7+
import org.junit.jupiter.api.BeforeAll;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.DisplayName;
10+
import org.junit.jupiter.api.Test;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.boot.test.mock.mockito.MockBean;
13+
import org.springframework.test.util.ReflectionTestUtils;
14+
import uk.gov.hmcts.reform.judicialapi.elinks.configuration.IdamTokenConfigProperties;
15+
import uk.gov.hmcts.reform.judicialapi.elinks.domain.BaseLocation;
16+
import uk.gov.hmcts.reform.judicialapi.elinks.domain.DataloadSchedulerJob;
17+
import uk.gov.hmcts.reform.judicialapi.elinks.domain.ElinkDataSchedularAudit;
18+
import uk.gov.hmcts.reform.judicialapi.elinks.domain.Location;
19+
import uk.gov.hmcts.reform.judicialapi.elinks.domain.UserProfile;
20+
import uk.gov.hmcts.reform.judicialapi.elinks.repository.AppointmentsRepository;
21+
import uk.gov.hmcts.reform.judicialapi.elinks.repository.AuthorisationsRepository;
22+
import uk.gov.hmcts.reform.judicialapi.elinks.repository.BaseLocationRepository;
23+
import uk.gov.hmcts.reform.judicialapi.elinks.repository.DataloadSchedulerJobRepository;
24+
import uk.gov.hmcts.reform.judicialapi.elinks.repository.ElinkDataExceptionRepository;
25+
import uk.gov.hmcts.reform.judicialapi.elinks.repository.ElinkSchedularAuditRepository;
26+
import uk.gov.hmcts.reform.judicialapi.elinks.repository.JudicialRoleTypeRepository;
27+
import uk.gov.hmcts.reform.judicialapi.elinks.repository.LocationRepository;
28+
import uk.gov.hmcts.reform.judicialapi.elinks.repository.ProfileRepository;
29+
import uk.gov.hmcts.reform.judicialapi.elinks.response.ElinkLocationWrapperResponse;
30+
import uk.gov.hmcts.reform.judicialapi.elinks.scheduler.ElinksApiJobScheduler;
31+
import uk.gov.hmcts.reform.judicialapi.elinks.service.PublishSidamIdService;
32+
import uk.gov.hmcts.reform.judicialapi.elinks.servicebus.ElinkTopicPublisher;
33+
import uk.gov.hmcts.reform.judicialapi.elinks.util.ElinksEnabledIntegrationTest;
34+
import uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants;
35+
import uk.gov.hmcts.reform.judicialapi.versions.V2;
36+
37+
import java.util.List;
38+
import java.util.Map;
39+
40+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
41+
import static com.github.tomakehurst.wiremock.client.WireMock.get;
42+
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
43+
import static org.assertj.core.api.Assertions.assertThat;
44+
import static org.junit.Assert.assertEquals;
45+
import static org.junit.Assert.assertTrue;
46+
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.BASE_LOCATION_DATA_LOAD_SUCCESS;
47+
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.LOCATIONAPI;
48+
49+
class ElinksEndToEndIntegrationForSidamIdisPresent extends ElinksEnabledIntegrationTest {
50+
51+
@Autowired
52+
LocationRepository locationRepository;
53+
@Autowired
54+
ProfileRepository profileRepository;
55+
@Autowired
56+
JudicialRoleTypeRepository judicialRoleTypeRepository;
57+
@Autowired
58+
BaseLocationRepository baseLocationRepository;
59+
@Autowired
60+
AuthorisationsRepository authorisationsRepository;
61+
@Autowired
62+
AppointmentsRepository appointmentsRepository;
63+
@Autowired
64+
IdamTokenConfigProperties tokenConfigProperties;
65+
66+
67+
@Autowired
68+
private ElinkSchedularAuditRepository elinkSchedularAuditRepository;
69+
70+
@Autowired
71+
private ElinksApiJobScheduler elinksApiJobScheduler;
72+
73+
@Autowired
74+
private DataloadSchedulerJobRepository dataloadSchedulerJobRepository;
75+
76+
@Autowired
77+
PublishSidamIdService publishSidamIdService;
78+
79+
@MockBean
80+
ElinkTopicPublisher elinkTopicPublisher;
81+
82+
@Autowired
83+
ElinkDataExceptionRepository elinkDataExceptionRepository;
84+
85+
86+
87+
@BeforeAll
88+
void loadElinksResponse() throws Exception {
89+
90+
cleanupData();
91+
92+
String locationResponseValidationJson =
93+
loadJson("src/integrationTest/resources/wiremock_responses/location.json");
94+
String baselocationResponseValidationJson =
95+
loadJson("src/integrationTest/resources/wiremock_responses/base_location.json");
96+
String peopleResponseValidationJson =
97+
loadJson("src/integrationTest/resources/wiremock_responses/testpeople_withoutsidam.json");
98+
99+
elinks.stubFor(get(urlPathMatching("/reference_data/location"))
100+
.willReturn(aResponse()
101+
.withStatus(200)
102+
.withHeader("Content-Type", V2.MediaType.SERVICE)
103+
.withHeader("Connection", "close")
104+
.withBody(locationResponseValidationJson)));
105+
106+
elinks.stubFor(get(urlPathMatching("/reference_data/base_location"))
107+
.willReturn(aResponse()
108+
.withStatus(200)
109+
.withHeader("Content-Type", V2.MediaType.SERVICE)
110+
.withHeader("Connection", "close")
111+
.withBody(baselocationResponseValidationJson)
112+
.withTransformers("user-token-response")));
113+
114+
elinks.stubFor(get(urlPathMatching("/people"))
115+
.willReturn(aResponse()
116+
.withStatus(200)
117+
.withHeader("Content-Type", V2.MediaType.SERVICE)
118+
.withHeader("Connection", "close")
119+
.withBody(peopleResponseValidationJson)));
120+
}
121+
122+
@BeforeEach
123+
void before() {
124+
cleanupData();
125+
}
126+
127+
@AfterEach
128+
void cleanUp() {
129+
cleanupData();
130+
}
131+
132+
@DisplayName("Elinks end to test sidam is not updated")
133+
@Test
134+
void test_elinks_end_to_end_success_scenario_with_partial_success_return_status_200()
135+
throws JOSEException, JsonProcessingException {
136+
137+
ReflectionTestUtils.setField(elinksApiJobScheduler, "isSchedulerEnabled", true);
138+
ReflectionTestUtils.setField(publishSidamIdService, "elinkTopicPublisher", elinkTopicPublisher);
139+
140+
dataloadSchedulerJobRepository.deleteAll();
141+
elinksApiJobScheduler.loadElinksJob();
142+
143+
List<DataloadSchedulerJob> audits = dataloadSchedulerJobRepository.findAll();
144+
DataloadSchedulerJob jobDetails = audits.get(0);
145+
146+
//assserting scheduler data
147+
assertThat(jobDetails).isNotNull();
148+
assertThat(jobDetails.getPublishingStatus()).isNotNull();
149+
Assert.assertEquals(RefDataElinksConstants.JobStatus.SUCCESS.getStatus(),jobDetails.getPublishingStatus());
150+
151+
// asserting location data
152+
List<ElinkDataSchedularAudit> elinksAudit = elinkSchedularAuditRepository.findAll();
153+
Map<String, Object> locationResponse = elinksReferenceDataClient.getLocations();
154+
ElinkLocationWrapperResponse locations = (ElinkLocationWrapperResponse) locationResponse.get("body");
155+
ElinkDataSchedularAudit locationAuditEntry = elinksAudit.get(0);
156+
157+
assertThat(locationResponse).containsEntry("http_status", "200 OK");
158+
assertEquals(BASE_LOCATION_DATA_LOAD_SUCCESS, locations.getMessage());
159+
assertEquals(LOCATIONAPI,locationAuditEntry.getApiName());
160+
assertEquals(RefDataElinksConstants.JobStatus.SUCCESS.getStatus(), locationAuditEntry.getStatus());
161+
162+
163+
List<Location> locationsList = locationRepository.findAll();
164+
assertEquals(11, locationsList.size());
165+
assertEquals("1", locationsList.get(1).getRegionId());
166+
assertEquals("London", locationsList.get(1).getRegionDescEn());
167+
168+
169+
//asserting baselocation data
170+
List<BaseLocation> baseLocationList = baseLocationRepository.findAll();
171+
assertEquals(12, baseLocationList.size());
172+
assertEquals("Aberconwy",baseLocationList.get(4).getName());
173+
assertEquals("1",baseLocationList.get(4).getBaseLocationId());
174+
assertEquals("1722",baseLocationList.get(4).getParentId());
175+
176+
List<UserProfile> userprofile = profileRepository.findAll();
177+
assertEquals(11, userprofile.size());
178+
assertEquals("123454", userprofile.get(10).getPersonalCode());
179+
assertEquals("Rachel", userprofile.get(10).getKnownAs());
180+
assertEquals("Jones", userprofile.get(10).getSurname());
181+
assertEquals("District Judge Rachel Jones", userprofile.get(10).getFullName());
182+
assertEquals(null, userprofile.get(10).getPostNominals());
183+
assertEquals("DJ.Rachel.Jones@ejudiciary.net",
184+
userprofile.get(10).getEmailId());
185+
assertTrue(userprofile.get(10).getActiveFlag());
186+
assertEquals("5f8b26ba-0c8b-4192-b5c7-311d737f0cae", userprofile.get(10).getObjectId());
187+
assertEquals("3333333",userprofile.get(10).getSidamId());
188+
assertEquals("RJ",userprofile.get(10).getInitials());
189+
190+
191+
192+
//asserting userprofile data for leaver api
193+
194+
//asserting userprofile data for deleted api
195+
196+
}
197+
198+
private void cleanupData() {
199+
elinkSchedularAuditRepository.deleteAll();
200+
dataloadSchedulerJobRepository.deleteAll();
201+
}
202+
}

src/integrationTest/java/uk/gov/hmcts/reform/judicialapi/elinks/ElinksFailedApiPublishingStatusEndToEndIntegrationTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
import static org.mockito.ArgumentMatchers.anyList;
4848
import static org.mockito.ArgumentMatchers.anyString;
4949
import static org.powermock.api.mockito.PowerMockito.doNothing;
50+
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.DELETEDAPI;
5051
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.LEAVERSAPI;
5152
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.LOCATION;
5253
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.LOCATIONAPI;
53-
import static uk.gov.hmcts.reform.judicialapi.elinks.util.RefDataElinksConstants.PEOPLEAPI;
5454

5555
public class ElinksFailedApiPublishingStatusEndToEndIntegrationTest extends ElinksEnabledIntegrationTest {
5656

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

155155
assertThat(peopleResponse).containsEntry("http_status", "400");
156-
assertEquals(PEOPLEAPI,peopleAuditEntry.getApiName());
156+
assertEquals(LEAVERSAPI,peopleAuditEntry.getApiName());
157157
assertEquals(RefDataElinksConstants.JobStatus.FAILED.getStatus(), peopleAuditEntry.getStatus());
158158

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

167167
assertThat(leaversResponse).containsEntry("http_status", "400");
168-
assertEquals(LEAVERSAPI,leaversAuditEntry.getApiName());
168+
assertEquals(DELETEDAPI,leaversAuditEntry.getApiName());
169169
assertEquals(RefDataElinksConstants.JobStatus.FAILED.getStatus(), leaversAuditEntry.getStatus());
170170

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

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

179179
// asserting SIDAM publishing
180180
Map<String, Object> idamResponse = elinksReferenceDataClient.publishSidamIds();

src/integrationTest/java/uk/gov/hmcts/reform/judicialapi/elinks/ElinksLoadPeopleDataWithDuplicate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void test_elinks_end_to_end_success_scenario_with_return_status_200()
151151
assertEquals(RefDataElinksConstants.JobStatus.PARTIAL_SUCCESS.getStatus(), peopleAuditEntry.getStatus());
152152

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

0 commit comments

Comments
 (0)