From e0818d702fb2d715827986bc5ecc6f13d0678935 Mon Sep 17 00:00:00 2001 From: karen-hedges <133129444+karen-hedges@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:18:16 +0000 Subject: [PATCH] DMP-4613 Add ARM RPO check for getExtendedProductionsByMatter status Fixed tests --- ...GetExtendedProductionsByMatterIntTest.java | 3 - .../arm/service/ArmRpoPollServiceIntTest.java | 157 +++++++++++++++--- .../getExtendedProductionsByMatter.json | 1 - .../ExtendedProductionsByMatterResponse.java | 2 - .../darts/arm/rpo/impl/ArmRpoApiImpl.java | 3 +- ...ApiGetExtendedProductionsByMatterTest.java | 1 - 6 files changed, 136 insertions(+), 31 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/arm/rpo/ArmRpoApiGetExtendedProductionsByMatterIntTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/arm/rpo/ArmRpoApiGetExtendedProductionsByMatterIntTest.java index 56cce7ee09..c288efe482 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/arm/rpo/ArmRpoApiGetExtendedProductionsByMatterIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/arm/rpo/ArmRpoApiGetExtendedProductionsByMatterIntTest.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import static uk.gov.hmcts.darts.arm.enums.ArmRpoResponseStatusCode.READY_STATUS; class ArmRpoApiGetExtendedProductionsByMatterIntTest extends IntegrationBase { @@ -42,7 +41,6 @@ void getExtendedSearchesByMatter_ReturnsTrue() { extendedProductionsByMatterResponse.setIsError(false); ExtendedProductionsByMatterResponse.Productions productions = new ExtendedProductionsByMatterResponse.Productions(); productions.setProductionId("1234"); - productions.setStatus(READY_STATUS.getStatusCode()); productions.setName(PRODUCTION_NAME); productions.setEndProductionTime(END_PRODUCTION_TIME); extendedProductionsByMatterResponse.setProductions(List.of(productions)); @@ -77,7 +75,6 @@ void getExtendedSearchesByMatter_ReturnsFalse_WhenEndProductionTimeIsNullInProgr extendedProductionsByMatterResponse.setIsError(false); ExtendedProductionsByMatterResponse.Productions productions = new ExtendedProductionsByMatterResponse.Productions(); productions.setProductionId("1234"); - productions.setStatus(2); productions.setName(PRODUCTION_NAME); extendedProductionsByMatterResponse.setProductions(List.of(productions)); diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/arm/service/ArmRpoPollServiceIntTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/arm/service/ArmRpoPollServiceIntTest.java index c545dd0bc9..bfebfc25f4 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/arm/service/ArmRpoPollServiceIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/arm/service/ArmRpoPollServiceIntTest.java @@ -46,6 +46,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import static uk.gov.hmcts.darts.arm.enums.ArmRpoResponseStatusCode.READY_STATUS; import static uk.gov.hmcts.darts.test.common.data.PersistableFactory.getArmRpoExecutionDetailTestData; @TestPropertySource(properties = {"darts.storage.arm.is-mock-arm-rpo-download-csv=false"}) @@ -62,6 +63,8 @@ class ArmRpoPollServiceIntTest extends PostgresIntegrationBase { private static final String STORAGE_ACCOUNT_ID = "StorageAccountId"; private static final String PROPERTY_NAME = "propertyName"; private static final String INGESTION_DATE = "ingestionDate"; + private static final int HTTP_STATUS_OK = 200; + private static final int HTTP_STATUS_400 = 400; @MockBean private UserIdentity userIdentity; @@ -119,7 +122,7 @@ void pollArmRpo_shouldPollSuccessfully_WithSaveBackgroundCompleted() throws IOEx .thenReturn(getProductionOutputFilesResponse(PRODUCTION_ID)); when(armRpoDownloadProduction.downloadProduction(any(), any(), any())) - .thenReturn(getFeignResponse(200)); + .thenReturn(getFeignResponse(HTTP_STATUS_OK)); when(armRpoClient.removeProduction(any(), any())) .thenReturn(getRemoveProductionResponse()); @@ -168,7 +171,7 @@ void pollArmRpo_shouldPollSuccessfully_WithGetExtendedSearchesByMatterInProgress .thenReturn(getProductionOutputFilesResponse(PRODUCTION_ID)); when(armRpoDownloadProduction.downloadProduction(any(), any(), any())) - .thenReturn(getFeignResponse(200)); + .thenReturn(getFeignResponse(HTTP_STATUS_OK)); when(armRpoClient.removeProduction(any(), any())) .thenReturn(getRemoveProductionResponse()); @@ -195,7 +198,7 @@ void pollArmRpo_shouldPollSuccessfully_WithGetExtendedSearchesByMatterInProgress } @Test - void pollArmRpo_shouldPollSuccessfully_WithSaveBackgroundCompletedCreateExportInProgress() { + void pollArmRpo_shouldPollSuccessfully_WithSaveBackgroundCompletedAndFinishWithCreateExportInProgress() { // given armRpoExecutionDetailEntity.setArmRpoStatus(ArmRpoHelper.completedRpoStatus()); armRpoExecutionDetailEntity.setArmRpoState(ArmRpoHelper.saveBackgroundSearchRpoState()); @@ -230,7 +233,107 @@ void pollArmRpo_shouldPollSuccessfully_WithSaveBackgroundCompletedCreateExportIn } @Test - void pollArmRpo_shouldPollSuccessfullyWithFailedDownloadProductionIsManual() throws IOException { + void pollArmRpo_shouldPollSuccessfully_WithGetExtendedProductionsByMatterInProgress() throws IOException { + // given + armRpoExecutionDetailEntity.setArmRpoStatus(ArmRpoHelper.inProgressRpoStatus()); + armRpoExecutionDetailEntity.setArmRpoState(ArmRpoHelper.getExtendedSearchesByMatterRpoState()); + armRpoExecutionDetailEntity.setMatterId(MATTER_ID); + armRpoExecutionDetailEntity.setSearchId(SEARCH_ID); + armRpoExecutionDetailEntity.setStorageAccountId(STORAGE_ACCOUNT_ID); + armRpoExecutionDetailEntity.setProductionId(PRODUCTION_ID); + armRpoExecutionDetailEntity = dartsPersistence.save(armRpoExecutionDetailEntity); + + when(armApiService.getArmBearerToken()).thenReturn(BEARER_TOKEN); + when(armRpoClient.getExtendedSearchesByMatter(any(), any())) + .thenReturn(getExtendedSearchesByMatterResponse()); + when(armRpoClient.getMasterIndexFieldByRecordClassSchema(any(), any())) + .thenReturn(getMasterIndexFieldByRecordClassSchemaResponse(PROPERTY_NAME, INGESTION_DATE)); + when(armRpoClient.createExportBasedOnSearchResultsTable(anyString(), any())) + .thenReturn(getCreateExportBasedOnSearchResultsTableResponse()); + when(armRpoClient.getExtendedProductionsByMatter(anyString(), any())) + .thenReturn(getExtendedProductionsByMatterResponse()); + when(armRpoClient.getProductionOutputFiles(any(), any())) + .thenReturn(getProductionOutputFilesResponse(PRODUCTION_ID)); + + when(armRpoDownloadProduction.downloadProduction(any(), any(), any())) + .thenReturn(getFeignResponse(HTTP_STATUS_OK)); + + when(armRpoClient.removeProduction(any(), any())) + .thenReturn(getRemoveProductionResponse()); + + // when + armRpoPollService.pollArmRpo(false); + + // then + var updatedArmRpoExecutionDetailEntity = dartsPersistence.getArmRpoExecutionDetailRepository().findById(armRpoExecutionDetailEntity.getId()); + assertNotNull(updatedArmRpoExecutionDetailEntity); + assertEquals(ArmRpoHelper.removeProductionRpoState().getId(), updatedArmRpoExecutionDetailEntity.get().getArmRpoState().getId()); + assertEquals(ArmRpoHelper.completedRpoStatus().getId(), updatedArmRpoExecutionDetailEntity.get().getArmRpoStatus().getId()); + + verify(armRpoClient).getExtendedSearchesByMatter(any(), any()); + verify(armRpoClient).getMasterIndexFieldByRecordClassSchema(any(), any()); + verify(armRpoClient).createExportBasedOnSearchResultsTable(anyString(), any()); + verify(armRpoClient).getExtendedProductionsByMatter(anyString(), any()); + verify(armRpoClient).getProductionOutputFiles(any(), any()); + verify(armRpoDownloadProduction).downloadProduction(any(), any(), any()); + verify(armRpoClient).removeProduction(any(), any()); + + verifyNoMoreInteractions(armRpoClient); + + } + + @Test + void pollArmRpo_shouldPollSuccessfully_WithGetProductionOutputFilesInProgress() throws IOException { + // given + armRpoExecutionDetailEntity.setArmRpoStatus(ArmRpoHelper.inProgressRpoStatus()); + armRpoExecutionDetailEntity.setArmRpoState(ArmRpoHelper.getProductionOutputFilesRpoState()); + armRpoExecutionDetailEntity.setMatterId(MATTER_ID); + armRpoExecutionDetailEntity.setSearchId(SEARCH_ID); + armRpoExecutionDetailEntity.setStorageAccountId(STORAGE_ACCOUNT_ID); + armRpoExecutionDetailEntity.setProductionId(PRODUCTION_ID); + armRpoExecutionDetailEntity = dartsPersistence.save(armRpoExecutionDetailEntity); + + when(armApiService.getArmBearerToken()).thenReturn(BEARER_TOKEN); + when(armRpoClient.getExtendedSearchesByMatter(any(), any())) + .thenReturn(getExtendedSearchesByMatterResponse()); + when(armRpoClient.getMasterIndexFieldByRecordClassSchema(any(), any())) + .thenReturn(getMasterIndexFieldByRecordClassSchemaResponse(PROPERTY_NAME, INGESTION_DATE)); + when(armRpoClient.createExportBasedOnSearchResultsTable(anyString(), any())) + .thenReturn(getCreateExportBasedOnSearchResultsTableResponse()); + when(armRpoClient.getExtendedProductionsByMatter(anyString(), any())) + .thenReturn(getExtendedProductionsByMatterResponse()); + when(armRpoClient.getProductionOutputFiles(any(), any())) + .thenReturn(getProductionOutputFilesResponse(PRODUCTION_ID)); + + when(armRpoDownloadProduction.downloadProduction(any(), any(), any())) + .thenReturn(getFeignResponse(HTTP_STATUS_OK)); + + when(armRpoClient.removeProduction(any(), any())) + .thenReturn(getRemoveProductionResponse()); + + // when + armRpoPollService.pollArmRpo(false); + + // then + var updatedArmRpoExecutionDetailEntity = dartsPersistence.getArmRpoExecutionDetailRepository().findById(armRpoExecutionDetailEntity.getId()); + assertNotNull(updatedArmRpoExecutionDetailEntity); + assertEquals(ArmRpoHelper.removeProductionRpoState().getId(), updatedArmRpoExecutionDetailEntity.get().getArmRpoState().getId()); + assertEquals(ArmRpoHelper.completedRpoStatus().getId(), updatedArmRpoExecutionDetailEntity.get().getArmRpoStatus().getId()); + + verify(armRpoClient).getExtendedSearchesByMatter(any(), any()); + verify(armRpoClient).getMasterIndexFieldByRecordClassSchema(any(), any()); + verify(armRpoClient).createExportBasedOnSearchResultsTable(anyString(), any()); + verify(armRpoClient).getExtendedProductionsByMatter(anyString(), any()); + verify(armRpoClient).getProductionOutputFiles(any(), any()); + verify(armRpoDownloadProduction).downloadProduction(any(), any(), any()); + verify(armRpoClient).removeProduction(any(), any()); + + verifyNoMoreInteractions(armRpoClient); + + } + + @Test + void pollArmRpo_shouldPollSuccessfully_WithFailedDownloadProductionIsManual() throws IOException { // given armRpoExecutionDetailEntity.setArmRpoStatus(ArmRpoHelper.failedRpoStatus()); armRpoExecutionDetailEntity.setArmRpoState(ArmRpoHelper.downloadProductionRpoState()); @@ -253,7 +356,7 @@ void pollArmRpo_shouldPollSuccessfullyWithFailedDownloadProductionIsManual() thr .thenReturn(getProductionOutputFilesResponse(PRODUCTION_ID)); when(armRpoDownloadProduction.downloadProduction(any(), any(), any())) - .thenReturn(getFeignResponse(200)); + .thenReturn(getFeignResponse(HTTP_STATUS_OK)); when(armRpoClient.removeProduction(any(), any())) .thenReturn(getRemoveProductionResponse()); @@ -280,7 +383,7 @@ void pollArmRpo_shouldPollSuccessfullyWithFailedDownloadProductionIsManual() thr private @NotNull RemoveProductionResponse getRemoveProductionResponse() { RemoveProductionResponse response = new RemoveProductionResponse(); - response.setStatus(200); + response.setStatus(HTTP_STATUS_OK); response.setIsError(false); return response; } @@ -325,18 +428,18 @@ public void close() throws IOException { .body(body) .request(request) .build(); - } private @NotNull ProductionOutputFilesResponse getProductionOutputFilesResponse(String fileId) { var productionExportFileDetail = new ProductionOutputFilesResponse.ProductionExportFileDetail(); productionExportFileDetail.setProductionExportFileId(fileId); + productionExportFileDetail.setStatus(READY_STATUS.getStatusCode()); var productionExportFile = new ProductionOutputFilesResponse.ProductionExportFile(); productionExportFile.setProductionExportFileDetails(productionExportFileDetail); var response = new ProductionOutputFilesResponse(); - response.setStatus(200); + response.setStatus(HTTP_STATUS_OK); response.setIsError(false); response.setProductionExportFiles(Collections.singletonList(productionExportFile)); @@ -345,19 +448,19 @@ public void close() throws IOException { private @NotNull ExtendedProductionsByMatterResponse getExtendedProductionsByMatterResponse() { ExtendedProductionsByMatterResponse response = new ExtendedProductionsByMatterResponse(); - response.setStatus(200); + response.setStatus(HTTP_STATUS_OK); response.setIsError(false); ExtendedProductionsByMatterResponse.Productions productions = new ExtendedProductionsByMatterResponse.Productions(); productions.setProductionId(PRODUCTION_ID); productions.setName(PRODUCTION_NAME); - productions.setStatus(4); + productions.setEndProductionTime("2025-01-16T12:30:09.9129726+00:00"); response.setProductions(List.of(productions)); return response; } private @NotNull CreateExportBasedOnSearchResultsTableResponse getCreateExportBasedOnSearchResultsTableResponse() { CreateExportBasedOnSearchResultsTableResponse response = new CreateExportBasedOnSearchResultsTableResponse(); - response.setStatus(200); + response.setStatus(HTTP_STATUS_OK); response.setIsError(false); response.setResponseStatus(2); return response; @@ -365,7 +468,7 @@ public void close() throws IOException { private @NotNull CreateExportBasedOnSearchResultsTableResponse getCreateExportBasedOnSearchResultsTableResponseInProgress() { CreateExportBasedOnSearchResultsTableResponse response = new CreateExportBasedOnSearchResultsTableResponse(); - response.setStatus(400); + response.setStatus(HTTP_STATUS_400); response.setIsError(false); response.setResponseStatus(2); return response; @@ -373,28 +476,38 @@ public void close() throws IOException { private @NotNull MasterIndexFieldByRecordClassSchemaResponse getMasterIndexFieldByRecordClassSchemaResponse(String propertyName1, String propertyName2) { - MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField masterIndexField1 = new MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField(); - masterIndexField1.setMasterIndexFieldId("1"); - masterIndexField1.setDisplayName("displayName"); - masterIndexField1.setPropertyName(propertyName1); - masterIndexField1.setPropertyType("propertyType"); - masterIndexField1.setIsMasked(true); + MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField masterIndexField1 = getMasterIndexField1(propertyName1); + + MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField masterIndexField2 = getMasterIndexField2(propertyName2); + MasterIndexFieldByRecordClassSchemaResponse response = new MasterIndexFieldByRecordClassSchemaResponse(); + response.setMasterIndexFields(List.of(masterIndexField1, masterIndexField2)); + return response; + } + + private static MasterIndexFieldByRecordClassSchemaResponse.@NotNull MasterIndexField getMasterIndexField2(String propertyName2) { MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField masterIndexField2 = new MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField(); masterIndexField2.setMasterIndexFieldId("2"); masterIndexField2.setDisplayName("displayName"); masterIndexField2.setPropertyName(propertyName2); masterIndexField2.setPropertyType("propertyType"); masterIndexField2.setIsMasked(false); + return masterIndexField2; + } - MasterIndexFieldByRecordClassSchemaResponse response = new MasterIndexFieldByRecordClassSchemaResponse(); - response.setMasterIndexFields(List.of(masterIndexField1, masterIndexField2)); - return response; + private static MasterIndexFieldByRecordClassSchemaResponse.@NotNull MasterIndexField getMasterIndexField1(String propertyName1) { + MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField masterIndexField1 = new MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField(); + masterIndexField1.setMasterIndexFieldId("1"); + masterIndexField1.setDisplayName("displayName"); + masterIndexField1.setPropertyName(propertyName1); + masterIndexField1.setPropertyType("propertyType"); + masterIndexField1.setIsMasked(true); + return masterIndexField1; } private ExtendedSearchesByMatterResponse getExtendedSearchesByMatterResponse() { ExtendedSearchesByMatterResponse response = new ExtendedSearchesByMatterResponse(); - response.setStatus(200); + response.setStatus(HTTP_STATUS_OK); response.setIsError(false); ExtendedSearchesByMatterResponse.Search search = new ExtendedSearchesByMatterResponse.Search(); search.setTotalCount(4); diff --git a/src/integrationTest/resources/tests/arm/client/ArmRpoClientIntTest/expectedResponse/getExtendedProductionsByMatter.json b/src/integrationTest/resources/tests/arm/client/ArmRpoClientIntTest/expectedResponse/getExtendedProductionsByMatter.json index cb745c266a..1fd57c0c73 100644 --- a/src/integrationTest/resources/tests/arm/client/ArmRpoClientIntTest/expectedResponse/getExtendedProductionsByMatter.json +++ b/src/integrationTest/resources/tests/arm/client/ArmRpoClientIntTest/expectedResponse/getExtendedProductionsByMatter.json @@ -8,7 +8,6 @@ { "productionID": "1b6a29d9-a72e-420b-8d69-b8acbeed806a", "name": "DARTS_RPO_2024-08-13_CSV", - "status": 4, "startProductionTime": "2024-08-13T16:50:15.4091127+00:00", "endProductionTime": "2024-08-13T16:50:21.1592576+00:00" } diff --git a/src/main/java/uk/gov/hmcts/darts/arm/client/model/rpo/ExtendedProductionsByMatterResponse.java b/src/main/java/uk/gov/hmcts/darts/arm/client/model/rpo/ExtendedProductionsByMatterResponse.java index fcae3f7e1a..b9745cd934 100644 --- a/src/main/java/uk/gov/hmcts/darts/arm/client/model/rpo/ExtendedProductionsByMatterResponse.java +++ b/src/main/java/uk/gov/hmcts/darts/arm/client/model/rpo/ExtendedProductionsByMatterResponse.java @@ -26,8 +26,6 @@ public static class Productions { @JsonProperty("productionID") private String productionId; - @JsonProperty("status") - private Integer status; @JsonProperty("name") private String name; @JsonProperty("startProductionTime") diff --git a/src/main/java/uk/gov/hmcts/darts/arm/rpo/impl/ArmRpoApiImpl.java b/src/main/java/uk/gov/hmcts/darts/arm/rpo/impl/ArmRpoApiImpl.java index 93d69a78d7..71cfaaf74c 100644 --- a/src/main/java/uk/gov/hmcts/darts/arm/rpo/impl/ArmRpoApiImpl.java +++ b/src/main/java/uk/gov/hmcts/darts/arm/rpo/impl/ArmRpoApiImpl.java @@ -594,8 +594,7 @@ private boolean processExtendedProductionsByMatterResponse(String productionName log.warn(errorMessage.append("No production id found against the production name: " + productionName + ", so continue polling").toString()); return false; } - if (StringUtils.isBlank(productionMatch.getProductionId()) - || isNull(productionMatch.getStatus())) { + if (StringUtils.isBlank(productionMatch.getProductionId())) { throw handleFailureAndCreateException(errorMessage.append("Production Id or status is missing from ARM RPO response").toString(), armRpoExecutionDetailEntity, userAccount); } diff --git a/src/test/java/uk/gov/hmcts/darts/arm/rpo/impl/ArmRpoApiGetExtendedProductionsByMatterTest.java b/src/test/java/uk/gov/hmcts/darts/arm/rpo/impl/ArmRpoApiGetExtendedProductionsByMatterTest.java index 1772adeebb..49990d2e3a 100644 --- a/src/test/java/uk/gov/hmcts/darts/arm/rpo/impl/ArmRpoApiGetExtendedProductionsByMatterTest.java +++ b/src/test/java/uk/gov/hmcts/darts/arm/rpo/impl/ArmRpoApiGetExtendedProductionsByMatterTest.java @@ -64,7 +64,6 @@ void getExtendedProductionsByMatter_Success() { extendedProductionsByMatterResponse.setIsError(false); ExtendedProductionsByMatterResponse.Productions productions = new ExtendedProductionsByMatterResponse.Productions(); productions.setProductionId("12345"); - productions.setStatus(4); productions.setName(PRODUCTION_NAME); productions.setStartProductionTime("2025-01-16T12:30:02.9343888+00:00"); productions.setEndProductionTime("2025-01-16T12:30:09.9129726+00:00");