Skip to content

Commit

Permalink
Merge branch 'master' into DMP-4616
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Edwards-cgi authored Jan 23, 2025
2 parents c6a6433 + 488e85a commit 7a959fc
Show file tree
Hide file tree
Showing 27 changed files with 823 additions and 297 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ plugins {
id 'org.owasp.dependencycheck' version '11.1.1'
id 'com.github.ben-manes.versions' version '0.51.0'
id 'org.sonarqube' version '6.0.1.5171'
id "io.freefair.lombok" version "8.11"
id "org.openapi.generator" version "7.10.0"
id "io.freefair.lombok" version "8.12"
id "org.openapi.generator" version "7.11.0"
id "org.flywaydb.flyway" version "10.22.0"
id 'maven-publish'
id("com.dorongold.task-tree") version "4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/.terraform-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.4
1.10.5
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,12 @@ private static Stream<Arguments> genericArmRpoClientTestArguments() {
);
}


@AllArgsConstructor
static class ClientCallable {
Object request;
Object response;
}


@ParameterizedTest(name = "{0} should succeed when server returns 200")
@MethodSource("genericArmRpoClientTestArguments")
void generic_serverReturns200Success_ShouldSucceed(String suffix, BiFunction<ArmRpoClient, String, ClientCallable> callClient) throws IOException {
Expand All @@ -176,7 +174,6 @@ void generic_serverReturns200Success_ShouldSucceed(String suffix, BiFunction<Arm

if (clientCallable.request != null) {
requestPatternBuilder.withRequestBody(equalTo(TestUtils.writeAsString(clientCallable.request)));

}
verify(requestPatternBuilder);
JSONAssert.assertEquals(TestUtils.getContentsFromFile(EXPECTED_RESPONSE_DIRECTORY + suffix + ".json"),
Expand Down Expand Up @@ -208,7 +205,6 @@ void downloadProduction_serverReturns200Success_ShouldSucceed() throws IOExcepti
}
}


@Test
void getRecordManagementMatter_ShouldSucceedIfServerReturns200Success_WithEmptyRequest() throws Exception {
// Given
Expand All @@ -222,7 +218,7 @@ void getRecordManagementMatter_ShouldSucceedIfServerReturns200Success_WithEmptyR
.withHeader("Content-type", "application/json")
.withBody(TestUtils.getContentsFromFile(MOCK_RESPONSE_DIRECTORY + "getRecordManagementMatter.json"))
.withStatus(200)));

// When
armRpoClient.getRecordManagementMatter(bearerAuth, request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ArmRpoApiCreateExportBasedOnSearchResultsTableIntTest extends PostgresInte
@Autowired
private ArmRpoApi armRpoApi;


@Test
void createExportBasedOnSearchResultsTable_ReturnsTrue() {
// given
Expand Down Expand Up @@ -101,9 +100,8 @@ void createExportBasedOnSearchResultsTable_ReturnsFalse_WhenInProgress() {
private List<MasterIndexFieldByRecordClassSchema> createHeaderColumns() {
return List.of(
createMasterIndexFieldByRecordClassSchema("200b9c27-b497-4977-82e7-1586b32a5871", "Record Class", "record_class", "string", false),
createMasterIndexFieldByRecordClassSchema("90ee0e13-8639-4c4a-b542-66b6c8911549", "Archived Date", "ingestionDate", "date", false),
createMasterIndexFieldByRecordClassSchema("a9b8daf2-d9ff-4815-b65a-f6ae2763b92c", "Client Identifier", "client_identifier", "string",
false),
createMasterIndexFieldByRecordClassSchema("90ee0e13-8639-4c4a-b542-66b6c8911549", "Archived Date", "ingestionDate", "date", true),
createMasterIndexFieldByRecordClassSchema("a9b8daf2-d9ff-4815-b65a-f6ae2763b92c", "Client Identifier", "client_identifier", "string", false),
createMasterIndexFieldByRecordClassSchema("109b6bf1-57a0-48ec-b22e-c7248dc74f91", "Contributor", "contributor", "string", false),
createMasterIndexFieldByRecordClassSchema("893048bf-1e7c-4811-9abf-00cd77a715cf", "Record Date", "recordDate", "date", false),
createMasterIndexFieldByRecordClassSchema("fdd0fcbb-da46-4af1-a627-ac255c12bb23", "ObjectId", "bf_012", "number", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

class ArmRpoApiGetExtendedProductionsByMatterIntTest extends IntegrationBase {

private static final String PRODUCTION_NAME = "DARTS_RPO_2024-08-13";
public static final String END_PRODUCTION_TIME = "2025-01-16T12:30:09.9129726+00:00";
@MockBean
private ArmRpoClient armRpoClient;

Expand All @@ -30,13 +34,15 @@ class ArmRpoApiGetExtendedProductionsByMatterIntTest extends IntegrationBase {
private ArmRpoApi armRpoApi;

@Test
void getExtendedSearchesByMatterSuccess() {
void getExtendedSearchesByMatter_ReturnsTrue() {
// given
ExtendedProductionsByMatterResponse extendedProductionsByMatterResponse = new ExtendedProductionsByMatterResponse();
extendedProductionsByMatterResponse.setStatus(200);
extendedProductionsByMatterResponse.setIsError(false);
ExtendedProductionsByMatterResponse.Productions productions = new ExtendedProductionsByMatterResponse.Productions();
productions.setProductionId("4");
productions.setProductionId("1234");
productions.setName(PRODUCTION_NAME);
productions.setEndProductionTime(END_PRODUCTION_TIME);
extendedProductionsByMatterResponse.setProductions(List.of(productions));

when(armRpoClient.getExtendedProductionsByMatter(any(), any())).thenReturn(extendedProductionsByMatterResponse);
Expand All @@ -50,13 +56,46 @@ void getExtendedSearchesByMatterSuccess() {
var bearerAuth = "Bearer some-token";

// when
armRpoApi.getExtendedProductionsByMatter(bearerAuth, armRpoExecutionDetail.getId(), userAccount);
var result = armRpoApi.getExtendedProductionsByMatter(bearerAuth, armRpoExecutionDetail.getId(), PRODUCTION_NAME, userAccount);

// then
assertTrue(result);
var armRpoExecutionDetailEntityUpdated = dartsPersistence.getArmRpoExecutionDetailRepository().findById(armRpoExecutionDetail.getId()).get();
assertEquals(ArmRpoStateEnum.GET_EXTENDED_PRODUCTIONS_BY_MATTER.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoState().getId());
assertEquals(ArmRpoStatusEnum.COMPLETED.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoStatus().getId());
assertEquals("4", armRpoExecutionDetailEntityUpdated.getProductionId());
assertEquals("1234", armRpoExecutionDetailEntityUpdated.getProductionId());

}

@Test
void getExtendedSearchesByMatter_ReturnsFalse_WhenEndProductionTimeIsNullInProgress() {
// given
ExtendedProductionsByMatterResponse extendedProductionsByMatterResponse = new ExtendedProductionsByMatterResponse();
extendedProductionsByMatterResponse.setStatus(200);
extendedProductionsByMatterResponse.setIsError(false);
ExtendedProductionsByMatterResponse.Productions productions = new ExtendedProductionsByMatterResponse.Productions();
productions.setProductionId("1234");
productions.setName(PRODUCTION_NAME);
extendedProductionsByMatterResponse.setProductions(List.of(productions));

when(armRpoClient.getExtendedProductionsByMatter(any(), any())).thenReturn(extendedProductionsByMatterResponse);

UserAccountEntity userAccount = dartsDatabase.getUserAccountStub().getIntegrationTestUserAccountEntity();
ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity = new ArmRpoExecutionDetailEntity();
armRpoExecutionDetailEntity.setMatterId("1");
armRpoExecutionDetailEntity.setCreatedBy(userAccount);
armRpoExecutionDetailEntity.setLastModifiedBy(userAccount);
var armRpoExecutionDetail = dartsPersistence.save(armRpoExecutionDetailEntity);
var bearerAuth = "Bearer some-token";

// when
var result = armRpoApi.getExtendedProductionsByMatter(bearerAuth, armRpoExecutionDetail.getId(), PRODUCTION_NAME, userAccount);

// then
assertFalse(result);
var armRpoExecutionDetailEntityUpdated = dartsPersistence.getArmRpoExecutionDetailRepository().findById(armRpoExecutionDetail.getId()).get();
assertEquals(ArmRpoStateEnum.GET_EXTENDED_PRODUCTIONS_BY_MATTER.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoState().getId());
assertEquals(ArmRpoStatusEnum.IN_PROGRESS.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoStatus().getId());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void getIndexesByMatterIdShouldFailWithMissingMatterId() {

// then
assertThat(armRpoException.getMessage(), containsString(
"Failure during ARM RPO get indexes by matter ID: Unable to find indexes by matter ID in response"));
"Failure during ARM RPO get indexes by matter ID: Unable to find any indexes by matter ID in response"));
var armRpoExecutionDetailEntityUpdated = dartsPersistence.getArmRpoExecutionDetailRepository().findById(armRpoExecutionDetail.getId()).orElseThrow();
assertEquals(ArmRpoStateEnum.GET_INDEXES_BY_MATTERID.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoState().getId());
assertEquals(ArmRpoStatusEnum.FAILED.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoStatus().getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.darts.arm.enums.ArmRpoResponseStatusCode.READY_STATUS;

@SuppressWarnings("checkstyle:linelength")
class ArmRpoApiGetProductionOutputFilesIntTest extends PostgresIntegrationBase {
Expand All @@ -36,12 +37,13 @@ class ArmRpoApiGetProductionOutputFilesIntTest extends PostgresIntegrationBase {

private static final String TOKEN = "some token";
private static final String PRODUCTION_ID = UUID.randomUUID().toString();
private static final String PRODUCTION_EXPORT_FILE_ID = UUID.randomUUID().toString();
private static final String PRODUCTION_EXPORT_FILE_ID1 = UUID.randomUUID().toString();
private static final String PRODUCTION_EXPORT_FILE_ID2 = UUID.randomUUID().toString();

@Test
void getProductionOutputFiles_shouldSucceedAndReturnASingleItem_whenASuccessResponseIsReturnedFromArmWithASingularProductionExportFile() {
void getProductionOutputFiles_shouldSucceedAndReturnSingleItem_whenSuccessResponseIsReturnedFromArmWithSingularProductionExportFile() {
// Given
var productionOutputFilesResponse = createProductionOutputFilesResponse(PRODUCTION_EXPORT_FILE_ID);
var productionOutputFilesResponse = createProductionOutputFilesResponse(PRODUCTION_EXPORT_FILE_ID1);
when(armRpoClient.getProductionOutputFiles(eq(TOKEN), any(ProductionOutputFilesRequest.class)))
.thenReturn(productionOutputFilesResponse);

Expand All @@ -56,14 +58,40 @@ void getProductionOutputFiles_shouldSucceedAndReturnASingleItem_whenASuccessResp

// Then
assertEquals(1, productionOutputFiles.size());
assertEquals(PRODUCTION_EXPORT_FILE_ID, productionOutputFiles.getFirst());
assertEquals(PRODUCTION_EXPORT_FILE_ID1, productionOutputFiles.getFirst());

executionDetailEntity = dartsPersistence.getArmRpoExecutionDetailRepository().findById(executionId)
.orElseThrow();
assertEquals(ArmRpoStateEnum.GET_PRODUCTION_OUTPUT_FILES.getId(), executionDetailEntity.getArmRpoState().getId());
assertEquals(ArmRpoStatusEnum.COMPLETED.getId(), executionDetailEntity.getArmRpoStatus().getId());
}

@Test
void getProductionOutputFiles_shouldSucceedAndReturnMultipleItems_whenSuccessResponseIsReturnedFromArmWithSingularProductionExportFile() {
// Given
var productionOutputFilesResponse = createMultipleProductionOutputFilesResponse(PRODUCTION_EXPORT_FILE_ID1, PRODUCTION_EXPORT_FILE_ID2);
when(armRpoClient.getProductionOutputFiles(eq(TOKEN), any(ProductionOutputFilesRequest.class)))
.thenReturn(productionOutputFilesResponse);

UserAccountEntity userAccount = dartsDatabase.getUserAccountStub().getIntegrationTestUserAccountEntity();
var executionDetailEntity = createExecutionDetailEntity(userAccount);
executionDetailEntity = dartsPersistence.save(executionDetailEntity);

Integer executionId = executionDetailEntity.getId();

// When
List<String> productionOutputFiles = armRpoApi.getProductionOutputFiles(TOKEN, executionId, userAccount);

// Then
assertEquals(2, productionOutputFiles.size());
assertEquals(PRODUCTION_EXPORT_FILE_ID1, productionOutputFiles.getFirst());
assertEquals(PRODUCTION_EXPORT_FILE_ID2, productionOutputFiles.get(1));

executionDetailEntity = dartsPersistence.getArmRpoExecutionDetailRepository().findById(executionId).orElseThrow();
assertEquals(ArmRpoStateEnum.GET_PRODUCTION_OUTPUT_FILES.getId(), executionDetailEntity.getArmRpoState().getId());
assertEquals(ArmRpoStatusEnum.COMPLETED.getId(), executionDetailEntity.getArmRpoStatus().getId());
}

@Test
void getProductionOutputFiles_shouldThrowException_whenArmReturnsNoProductionExportFiles() {
// Given
Expand All @@ -81,7 +109,7 @@ void getProductionOutputFiles_shouldThrowException_whenArmReturnsNoProductionExp
.getMessage();

// Then
assertThat(exceptionMessage, containsString("No production export file ids were returned"));
assertThat(exceptionMessage, containsString("ARM getProductionOutputFiles: No production export file id's were returned"));

executionDetailEntity = dartsPersistence.getArmRpoExecutionDetailRepository().findById(executionId)
.orElseThrow();
Expand All @@ -100,6 +128,7 @@ private ArmRpoExecutionDetailEntity createExecutionDetailEntity(UserAccountEntit
private ProductionOutputFilesResponse createProductionOutputFilesResponse(String fileId) {
var productionExportFileDetail = new ProductionOutputFilesResponse.ProductionExportFileDetail();
productionExportFileDetail.setProductionExportFileId(fileId);
productionExportFileDetail.setStatus(READY_STATUS.getStatusCode());

var productionExportFile = new ProductionOutputFilesResponse.ProductionExportFile();
productionExportFile.setProductionExportFileDetails(productionExportFileDetail);
Expand All @@ -112,4 +141,27 @@ private ProductionOutputFilesResponse createProductionOutputFilesResponse(String
return response;
}

private ProductionOutputFilesResponse createMultipleProductionOutputFilesResponse(String fileId1, String fileId2) {
var productionExportFileDetail1 = new ProductionOutputFilesResponse.ProductionExportFileDetail();
productionExportFileDetail1.setProductionExportFileId(fileId1);
productionExportFileDetail1.setStatus(READY_STATUS.getStatusCode());

var productionExportFile1 = new ProductionOutputFilesResponse.ProductionExportFile();
productionExportFile1.setProductionExportFileDetails(productionExportFileDetail1);

var productionExportFileDetail2 = new ProductionOutputFilesResponse.ProductionExportFileDetail();
productionExportFileDetail2.setProductionExportFileId(fileId2);
productionExportFileDetail2.setStatus(READY_STATUS.getStatusCode());

var productionExportFile2 = new ProductionOutputFilesResponse.ProductionExportFile();
productionExportFile2.setProductionExportFileDetails(productionExportFileDetail2);

var response = new ProductionOutputFilesResponse();
response.setStatus(200);
response.setIsError(false);
response.setProductionExportFiles(List.of(productionExportFile1, productionExportFile2));

return response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class ArmRpoGetProfileEntitlementsIntTest extends PostgresIntegrationBase {
private static final String ENTITLEMENT_ID = "some entitlement id";
private static final String ENTITLEMENT_NAME = "SRV-DARTS-RW-E";


@Test
void getProfileEntitlements_shouldSucceed_whenASuccessResponseIsObtainedFromArmThatContainsAMatchingEntitlement() {
// Given
Expand Down Expand Up @@ -86,7 +85,7 @@ void getProfileEntitlements_shouldFail_whenArmResponseDoesNotContainAMatchingEnt
.getMessage();

// Then
assertThat(exceptionMessage, containsString("No matching entitlements were returned"));
assertThat(exceptionMessage, containsString("ARM getProfileEntitlements: No matching entitlements 'SRV-DARTS-RW-E' were returned"));

executionDetailEntity = dartsPersistence.getArmRpoExecutionDetailRepository().findById(executionId)
.orElseThrow();
Expand Down
Loading

0 comments on commit 7a959fc

Please sign in to comment.