From 4329731f8a458769a0238cf25dca4837fc374f5a Mon Sep 17 00:00:00 2001 From: Andrew Porritt <109674546+porritta@users.noreply.github.com> Date: Mon, 20 May 2024 15:11:18 +0100 Subject: [PATCH] fix(ccls-2217): Add BaseEvidenceDocumentDetail for query response --- caab-api/open-api-specification.yml | 29 +++++++++++-------- ...BaseEvidenceControllerIntegrationTest.java | 25 ++++++++++++---- .../ccms/caab/api/mapper/EvidenceMapper.java | 6 ++++ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/caab-api/open-api-specification.yml b/caab-api/open-api-specification.yml index 847b21b..c725ad4 100644 --- a/caab-api/open-api-specification.yml +++ b/caab-api/open-api-specification.yml @@ -2429,8 +2429,8 @@ components: type: 'array' default: [] items: - $ref: '#/components/schemas/evidenceDocumentDetail' - evidenceDocumentDetail: + $ref: '#/components/schemas/baseEvidenceDocumentDetail' + baseEvidenceDocumentDetail: type: 'object' properties: id: @@ -2445,19 +2445,26 @@ components: $ref: '#/components/schemas/stringDisplayValue' description: type: 'string' - registered_document_id: + file_name: type: 'string' - document_sender: + file_extension: type: 'string' - transfer_status: + evidence_descriptions: type: 'string' - file_name: + audit_trail: + $ref: '#/components/schemas/auditDetail' + evidenceDocumentDetail: + type: 'object' + allOf: + - $ref: "#/components/schemas/baseEvidenceDocumentDetail" + properties: + registered_document_id: type: 'string' - file_extension: + ccms_module: type: 'string' file_data: type: 'string' - evidence_descriptions: + notification_reference: type: 'string' transfer_retry_count: type: 'integer' @@ -2465,12 +2472,10 @@ components: type: 'string' transfer_response_description: type: 'string' - ccms_module: + transfer_status: type: 'string' - notification_reference: + document_sender: type: 'string' - audit_trail: - $ref: '#/components/schemas/auditDetail' auditDetail: type: 'object' diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseEvidenceControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseEvidenceControllerIntegrationTest.java index 09e5658..908de5a 100644 --- a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseEvidenceControllerIntegrationTest.java +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseEvidenceControllerIntegrationTest.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.net.URI; import org.junit.jupiter.api.Test; @@ -12,6 +13,7 @@ import org.springframework.test.context.jdbc.Sql; import uk.gov.laa.ccms.caab.api.controller.EvidenceController; import uk.gov.laa.ccms.caab.api.service.EvidenceService; +import uk.gov.laa.ccms.caab.model.BaseEvidenceDocumentDetail; import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetail; import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetails; @@ -81,7 +83,7 @@ public void testGetEvidenceDocuments_byApplicationOrOutcomeId() { EvidenceDocumentDetail retrievedEvidenceDocumentDetails = evidenceService.getEvidenceDocument(3L); - assertEquals(retrievedEvidenceDocumentDetails, responseEntity.getBody().getContent().get(0)); + compareData(retrievedEvidenceDocumentDetails, responseEntity.getBody().getContent().getFirst()); } @Test @@ -109,7 +111,7 @@ public void testGetEvidenceDocuments_usingAllFields() { EvidenceDocumentDetail retrievedEvidenceDocumentDetails = evidenceService.getEvidenceDocument(3L); - assertEquals(retrievedEvidenceDocumentDetails, responseEntity.getBody().getContent().get(0)); + compareData(retrievedEvidenceDocumentDetails, responseEntity.getBody().getContent().getFirst()); } @Test @@ -137,7 +139,7 @@ public void testGetEvidenceDocuments_transferPending_filtersCorrectly() { EvidenceDocumentDetail retrievedEvidenceDocumentDetails = evidenceService.getEvidenceDocument(4L); - assertEquals(retrievedEvidenceDocumentDetails, responseEntity.getBody().getContent().get(0)); + compareData(retrievedEvidenceDocumentDetails, responseEntity.getBody().getContent().getFirst()); } @Test @@ -176,7 +178,7 @@ public void testRemoveEvidenceDocument() { Pageable.unpaged() ).getBody(); - assertEquals(0, queriedDocuments.getContent().size()); + assertTrue(queriedDocuments.getContent().isEmpty()); } @Test @@ -243,7 +245,7 @@ public void testRemoveEvidenceDocuments_byCaseRef() { Pageable.unpaged() ).getBody(); - assertEquals(0, queriedDocuments.getContent().size()); + assertTrue(queriedDocuments.getContent().isEmpty()); } @Test @@ -278,4 +280,17 @@ public void testRemoveEvidenceDocuments_byCaseRef_transferPending_filtersCorrect assertEquals(1, queriedDocuments.getContent().size()); } + + private static void compareData(EvidenceDocumentDetail retrievedEvidenceDocumentDetails, + BaseEvidenceDocumentDetail baseEvidenceDocumentDetail) { + assertEquals(retrievedEvidenceDocumentDetails.getId(), baseEvidenceDocumentDetail.getId()); + assertEquals(retrievedEvidenceDocumentDetails.getApplicationOrOutcomeId(), baseEvidenceDocumentDetail.getApplicationOrOutcomeId()); + assertEquals(retrievedEvidenceDocumentDetails.getCaseReferenceNumber(), baseEvidenceDocumentDetail.getCaseReferenceNumber()); + assertEquals(retrievedEvidenceDocumentDetails.getDescription(), baseEvidenceDocumentDetail.getDescription()); + assertEquals(retrievedEvidenceDocumentDetails.getDocumentType(), baseEvidenceDocumentDetail.getDocumentType()); + assertEquals(retrievedEvidenceDocumentDetails.getEvidenceDescriptions(), baseEvidenceDocumentDetail.getEvidenceDescriptions()); + assertEquals(retrievedEvidenceDocumentDetails.getFileExtension(), baseEvidenceDocumentDetail.getFileExtension()); + assertEquals(retrievedEvidenceDocumentDetails.getFileName(), baseEvidenceDocumentDetail.getFileName()); + assertEquals(retrievedEvidenceDocumentDetails.getProviderId(), baseEvidenceDocumentDetail.getProviderId()); + } } diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/EvidenceMapper.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/EvidenceMapper.java index a80b253..4c40e7a 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/EvidenceMapper.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/EvidenceMapper.java @@ -6,6 +6,7 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.springframework.data.domain.Page; +import uk.gov.laa.ccms.caab.model.BaseEvidenceDocumentDetail; import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetail; import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetails; @@ -22,6 +23,11 @@ public interface EvidenceMapper { EvidenceDocumentDetails toEvidenceDocumentDetails( final Page evidenceDocuments); + @Mapping(target = "documentType.id", source = "documentType") + @Mapping(target = "documentType.displayValue", source = "documentTypeDisplayValue") + BaseEvidenceDocumentDetail toBaseEvidenceDocumentDetail( + final uk.gov.laa.ccms.caab.api.entity.EvidenceDocument evidenceDocument); + @Mapping(target = "documentType.id", source = "documentType") @Mapping(target = "documentType.displayValue", source = "documentTypeDisplayValue") @Mapping(target = "fileData", source = "fileBytes")