Skip to content

Commit

Permalink
DMP-4613 Add ARM RPO check for getExtendedProductionsByMatter status
Browse files Browse the repository at this point in the history
Fixed tests
  • Loading branch information
karen-hedges committed Jan 21, 2025
1 parent a5af1be commit e0818d7
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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));
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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;
}
Expand Down Expand Up @@ -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));

Expand All @@ -345,56 +448,66 @@ 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;
}

private @NotNull CreateExportBasedOnSearchResultsTableResponse getCreateExportBasedOnSearchResultsTableResponseInProgress() {
CreateExportBasedOnSearchResultsTableResponse response = new CreateExportBasedOnSearchResultsTableResponse();
response.setStatus(400);
response.setStatus(HTTP_STATUS_400);
response.setIsError(false);
response.setResponseStatus(2);
return response;
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit e0818d7

Please sign in to comment.