|
| 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 | +} |
0 commit comments