From 4d47e68e95733fa9d4f7597a551e7e29da6edef2 Mon Sep 17 00:00:00 2001 From: Phil Payne Date: Tue, 24 Oct 2023 16:02:42 +0100 Subject: [PATCH 1/5] story(ccls-1797) add application provider details endpoints --- caab-api/open-api-specification.yml | 96 ++++++++++++++++--- .../data/api/AbstractIntegrationTest.java | 2 +- .../ApplicationServiceIntegrationTest.java | 73 ++++++++++++++ .../api/controller/ApplicationController.java | 21 ++++ .../caab/api/mapper/ApplicationMapper.java | 31 ++++++ .../caab/api/service/ApplicationService.java | 34 +++++++ .../controller/ApplicationControllerTest.java | 30 +++++- .../api/mapper/ApplicationMapperTest.java | 94 ++++++++++++++++++ .../api/service/ApplicationServiceTest.java | 70 ++++++++++++++ 9 files changed, 436 insertions(+), 15 deletions(-) diff --git a/caab-api/open-api-specification.yml b/caab-api/open-api-specification.yml index 58ffb3e..bb72e18 100644 --- a/caab-api/open-api-specification.yml +++ b/caab-api/open-api-specification.yml @@ -127,6 +127,71 @@ paths: description: 'Not found' '500': description: 'Internal server error' + /applications/{id}/provider-details: + get: + tags: + - applications + summary: 'get an applications provider details' + operationId: 'getApplicationProviderDetails' + parameters: + - name: 'id' + in: 'path' + required: true + schema: + type: 'integer' + format: 'int64' + example: '1234567890' + responses: + '200': + description: 'Successful operation' + content: + application/json: + schema: + $ref: "#/components/schemas/applicationProviderDetails" + '400': + description: 'Bad request' + '401': + description: 'Unauthorized' + '404': + description: 'Not found' + '500': + description: 'Internal server error' + patch: + tags: + - applications + summary: 'patch an applications provider details' + operationId: 'patchApplicationProviderDetails' + requestBody: + description: patch an application's application type + content: + application/json: + schema: + $ref: '#/components/schemas/applicationProviderDetails' + parameters: + - name: 'id' + in: 'path' + required: true + schema: + type: 'integer' + format: 'int64' + example: '1234567890' + - name: 'Caab-user-Login-Id' + in: header + required: true + schema: + type: 'string' + example: 'MARILYN@DESORANDCO.CO.UK' + responses: + '200': + description: 'Successful operation' + '400': + description: 'Bad request' + '401': + description: 'Unauthorized' + '404': + description: 'Not found' + '500': + description: 'Internal server error' components: schemas: intDisplayValue: @@ -682,7 +747,7 @@ components: registration_ref: type: 'string' recovery_of_award_time_related: - type: 'string' + type: 'boolean' address_line_1: type: 'string' address_line_2: @@ -847,22 +912,12 @@ components: user_defined_ind: type: 'boolean' applicationDetail: + allOf: + - $ref: "#/components/schemas/applicationProviderDetails" type: 'object' properties: case_reference_number: type: 'string' - provider_case_reference: - type: 'string' - provider: - $ref: "#/components/schemas/intDisplayValue" - office: - $ref: "#/components/schemas/intDisplayValue" - supervisor: - $ref: "#/components/schemas/stringDisplayValue" - fee_earner: - $ref: "#/components/schemas/stringDisplayValue" - provider_contact: - $ref: "#/components/schemas/stringDisplayValue" category_of_law: $ref: "#/components/schemas/stringDisplayValue" relation_to_linked_case: @@ -957,6 +1012,21 @@ components: - provider - category_of_law - client + applicationProviderDetails: + type: 'object' + properties: + provider: + $ref: "#/components/schemas/intDisplayValue" + office: + $ref: "#/components/schemas/intDisplayValue" + fee_earner: + $ref: "#/components/schemas/stringDisplayValue" + supervisor: + $ref: "#/components/schemas/stringDisplayValue" + provider_contact: + $ref: "#/components/schemas/stringDisplayValue" + provider_case_reference: + type: 'string' auditDetail: type: 'object' properties: diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java index bfb9138..5457fe8 100644 --- a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java @@ -15,7 +15,7 @@ public class AbstractIntegrationTest { public static OracleContainer oracleDB; static { - oracleDB = new OracleContainer("gvenzl/oracle-xe:21-slim"); + oracleDB = new OracleContainer("gvenzl/oracle-xe:21-slim-faststart"); oracleDB.start(); } diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java index bc01665..4ecd112 100644 --- a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java @@ -16,6 +16,8 @@ import java.util.Date; import java.util.TimeZone; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; @@ -28,6 +30,7 @@ import uk.gov.laa.ccms.caab.api.service.ApplicationService; import uk.gov.laa.ccms.caab.model.Address; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import uk.gov.laa.ccms.caab.model.Client; import uk.gov.laa.ccms.caab.model.CostLimit; @@ -332,6 +335,76 @@ public void testPatchApplicationType() { assertEquals(amendedApplicationTypeDisplay, result.getApplicationTypeDisplayValue()); } + @ParameterizedTest + @CsvSource({ + "24, NewProviderCaseRef1, New Provider Display1, 12345, 67890, FeeEarnerId1, SupervisorId1, ProviderContactId1, TestUser", + "21, NewProviderCaseRef2, New Provider Display2, 54321, 98760, FeeEarnerId2, SupervisorId2, ProviderContactId2, AnotherUser", + "41, NewProviderCaseRef3, New Provider Display3, 13579, 24680, FeeEarnerId3, SupervisorId3, ProviderContactId3, ThirdUser" + }) + @Sql(scripts = "/sql/application_insert.sql") + public void testPatchProviderDetails( + Long applicationId, + String newProviderCaseReference, + String newProviderDisplayValue, + Integer newProviderId, + Integer newOfficeId, + String newFeeEarnerId, + String newSupervisorId, + String newProviderContactId, + String caabUserLoginId) { + + // Create an ApplicationProviderDetails instance with the provided values + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + IntDisplayValue provider = new IntDisplayValue().id(newProviderId).displayValue(newProviderDisplayValue); + IntDisplayValue office = new IntDisplayValue().id(newOfficeId); + StringDisplayValue feeEarner = new StringDisplayValue().id(newFeeEarnerId); + StringDisplayValue supervisor = new StringDisplayValue().id(newSupervisorId); + StringDisplayValue providerContact = new StringDisplayValue().id(newProviderContactId); + + providerDetails.setProvider(provider); + providerDetails.setProviderCaseReference(newProviderCaseReference); + providerDetails.setOffice(office); + providerDetails.setFeeEarner(feeEarner); + providerDetails.setSupervisor(supervisor); + providerDetails.setProviderContact(providerContact); + + // Call the patchProviderDetails method + applicationService.patchProviderDetails(applicationId, caabUserLoginId, providerDetails); + + // Fetch the application from the database after the update + Application updatedApplication = applicationRepository.findById(applicationId).orElse(null); + + // Assert that the updated application has the expected provider details + assertNotNull(updatedApplication); + assertEquals(newProviderCaseReference, updatedApplication.getProviderCaseReference()); + assertEquals(newProviderDisplayValue, updatedApplication.getProviderDisplayValue()); + + // Assert for other provider details + assertEquals(provider.getId().toString(), updatedApplication.getProviderId()); + assertEquals(office.getId().toString(), updatedApplication.getOfficeId().toString()); + assertEquals(feeEarner.getId(), updatedApplication.getFeeEarner()); + assertEquals(supervisor.getId(), updatedApplication.getSupervisor()); + assertEquals(providerContact.getId(), updatedApplication.getProviderContact()); + } + + @Test + @Sql(scripts = "/sql/application_insert.sql") + public void testPatchProviderDetails_ApplicationNotFound() { + Long nonExistentApplicationId = 999L; + + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + + // Use assertThrows to check if the method throws the expected exception + CaabApiException exception = assertThrows(CaabApiException.class, () -> { + applicationService.patchProviderDetails(nonExistentApplicationId, "TestUser", providerDetails); + }); + + assertEquals( + String.format("Application with id %s not found", nonExistentApplicationId), + exception.getMessage()); + assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus()); + } + private ApplicationDetail buildRequiredApplicationDetail() { ApplicationDetail application = new ApplicationDetail(); diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java index fdb2576..ddfc4db 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java @@ -11,6 +11,7 @@ import uk.gov.laa.ccms.caab.api.ApplicationsApi; import uk.gov.laa.ccms.caab.api.service.ApplicationService; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; /** @@ -52,6 +53,15 @@ public ResponseEntity getApplication( return new ResponseEntity<>(application, HttpStatus.OK); } + @Override + public ResponseEntity getApplicationProviderDetails(Long id) { + + ApplicationProviderDetails applicationProviderDetails = + applicationService.getApplicationProviderDetails(id); + + return new ResponseEntity<>(applicationProviderDetails, HttpStatus.OK); + } + @Override public ResponseEntity getApplicationType( final Long id) { @@ -61,6 +71,17 @@ public ResponseEntity getApplicationType( return new ResponseEntity<>(applicationType, HttpStatus.OK); } + @Override + public ResponseEntity patchApplicationProviderDetails( + Long id, + String caabUserLoginId, + ApplicationProviderDetails applicationProviderDetails) { + + applicationService.patchProviderDetails(id, caabUserLoginId, applicationProviderDetails); + + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + @Override public ResponseEntity patchApplicationType( final Long id, diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java index 89e7dee..507f7ea 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java @@ -12,6 +12,7 @@ import uk.gov.laa.ccms.caab.api.entity.PriorAuthority; import uk.gov.laa.ccms.caab.api.entity.Proceeding; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import uk.gov.laa.ccms.caab.model.AuditDetail; @@ -73,6 +74,24 @@ void addApplicationType(@MappingTarget Application application, ApplicationType applicationType, String caabUserLoginId); + @Mapping(target = "id", ignore = true) + @Mapping(target = "providerId", source = "providerDetails.provider.id") + @Mapping(target = "providerDisplayValue", source = "providerDetails.provider.displayValue") + @Mapping(target = "officeId", source = "providerDetails.office.id") + @Mapping(target = "officeDisplayValue", source = "providerDetails.office.displayValue") + @Mapping(target = "supervisor", source = "providerDetails.supervisor.id") + @Mapping(target = "supervisorDisplayValue", source = "providerDetails.supervisor.displayValue") + @Mapping(target = "feeEarner", source = "providerDetails.feeEarner.id") + @Mapping(target = "feeEarnerDisplayValue", source = "providerDetails.feeEarner.displayValue") + @Mapping(target = "providerContact", source = "providerDetails.providerContact.id") + @Mapping(target = "providerContactDisplayValue", + source = "providerDetails.providerContact.displayValue") + @Mapping(target = "auditTrail.modifiedBy", + source = "caabUserLoginId") + void addProviderDetails(@MappingTarget Application application, + ApplicationProviderDetails providerDetails, + String caabUserLoginId); + @Mapping(target = "id", source = "applicationType") @Mapping(target = "displayValue", source = "applicationTypeDisplayValue") @Mapping(target = "devolvedPowers.used", source = "devolvedPowersUsed") @@ -82,6 +101,18 @@ void addApplicationType(@MappingTarget Application application, source = "devolvedPowersContractFlag") ApplicationType toApplicationType(Application application); + @Mapping(target = "provider.id", source = "providerId") + @Mapping(target = "provider.displayValue", source = "providerDisplayValue") + @Mapping(target = "office.id", source = "officeId") + @Mapping(target = "office.displayValue", source = "officeDisplayValue") + @Mapping(target = "supervisor.id", source = "supervisor") + @Mapping(target = "supervisor.displayValue", source = "supervisorDisplayValue") + @Mapping(target = "feeEarner.id", source = "feeEarner") + @Mapping(target = "feeEarner.displayValue", source = "feeEarnerDisplayValue") + @Mapping(target = "providerContact.id", source = "providerContact") + @Mapping(target = "providerContact.displayValue", source = "providerContactDisplayValue") + ApplicationProviderDetails toProviderDetails(Application application); + @Mapping(target = "id", ignore = true) @Mapping(target = "auditTrail", ignore = true) @Mapping(target = "postCode", source = "postcode") diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java index b3a9d97..a9ae01a 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java @@ -13,6 +13,7 @@ import uk.gov.laa.ccms.caab.api.mapper.ApplicationMapper; import uk.gov.laa.ccms.caab.api.repository.ApplicationRepository; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; /** @@ -92,6 +93,19 @@ public ApplicationDetail getApplication(final Long id) { String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); } + /** + * Gets an applications provider details. + * + * @param id the TDS id for the application. + * @return the applications provider details. + */ + public ApplicationProviderDetails getApplicationProviderDetails(final Long id) { + return applicationRepository.findById(id) + .map(applicationMapper::toProviderDetails) + .orElseThrow(() -> new CaabApiException( + String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); + } + /** * Gets an applications application type. * @@ -106,6 +120,26 @@ public ApplicationType getApplicationType(final Long id) { String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); } + /** + * Patch an application with new provider details. + * + * @param id the TDS id for the application. + * @param caabUserLoginId the CAAB user login ID responsible for the application creation. + * @param providerDetails the new application provider details to update the application with + */ + public void patchProviderDetails( + final Long id, + final String caabUserLoginId, + final ApplicationProviderDetails providerDetails) { + + Application application = applicationRepository.findById(id) + .orElseThrow(() -> new CaabApiException( + String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); + + applicationMapper.addProviderDetails(application, providerDetails, caabUserLoginId); + applicationRepository.save(application); + } + /** * Patch an application with new application type. * diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java index e8d3423..c1d6a96 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java @@ -24,6 +24,7 @@ import uk.gov.laa.ccms.caab.api.controller.ApplicationController; import uk.gov.laa.ccms.caab.api.service.ApplicationService; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import uk.gov.laa.ccms.caab.model.Client; import uk.gov.laa.ccms.caab.model.IntDisplayValue; @@ -118,7 +119,34 @@ public void patchApplicationType() throws Exception { .content(objectMapper.writeValueAsString(applicationType))) .andExpect(status().isNoContent()); - // Verify that the service method was called with the correct arguments verify(applicationService).patchApplicationType(id, caabUserLoginId, applicationType); } + + @Test + public void getApplicationProviderDetails() throws Exception { + Long id = 123L; + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + + when(applicationService.getApplicationProviderDetails(id)).thenReturn(providerDetails); + + this.mockMvc.perform(get("/applications/{id}/provider-details", id)) + .andExpect(status().isOk()); + } + + @Test + public void patchApplicationProviderDetails() throws Exception { + Long id = 123L; + String caabUserLoginId = "test"; + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + + doNothing().when(applicationService).patchProviderDetails(id, caabUserLoginId, providerDetails); + + this.mockMvc.perform(patch("/applications/{id}/provider-details", id) + .header("Caab-user-Login-Id", caabUserLoginId) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(providerDetails))) + .andExpect(status().isNoContent()); + + verify(applicationService).patchProviderDetails(id, caabUserLoginId, providerDetails); + } } \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java index 492c159..3bcd979 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java @@ -19,6 +19,7 @@ import uk.gov.laa.ccms.caab.api.entity.PriorAuthority; import uk.gov.laa.ccms.caab.api.entity.Proceeding; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import uk.gov.laa.ccms.caab.model.AuditDetail; import uk.gov.laa.ccms.caab.model.Client; @@ -536,5 +537,98 @@ private Application getApplicationWithPriorAuthorities() { return application; } + @Test + public void testToApplicationType() { + Application application = new Application(); + application.setApplicationType("AppType123"); + application.setApplicationTypeDisplayValue("Application Type Display"); + + application.setDevolvedPowersUsed(true); + application.setDateDevolvedPowersUsed(new Date()); + application.setDevolvedPowersContractFlag("ContractFlag123"); + + ApplicationType result = mapper.toApplicationType(application); + + assertNotNull(result); + assertEquals("AppType123", result.getId()); + assertEquals("Application Type Display", result.getDisplayValue()); + + assertNotNull(result.getDevolvedPowers()); + assertEquals(true, result.getDevolvedPowers().getUsed()); + assertNotNull(result.getDevolvedPowers().getDateUsed()); + assertEquals("ContractFlag123", result.getDevolvedPowers().getContractFlag()); + + } + + @Test + public void testAddProviderDetailsWithNullDetails() { + Application application = new Application(); + ApplicationProviderDetails providerDetails = null; + String caabUserLoginId = "user123"; + + mapper.addProviderDetails(application, providerDetails, caabUserLoginId); + + assertNull(application.getProviderId()); + assertNull(application.getProviderDisplayValue()); + assertNull(application.getOfficeId()); + assertNull(application.getOfficeDisplayValue()); + assertNull(application.getSupervisor()); + assertNull(application.getSupervisorDisplayValue()); + assertNull(application.getFeeEarner()); + assertNull(application.getFeeEarnerDisplayValue()); + assertNull(application.getProviderContact()); + assertNull(application.getProviderContactDisplayValue()); + assertEquals("user123", application.getAuditTrail().getModifiedBy()); + } + @Test + public void testAddProviderDetails() { + Application application = new Application(); + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + providerDetails.setProvider(new IntDisplayValue().id(123).displayValue("Provider Display")); + providerDetails.setOffice(new IntDisplayValue().id(1).displayValue("Office 1")); + providerDetails.setSupervisor(new StringDisplayValue().id("Supervisor").displayValue("Supervisor Display Value")); + providerDetails.setFeeEarner(new StringDisplayValue().id("FeeEarner").displayValue("Fee Earner Display Value")); + providerDetails.setProviderContact(new StringDisplayValue().id("ProviderContact").displayValue("Provider Contact Display Value")); + String caabUserLoginId = "user123"; + + mapper.addProviderDetails(application, providerDetails, caabUserLoginId); + + assertEquals("123", application.getProviderId()); + assertEquals("Provider Display", application.getProviderDisplayValue()); + assertEquals(1, application.getOfficeId().intValue()); + assertEquals("Office 1", application.getOfficeDisplayValue()); + assertEquals("Supervisor", application.getSupervisor()); + assertEquals("Supervisor Display Value", application.getSupervisorDisplayValue()); + assertEquals("FeeEarner", application.getFeeEarner()); + assertEquals("Fee Earner Display Value", application.getFeeEarnerDisplayValue()); + assertEquals("ProviderContact", application.getProviderContact()); + assertEquals("Provider Contact Display Value", application.getProviderContactDisplayValue()); + assertEquals("user123", application.getAuditTrail().getModifiedBy()); + } + + @Test + public void testToProviderDetails() { + Application application = new Application(); + application.setProviderId("123"); + application.setProviderDisplayValue("Provider Display Value"); + application.setOfficeId(1L); + application.setOfficeDisplayValue("Office 1"); + application.setSupervisorDisplayValue("Supervisor Display Value"); + application.setFeeEarnerDisplayValue("Fee Earner Display Value"); + application.setProviderContactDisplayValue("Provider Contact Display Value"); + application.setProviderCaseReference("ProviderCase123"); + + ApplicationProviderDetails result = mapper.toProviderDetails(application); + + assertNotNull(result); + assertEquals(123, result.getProvider().getId()); + assertEquals("Provider Display Value", result.getProvider().getDisplayValue()); + assertEquals(1, result.getOffice().getId()); + assertEquals("Office 1", result.getOffice().getDisplayValue()); + assertEquals("Supervisor Display Value", result.getSupervisor().getDisplayValue()); + assertEquals("Fee Earner Display Value", result.getFeeEarner().getDisplayValue()); + assertEquals("Provider Contact Display Value", result.getProviderContact().getDisplayValue()); + assertEquals("ProviderCase123", result.getProviderCaseReference()); + } } diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java index 9c8cd74..8d37e4f 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java @@ -16,6 +16,7 @@ import uk.gov.laa.ccms.caab.api.service.ApplicationService; import uk.gov.laa.ccms.caab.model.ApplicationDetail; import uk.gov.laa.ccms.caab.api.repository.ApplicationRepository; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -185,6 +186,75 @@ void patchApplicationType_whenNotExists_throwsException() { assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus()); } + @Test + void getApplicationProviderDetails_whenExists_returnsProviderDetails() { + Long id = 1L; + ApplicationProviderDetails expectedProviderDetails = new ApplicationProviderDetails(); + Application application = new Application(); + + when(applicationRepository.findById(id)).thenReturn(Optional.of(application)); // Assuming Application exists + when(applicationMapper.toProviderDetails(application)).thenReturn(expectedProviderDetails); + + ApplicationProviderDetails result = applicationService.getApplicationProviderDetails(id); + + verify(applicationRepository).findById(id); + verify(applicationMapper).toProviderDetails(application); + + assertEquals(expectedProviderDetails, result); + } + + @Test + void getApplicationProviderDetails_whenNotExists_throwsException() { + Long id = 1L; + + when(applicationRepository.findById(id)).thenReturn(Optional.empty()); + + // Use assertThrows to check if the method throws the expected exception + CaabApiException exception = assertThrows(CaabApiException.class, () -> { + applicationService.getApplicationProviderDetails(id); + }); + + verify(applicationRepository).findById(id); + + // Optionally, you can check the exception message and HTTP status code + assertEquals("Application with id 1 not found", exception.getMessage()); + assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus()); + } + + @Test + void patchProviderDetails_whenExists_updatesProviderDetails() { + Long id = 1L; + String caabUserLoginId = "testUser"; + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + Application application = new Application(); + + when(applicationRepository.findById(id)).thenReturn(Optional.of(application)); // Assuming Application exists + + applicationService.patchProviderDetails(id, caabUserLoginId, providerDetails); + + verify(applicationRepository).findById(id); + verify(applicationMapper).addProviderDetails(application, providerDetails, caabUserLoginId); + verify(applicationRepository).save(application); + } + + @Test + void patchProviderDetails_whenNotExists_throwsException() { + Long id = 1L; + String caabUserLoginId = "testUser"; + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + + when(applicationRepository.findById(id)).thenReturn(Optional.empty()); + + CaabApiException exception = assertThrows(CaabApiException.class, () -> { + applicationService.patchProviderDetails(id, caabUserLoginId, providerDetails); + }); + + verify(applicationRepository).findById(id); + + assertEquals("Application with id 1 not found", exception.getMessage()); + assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus()); + } + /** * Helper method to setup the mocking behaviour of applicationMapper and applicationRepository. */ From ddceb03eb1a82b55b04512a3b0d1049a78b3ecee Mon Sep 17 00:00:00 2001 From: Andrew Porritt <109674546+porritta@users.noreply.github.com> Date: Tue, 24 Oct 2023 16:36:25 +0100 Subject: [PATCH 2/5] story(ccls-1913): add missing award attributes with inheritance (#15) * story(ccls-1913): add missing award attributes with inheritance * story(ccls-1913): corrected leave of court type --- caab-api/open-api-specification.yml | 65 ++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/caab-api/open-api-specification.yml b/caab-api/open-api-specification.yml index 58ffb3e..3c9952b 100644 --- a/caab-api/open-api-specification.yml +++ b/caab-api/open-api-specification.yml @@ -551,7 +551,7 @@ components: type: 'number' default: 0.00 leave_of_court_required_ind: - type: 'string' + type: 'boolean' offered_amount: type: 'number' default: 0.00 @@ -580,7 +580,64 @@ components: format: 'date' time_related_recovery_details: type: 'string' + liableParty: + type: 'object' + properties: + award_type: + type: 'string' + opponent_id: + type: 'string' + auditTrail: + $ref: "#/components/schemas/auditDetail" + baseAward: + type: 'object' + discriminator: + propertyName: 'discriminator' + properties: + award_type: + type: 'string' + date_of_order: + type: 'string' + format: 'date' + awarded_by: + type: 'string' + description: + type: 'string' + award_amount: + type: 'number' + update_allowed: + type: 'boolean' + delete_allowed: + type: 'boolean' + default: true + ebs_id: + type: 'string' + award_code: + type: 'string' + triggering_event: + type: 'string' + effective_date: + type: 'string' + format: 'date' + time_related_recovery_details: + type: 'string' + cost_or_financial: + type: 'boolean' + default: false + opponents_to_select: + type: 'boolean' + default: false + opponent_id: + type: 'string' + liable_parties: + type: 'array' + items: + $ref: '#/components/schemas/liableParty' + auditTrail: + $ref: "#/components/schemas/auditDetail" costAward: + allOf: + - $ref: '#/components/schemas/baseAward' type: 'object' properties: court_assessment_status: @@ -620,6 +677,8 @@ components: recovery: $ref: "#/components/schemas/recovery" financialAward: + allOf: + - $ref: '#/components/schemas/baseAward' type: 'object' properties: interim_award: @@ -645,6 +704,8 @@ components: recovery: $ref: "#/components/schemas/recovery" landAward: + allOf: + - $ref: '#/components/schemas/baseAward' type: 'object' properties: description: @@ -692,6 +753,8 @@ components: time_recovery: $ref: "#/components/schemas/timeRecovery" otherAssetAward: + allOf: + - $ref: '#/components/schemas/baseAward' type: 'object' properties: description: From 131f5ac5e41eda640e302332c97d1a9ac4aed358 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Tue, 24 Oct 2023 15:38:42 +0000 Subject: [PATCH 3/5] [Gradle Release Plugin] - pre tag commit: 'laa-ccms-caab-api-0.0.4'. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d1627a1..9186103 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=0.0.4-SNAPSHOT +version=0.0.4 group='uk.gov.laa.ccms' \ No newline at end of file From 1b69218f612863e7a972a45dfbbd3e13e18c6db8 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Tue, 24 Oct 2023 15:38:44 +0000 Subject: [PATCH 4/5] [Gradle Release Plugin] - new version commit: 'laa-ccms-caab-api-0.0.5-SNAPSHOT'. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9186103..664d7d3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=0.0.4 +version=0.0.5-SNAPSHOT group='uk.gov.laa.ccms' \ No newline at end of file From 260916caf8b57eb64c0f1fe8cf4f23e992c71709 Mon Sep 17 00:00:00 2001 From: Phil Payne Date: Tue, 24 Oct 2023 16:02:42 +0100 Subject: [PATCH 5/5] story(ccls-1797) add application provider details endpoints --- caab-api/open-api-specification.yml | 96 ++++++++++++++++--- .../data/api/AbstractIntegrationTest.java | 2 +- .../ApplicationServiceIntegrationTest.java | 73 ++++++++++++++ .../api/controller/ApplicationController.java | 21 ++++ .../caab/api/mapper/ApplicationMapper.java | 31 ++++++ .../caab/api/service/ApplicationService.java | 34 +++++++ .../controller/ApplicationControllerTest.java | 30 +++++- .../api/mapper/ApplicationMapperTest.java | 94 ++++++++++++++++++ .../api/service/ApplicationServiceTest.java | 70 ++++++++++++++ 9 files changed, 436 insertions(+), 15 deletions(-) diff --git a/caab-api/open-api-specification.yml b/caab-api/open-api-specification.yml index 3c9952b..8130643 100644 --- a/caab-api/open-api-specification.yml +++ b/caab-api/open-api-specification.yml @@ -127,6 +127,71 @@ paths: description: 'Not found' '500': description: 'Internal server error' + /applications/{id}/provider-details: + get: + tags: + - applications + summary: 'get an applications provider details' + operationId: 'getApplicationProviderDetails' + parameters: + - name: 'id' + in: 'path' + required: true + schema: + type: 'integer' + format: 'int64' + example: '1234567890' + responses: + '200': + description: 'Successful operation' + content: + application/json: + schema: + $ref: "#/components/schemas/applicationProviderDetails" + '400': + description: 'Bad request' + '401': + description: 'Unauthorized' + '404': + description: 'Not found' + '500': + description: 'Internal server error' + patch: + tags: + - applications + summary: 'patch an applications provider details' + operationId: 'patchApplicationProviderDetails' + requestBody: + description: patch an application's application type + content: + application/json: + schema: + $ref: '#/components/schemas/applicationProviderDetails' + parameters: + - name: 'id' + in: 'path' + required: true + schema: + type: 'integer' + format: 'int64' + example: '1234567890' + - name: 'Caab-user-Login-Id' + in: header + required: true + schema: + type: 'string' + example: 'MARILYN@DESORANDCO.CO.UK' + responses: + '200': + description: 'Successful operation' + '400': + description: 'Bad request' + '401': + description: 'Unauthorized' + '404': + description: 'Not found' + '500': + description: 'Internal server error' components: schemas: intDisplayValue: @@ -743,7 +808,7 @@ components: registration_ref: type: 'string' recovery_of_award_time_related: - type: 'string' + type: 'boolean' address_line_1: type: 'string' address_line_2: @@ -910,22 +975,12 @@ components: user_defined_ind: type: 'boolean' applicationDetail: + allOf: + - $ref: "#/components/schemas/applicationProviderDetails" type: 'object' properties: case_reference_number: type: 'string' - provider_case_reference: - type: 'string' - provider: - $ref: "#/components/schemas/intDisplayValue" - office: - $ref: "#/components/schemas/intDisplayValue" - supervisor: - $ref: "#/components/schemas/stringDisplayValue" - fee_earner: - $ref: "#/components/schemas/stringDisplayValue" - provider_contact: - $ref: "#/components/schemas/stringDisplayValue" category_of_law: $ref: "#/components/schemas/stringDisplayValue" relation_to_linked_case: @@ -1020,6 +1075,21 @@ components: - provider - category_of_law - client + applicationProviderDetails: + type: 'object' + properties: + provider: + $ref: "#/components/schemas/intDisplayValue" + office: + $ref: "#/components/schemas/intDisplayValue" + fee_earner: + $ref: "#/components/schemas/stringDisplayValue" + supervisor: + $ref: "#/components/schemas/stringDisplayValue" + provider_contact: + $ref: "#/components/schemas/stringDisplayValue" + provider_case_reference: + type: 'string' auditDetail: type: 'object' properties: diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java index bfb9138..5457fe8 100644 --- a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/AbstractIntegrationTest.java @@ -15,7 +15,7 @@ public class AbstractIntegrationTest { public static OracleContainer oracleDB; static { - oracleDB = new OracleContainer("gvenzl/oracle-xe:21-slim"); + oracleDB = new OracleContainer("gvenzl/oracle-xe:21-slim-faststart"); oracleDB.start(); } diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java index bc01665..4ecd112 100644 --- a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/service/ApplicationServiceIntegrationTest.java @@ -16,6 +16,8 @@ import java.util.Date; import java.util.TimeZone; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; @@ -28,6 +30,7 @@ import uk.gov.laa.ccms.caab.api.service.ApplicationService; import uk.gov.laa.ccms.caab.model.Address; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import uk.gov.laa.ccms.caab.model.Client; import uk.gov.laa.ccms.caab.model.CostLimit; @@ -332,6 +335,76 @@ public void testPatchApplicationType() { assertEquals(amendedApplicationTypeDisplay, result.getApplicationTypeDisplayValue()); } + @ParameterizedTest + @CsvSource({ + "24, NewProviderCaseRef1, New Provider Display1, 12345, 67890, FeeEarnerId1, SupervisorId1, ProviderContactId1, TestUser", + "21, NewProviderCaseRef2, New Provider Display2, 54321, 98760, FeeEarnerId2, SupervisorId2, ProviderContactId2, AnotherUser", + "41, NewProviderCaseRef3, New Provider Display3, 13579, 24680, FeeEarnerId3, SupervisorId3, ProviderContactId3, ThirdUser" + }) + @Sql(scripts = "/sql/application_insert.sql") + public void testPatchProviderDetails( + Long applicationId, + String newProviderCaseReference, + String newProviderDisplayValue, + Integer newProviderId, + Integer newOfficeId, + String newFeeEarnerId, + String newSupervisorId, + String newProviderContactId, + String caabUserLoginId) { + + // Create an ApplicationProviderDetails instance with the provided values + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + IntDisplayValue provider = new IntDisplayValue().id(newProviderId).displayValue(newProviderDisplayValue); + IntDisplayValue office = new IntDisplayValue().id(newOfficeId); + StringDisplayValue feeEarner = new StringDisplayValue().id(newFeeEarnerId); + StringDisplayValue supervisor = new StringDisplayValue().id(newSupervisorId); + StringDisplayValue providerContact = new StringDisplayValue().id(newProviderContactId); + + providerDetails.setProvider(provider); + providerDetails.setProviderCaseReference(newProviderCaseReference); + providerDetails.setOffice(office); + providerDetails.setFeeEarner(feeEarner); + providerDetails.setSupervisor(supervisor); + providerDetails.setProviderContact(providerContact); + + // Call the patchProviderDetails method + applicationService.patchProviderDetails(applicationId, caabUserLoginId, providerDetails); + + // Fetch the application from the database after the update + Application updatedApplication = applicationRepository.findById(applicationId).orElse(null); + + // Assert that the updated application has the expected provider details + assertNotNull(updatedApplication); + assertEquals(newProviderCaseReference, updatedApplication.getProviderCaseReference()); + assertEquals(newProviderDisplayValue, updatedApplication.getProviderDisplayValue()); + + // Assert for other provider details + assertEquals(provider.getId().toString(), updatedApplication.getProviderId()); + assertEquals(office.getId().toString(), updatedApplication.getOfficeId().toString()); + assertEquals(feeEarner.getId(), updatedApplication.getFeeEarner()); + assertEquals(supervisor.getId(), updatedApplication.getSupervisor()); + assertEquals(providerContact.getId(), updatedApplication.getProviderContact()); + } + + @Test + @Sql(scripts = "/sql/application_insert.sql") + public void testPatchProviderDetails_ApplicationNotFound() { + Long nonExistentApplicationId = 999L; + + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + + // Use assertThrows to check if the method throws the expected exception + CaabApiException exception = assertThrows(CaabApiException.class, () -> { + applicationService.patchProviderDetails(nonExistentApplicationId, "TestUser", providerDetails); + }); + + assertEquals( + String.format("Application with id %s not found", nonExistentApplicationId), + exception.getMessage()); + assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus()); + } + private ApplicationDetail buildRequiredApplicationDetail() { ApplicationDetail application = new ApplicationDetail(); diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java index fdb2576..ddfc4db 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ApplicationController.java @@ -11,6 +11,7 @@ import uk.gov.laa.ccms.caab.api.ApplicationsApi; import uk.gov.laa.ccms.caab.api.service.ApplicationService; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; /** @@ -52,6 +53,15 @@ public ResponseEntity getApplication( return new ResponseEntity<>(application, HttpStatus.OK); } + @Override + public ResponseEntity getApplicationProviderDetails(Long id) { + + ApplicationProviderDetails applicationProviderDetails = + applicationService.getApplicationProviderDetails(id); + + return new ResponseEntity<>(applicationProviderDetails, HttpStatus.OK); + } + @Override public ResponseEntity getApplicationType( final Long id) { @@ -61,6 +71,17 @@ public ResponseEntity getApplicationType( return new ResponseEntity<>(applicationType, HttpStatus.OK); } + @Override + public ResponseEntity patchApplicationProviderDetails( + Long id, + String caabUserLoginId, + ApplicationProviderDetails applicationProviderDetails) { + + applicationService.patchProviderDetails(id, caabUserLoginId, applicationProviderDetails); + + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + @Override public ResponseEntity patchApplicationType( final Long id, diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java index 89e7dee..507f7ea 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapper.java @@ -12,6 +12,7 @@ import uk.gov.laa.ccms.caab.api.entity.PriorAuthority; import uk.gov.laa.ccms.caab.api.entity.Proceeding; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import uk.gov.laa.ccms.caab.model.AuditDetail; @@ -73,6 +74,24 @@ void addApplicationType(@MappingTarget Application application, ApplicationType applicationType, String caabUserLoginId); + @Mapping(target = "id", ignore = true) + @Mapping(target = "providerId", source = "providerDetails.provider.id") + @Mapping(target = "providerDisplayValue", source = "providerDetails.provider.displayValue") + @Mapping(target = "officeId", source = "providerDetails.office.id") + @Mapping(target = "officeDisplayValue", source = "providerDetails.office.displayValue") + @Mapping(target = "supervisor", source = "providerDetails.supervisor.id") + @Mapping(target = "supervisorDisplayValue", source = "providerDetails.supervisor.displayValue") + @Mapping(target = "feeEarner", source = "providerDetails.feeEarner.id") + @Mapping(target = "feeEarnerDisplayValue", source = "providerDetails.feeEarner.displayValue") + @Mapping(target = "providerContact", source = "providerDetails.providerContact.id") + @Mapping(target = "providerContactDisplayValue", + source = "providerDetails.providerContact.displayValue") + @Mapping(target = "auditTrail.modifiedBy", + source = "caabUserLoginId") + void addProviderDetails(@MappingTarget Application application, + ApplicationProviderDetails providerDetails, + String caabUserLoginId); + @Mapping(target = "id", source = "applicationType") @Mapping(target = "displayValue", source = "applicationTypeDisplayValue") @Mapping(target = "devolvedPowers.used", source = "devolvedPowersUsed") @@ -82,6 +101,18 @@ void addApplicationType(@MappingTarget Application application, source = "devolvedPowersContractFlag") ApplicationType toApplicationType(Application application); + @Mapping(target = "provider.id", source = "providerId") + @Mapping(target = "provider.displayValue", source = "providerDisplayValue") + @Mapping(target = "office.id", source = "officeId") + @Mapping(target = "office.displayValue", source = "officeDisplayValue") + @Mapping(target = "supervisor.id", source = "supervisor") + @Mapping(target = "supervisor.displayValue", source = "supervisorDisplayValue") + @Mapping(target = "feeEarner.id", source = "feeEarner") + @Mapping(target = "feeEarner.displayValue", source = "feeEarnerDisplayValue") + @Mapping(target = "providerContact.id", source = "providerContact") + @Mapping(target = "providerContact.displayValue", source = "providerContactDisplayValue") + ApplicationProviderDetails toProviderDetails(Application application); + @Mapping(target = "id", ignore = true) @Mapping(target = "auditTrail", ignore = true) @Mapping(target = "postCode", source = "postcode") diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java index b3a9d97..a9ae01a 100644 --- a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/ApplicationService.java @@ -13,6 +13,7 @@ import uk.gov.laa.ccms.caab.api.mapper.ApplicationMapper; import uk.gov.laa.ccms.caab.api.repository.ApplicationRepository; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; /** @@ -92,6 +93,19 @@ public ApplicationDetail getApplication(final Long id) { String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); } + /** + * Gets an applications provider details. + * + * @param id the TDS id for the application. + * @return the applications provider details. + */ + public ApplicationProviderDetails getApplicationProviderDetails(final Long id) { + return applicationRepository.findById(id) + .map(applicationMapper::toProviderDetails) + .orElseThrow(() -> new CaabApiException( + String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); + } + /** * Gets an applications application type. * @@ -106,6 +120,26 @@ public ApplicationType getApplicationType(final Long id) { String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); } + /** + * Patch an application with new provider details. + * + * @param id the TDS id for the application. + * @param caabUserLoginId the CAAB user login ID responsible for the application creation. + * @param providerDetails the new application provider details to update the application with + */ + public void patchProviderDetails( + final Long id, + final String caabUserLoginId, + final ApplicationProviderDetails providerDetails) { + + Application application = applicationRepository.findById(id) + .orElseThrow(() -> new CaabApiException( + String.format("Application with id %s not found", id), HttpStatus.NOT_FOUND)); + + applicationMapper.addProviderDetails(application, providerDetails, caabUserLoginId); + applicationRepository.save(application); + } + /** * Patch an application with new application type. * diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java index e8d3423..c1d6a96 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ApplicationControllerTest.java @@ -24,6 +24,7 @@ import uk.gov.laa.ccms.caab.api.controller.ApplicationController; import uk.gov.laa.ccms.caab.api.service.ApplicationService; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import uk.gov.laa.ccms.caab.model.Client; import uk.gov.laa.ccms.caab.model.IntDisplayValue; @@ -118,7 +119,34 @@ public void patchApplicationType() throws Exception { .content(objectMapper.writeValueAsString(applicationType))) .andExpect(status().isNoContent()); - // Verify that the service method was called with the correct arguments verify(applicationService).patchApplicationType(id, caabUserLoginId, applicationType); } + + @Test + public void getApplicationProviderDetails() throws Exception { + Long id = 123L; + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + + when(applicationService.getApplicationProviderDetails(id)).thenReturn(providerDetails); + + this.mockMvc.perform(get("/applications/{id}/provider-details", id)) + .andExpect(status().isOk()); + } + + @Test + public void patchApplicationProviderDetails() throws Exception { + Long id = 123L; + String caabUserLoginId = "test"; + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + + doNothing().when(applicationService).patchProviderDetails(id, caabUserLoginId, providerDetails); + + this.mockMvc.perform(patch("/applications/{id}/provider-details", id) + .header("Caab-user-Login-Id", caabUserLoginId) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(providerDetails))) + .andExpect(status().isNoContent()); + + verify(applicationService).patchProviderDetails(id, caabUserLoginId, providerDetails); + } } \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java index 492c159..3bcd979 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/ApplicationMapperTest.java @@ -19,6 +19,7 @@ import uk.gov.laa.ccms.caab.api.entity.PriorAuthority; import uk.gov.laa.ccms.caab.api.entity.Proceeding; import uk.gov.laa.ccms.caab.model.ApplicationDetail; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import uk.gov.laa.ccms.caab.model.AuditDetail; import uk.gov.laa.ccms.caab.model.Client; @@ -536,5 +537,98 @@ private Application getApplicationWithPriorAuthorities() { return application; } + @Test + public void testToApplicationType() { + Application application = new Application(); + application.setApplicationType("AppType123"); + application.setApplicationTypeDisplayValue("Application Type Display"); + + application.setDevolvedPowersUsed(true); + application.setDateDevolvedPowersUsed(new Date()); + application.setDevolvedPowersContractFlag("ContractFlag123"); + + ApplicationType result = mapper.toApplicationType(application); + + assertNotNull(result); + assertEquals("AppType123", result.getId()); + assertEquals("Application Type Display", result.getDisplayValue()); + + assertNotNull(result.getDevolvedPowers()); + assertEquals(true, result.getDevolvedPowers().getUsed()); + assertNotNull(result.getDevolvedPowers().getDateUsed()); + assertEquals("ContractFlag123", result.getDevolvedPowers().getContractFlag()); + + } + + @Test + public void testAddProviderDetailsWithNullDetails() { + Application application = new Application(); + ApplicationProviderDetails providerDetails = null; + String caabUserLoginId = "user123"; + + mapper.addProviderDetails(application, providerDetails, caabUserLoginId); + + assertNull(application.getProviderId()); + assertNull(application.getProviderDisplayValue()); + assertNull(application.getOfficeId()); + assertNull(application.getOfficeDisplayValue()); + assertNull(application.getSupervisor()); + assertNull(application.getSupervisorDisplayValue()); + assertNull(application.getFeeEarner()); + assertNull(application.getFeeEarnerDisplayValue()); + assertNull(application.getProviderContact()); + assertNull(application.getProviderContactDisplayValue()); + assertEquals("user123", application.getAuditTrail().getModifiedBy()); + } + @Test + public void testAddProviderDetails() { + Application application = new Application(); + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + providerDetails.setProvider(new IntDisplayValue().id(123).displayValue("Provider Display")); + providerDetails.setOffice(new IntDisplayValue().id(1).displayValue("Office 1")); + providerDetails.setSupervisor(new StringDisplayValue().id("Supervisor").displayValue("Supervisor Display Value")); + providerDetails.setFeeEarner(new StringDisplayValue().id("FeeEarner").displayValue("Fee Earner Display Value")); + providerDetails.setProviderContact(new StringDisplayValue().id("ProviderContact").displayValue("Provider Contact Display Value")); + String caabUserLoginId = "user123"; + + mapper.addProviderDetails(application, providerDetails, caabUserLoginId); + + assertEquals("123", application.getProviderId()); + assertEquals("Provider Display", application.getProviderDisplayValue()); + assertEquals(1, application.getOfficeId().intValue()); + assertEquals("Office 1", application.getOfficeDisplayValue()); + assertEquals("Supervisor", application.getSupervisor()); + assertEquals("Supervisor Display Value", application.getSupervisorDisplayValue()); + assertEquals("FeeEarner", application.getFeeEarner()); + assertEquals("Fee Earner Display Value", application.getFeeEarnerDisplayValue()); + assertEquals("ProviderContact", application.getProviderContact()); + assertEquals("Provider Contact Display Value", application.getProviderContactDisplayValue()); + assertEquals("user123", application.getAuditTrail().getModifiedBy()); + } + + @Test + public void testToProviderDetails() { + Application application = new Application(); + application.setProviderId("123"); + application.setProviderDisplayValue("Provider Display Value"); + application.setOfficeId(1L); + application.setOfficeDisplayValue("Office 1"); + application.setSupervisorDisplayValue("Supervisor Display Value"); + application.setFeeEarnerDisplayValue("Fee Earner Display Value"); + application.setProviderContactDisplayValue("Provider Contact Display Value"); + application.setProviderCaseReference("ProviderCase123"); + + ApplicationProviderDetails result = mapper.toProviderDetails(application); + + assertNotNull(result); + assertEquals(123, result.getProvider().getId()); + assertEquals("Provider Display Value", result.getProvider().getDisplayValue()); + assertEquals(1, result.getOffice().getId()); + assertEquals("Office 1", result.getOffice().getDisplayValue()); + assertEquals("Supervisor Display Value", result.getSupervisor().getDisplayValue()); + assertEquals("Fee Earner Display Value", result.getFeeEarner().getDisplayValue()); + assertEquals("Provider Contact Display Value", result.getProviderContact().getDisplayValue()); + assertEquals("ProviderCase123", result.getProviderCaseReference()); + } } diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java index 9c8cd74..8d37e4f 100644 --- a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/ApplicationServiceTest.java @@ -16,6 +16,7 @@ import uk.gov.laa.ccms.caab.api.service.ApplicationService; import uk.gov.laa.ccms.caab.model.ApplicationDetail; import uk.gov.laa.ccms.caab.api.repository.ApplicationRepository; +import uk.gov.laa.ccms.caab.model.ApplicationProviderDetails; import uk.gov.laa.ccms.caab.model.ApplicationType; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -185,6 +186,75 @@ void patchApplicationType_whenNotExists_throwsException() { assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus()); } + @Test + void getApplicationProviderDetails_whenExists_returnsProviderDetails() { + Long id = 1L; + ApplicationProviderDetails expectedProviderDetails = new ApplicationProviderDetails(); + Application application = new Application(); + + when(applicationRepository.findById(id)).thenReturn(Optional.of(application)); // Assuming Application exists + when(applicationMapper.toProviderDetails(application)).thenReturn(expectedProviderDetails); + + ApplicationProviderDetails result = applicationService.getApplicationProviderDetails(id); + + verify(applicationRepository).findById(id); + verify(applicationMapper).toProviderDetails(application); + + assertEquals(expectedProviderDetails, result); + } + + @Test + void getApplicationProviderDetails_whenNotExists_throwsException() { + Long id = 1L; + + when(applicationRepository.findById(id)).thenReturn(Optional.empty()); + + // Use assertThrows to check if the method throws the expected exception + CaabApiException exception = assertThrows(CaabApiException.class, () -> { + applicationService.getApplicationProviderDetails(id); + }); + + verify(applicationRepository).findById(id); + + // Optionally, you can check the exception message and HTTP status code + assertEquals("Application with id 1 not found", exception.getMessage()); + assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus()); + } + + @Test + void patchProviderDetails_whenExists_updatesProviderDetails() { + Long id = 1L; + String caabUserLoginId = "testUser"; + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + Application application = new Application(); + + when(applicationRepository.findById(id)).thenReturn(Optional.of(application)); // Assuming Application exists + + applicationService.patchProviderDetails(id, caabUserLoginId, providerDetails); + + verify(applicationRepository).findById(id); + verify(applicationMapper).addProviderDetails(application, providerDetails, caabUserLoginId); + verify(applicationRepository).save(application); + } + + @Test + void patchProviderDetails_whenNotExists_throwsException() { + Long id = 1L; + String caabUserLoginId = "testUser"; + ApplicationProviderDetails providerDetails = new ApplicationProviderDetails(); + + when(applicationRepository.findById(id)).thenReturn(Optional.empty()); + + CaabApiException exception = assertThrows(CaabApiException.class, () -> { + applicationService.patchProviderDetails(id, caabUserLoginId, providerDetails); + }); + + verify(applicationRepository).findById(id); + + assertEquals("Application with id 1 not found", exception.getMessage()); + assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus()); + } + /** * Helper method to setup the mocking behaviour of applicationMapper and applicationRepository. */