diff --git a/caab-api/open-api-specification.yml b/caab-api/open-api-specification.yml index c9db2f7..5570291 100644 --- a/caab-api/open-api-specification.yml +++ b/caab-api/open-api-specification.yml @@ -17,7 +17,7 @@ paths: type: 'string' example: '1234567890' - name: 'provider-id' - in: query + in: 'query' schema: type: 'string' example: '1234567890' @@ -164,7 +164,7 @@ paths: /applications/clients/{client-reference-id}: patch: tags: - - clients + - applications summary: 'Update a client for all applications with matching client reference id' operationId: 'updateApplicationClient' requestBody: @@ -460,7 +460,6 @@ paths: get: tags: - applications - - linked cases summary: 'Get an application''s linked cases' operationId: 'getApplicationLinkedCases' parameters: @@ -491,7 +490,6 @@ paths: post: tags: - applications - - linked cases summary: 'Add a linked case to an application' operationId: 'addApplicationLinkedCase' parameters: @@ -592,7 +590,7 @@ paths: /applications/{id}/proceedings: get: tags: - - proceedings + - applications summary: 'Get an application''s proceedings' operationId: 'getApplicationProceedings' parameters: @@ -622,7 +620,7 @@ paths: description: 'Internal server error' post: tags: - - proceedings + - applications summary: 'Add a proceeding to an application' operationId: 'addApplicationProceeding' parameters: @@ -723,7 +721,7 @@ paths: /proceedings/{proceeding-id}/scope-limitations: get: tags: - - scope limitations + - proceedings summary: 'Get a proceeding''s scope limitations' operationId: 'getProceedingsScopeLimitations' parameters: @@ -753,7 +751,7 @@ paths: description: 'Internal server error' post: tags: - - scope limitations + - proceedings summary: 'Add a scope limitations to an proceeding' operationId: 'addProceedingScopeLimitation' parameters: @@ -854,7 +852,7 @@ paths: /applications/{id}/prior-authorities: get: tags: - - prior authorities + - applications summary: 'Get an application''s prior authorities' operationId: 'getApplicationPriorAuthorities' parameters: @@ -884,7 +882,7 @@ paths: description: 'Internal server error' post: tags: - - prior authorities + - applications summary: 'Add a prior authority to an application' operationId: 'addApplicationPriorAuthority' parameters: @@ -986,7 +984,7 @@ paths: /applications/{id}/opponents: get: tags: - - opponents + - applications summary: 'Get an application''s opponents' operationId: 'getApplicationOpponents' parameters: @@ -1016,7 +1014,7 @@ paths: description: 'Internal server error' post: tags: - - opponents + - applications summary: 'Add an opponent to an application' operationId: 'addApplicationOpponent' parameters: @@ -1114,7 +1112,199 @@ paths: description: 'Not found' '500': description: 'Internal server error' - + /evidence: + get: + tags: + - evidence + summary: 'Get Evidence Documents' + operationId: 'getEvidenceDocuments' + x-spring-paginated: true + parameters: + - name: 'application-or-outcome-id' + in: 'query' + schema: + type: 'string' + example: '1234567890' + - name: 'case-reference-number' + in: 'query' + schema: + type: 'string' + example: '1234567890' + - name: 'provider-id' + in: 'query' + schema: + type: 'string' + example: '1234567890' + - name: 'document-type' + in: 'query' + schema: + type: 'string' + example: 'type' + - name: 'transfer-status' + in: 'query' + schema: + type: 'string' + example: 'status' + - name: 'ccms-module' + in: 'query' + schema: + type: 'string' + example: 'module' + responses: + '200': + description: 'Successful operation' + content: + application/json: + schema: + $ref: "#/components/schemas/evidenceDocumentDetails" + '400': + description: 'Bad request' + '401': + description: 'Unauthorized' + '404': + description: 'Not found' + '500': + description: 'Internal server error' + post: + tags: + - evidence + summary: 'Create Evidence Document' + operationId: 'createEvidenceDocument' + requestBody: + description: Create Evidence Document + content: + application/json: + schema: + $ref: '#/components/schemas/evidenceDocumentDetail' + parameters: + - name: 'Caab-User-Login-Id' + in: header + required: true + schema: + type: 'string' + example: 'SOMEUSER@COMPANY.CO.UK' + responses: + '200': + description: 'Successful operation' + '400': + description: 'Bad request' + '401': + description: 'Unauthorized' + '404': + description: 'Not found' + '500': + description: 'Internal server error' + delete: + tags: + - evidence + summary: 'Remove Evidence Documents' + operationId: 'removeEvidenceDocuments' + parameters: + - name: 'application-or-outcome-id' + in: 'query' + schema: + type: 'string' + example: '1234567890' + - name: 'case-reference-number' + in: 'query' + schema: + type: 'string' + example: '1234567890' + - name: 'provider-id' + in: 'query' + schema: + type: 'string' + example: '1234567890' + - name: 'document-type' + in: 'query' + schema: + type: 'string' + example: 'type' + - name: 'transfer-status' + in: 'query' + schema: + type: 'string' + example: 'status' + - name: 'ccms-module' + in: 'query' + schema: + type: 'string' + example: 'module' + - name: 'Caab-User-Login-Id' + in: header + required: true + schema: + type: 'string' + example: 'SOMEUSER@COMPANY.CO.UK' + responses: + '204': + description: 'No Content' + '400': + description: 'Bad request' + '401': + description: 'Unauthorized' + '404': + description: 'Not found' + '500': + description: 'Internal server error' + /evidence/{evidence-document-id}: + get: + tags: + - evidence + summary: 'Get Evidence Document' + operationId: 'getEvidenceDocument' + parameters: + - name: 'evidence-document-id' + in: 'path' + required: true + schema: + type: 'integer' + format: 'int64' + example: '1234567890' + responses: + '200': + description: 'Successful operation' + content: + application/json: + schema: + $ref: "#/components/schemas/evidenceDocumentDetail" + '400': + description: 'Bad request' + '401': + description: 'Unauthorized' + '404': + description: 'Not found' + '500': + description: 'Internal server error' + delete: + tags: + - evidence + summary: 'Remove an evidence document' + operationId: 'removeEvidenceDocument' + parameters: + - name: 'evidence-document-id' + in: 'path' + required: true + schema: + type: 'integer' + format: 'int64' + - name: 'Caab-User-Login-Id' + in: header + required: true + schema: + type: 'string' + example: 'SOMEUSER@COMPANY.CO.UK' + responses: + '204': + description: 'No Content' + '400': + description: 'Bad request' + '401': + description: 'Unauthorized' + '404': + description: 'Not found' + '500': + description: 'Internal server error' components: schemas: intDisplayValue: @@ -2041,6 +2231,58 @@ components: $ref: "#/components/schemas/stringDisplayValue" provider_case_reference: type: 'string' + evidenceDocumentDetails: + allOf: + - $ref: "#/components/schemas/page" + type: 'object' + properties: + content: + type: 'array' + default: [] + items: + $ref: '#/components/schemas/evidenceDocumentDetail' + evidenceDocumentDetail: + type: 'object' + properties: + id: + type: 'integer' + application_or_outcome_id: + type: 'string' + case_reference_number: + type: 'string' + provider_id: + type: 'string' + document_type: + $ref: '#/components/schemas/stringDisplayValue' + description: + type: 'string' + registered_document_id: + type: 'string' + document_sender: + type: 'string' + transfer_status: + type: 'string' + file_name: + type: 'string' + file_extension: + type: 'string' + file_data: + type: 'string' + evidence_descriptions: + type: 'string' + transfer_retry_count: + type: 'integer' + transfer_response_code: + type: 'string' + transfer_response_description: + type: 'string' + ccms_module: + type: 'string' + notification_reference: + type: 'string' + audit_trail: + $ref: '#/components/schemas/auditDetail' + auditDetail: type: 'object' properties: diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/AbstractControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/AbstractControllerIntegrationTest.java new file mode 100644 index 0000000..ecea734 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/AbstractControllerIntegrationTest.java @@ -0,0 +1,197 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static uk.gov.laa.ccms.caab.api.audit.AuditorAwareImpl.currentUserHolder; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Objects; +import java.util.Random; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.core.io.ClassPathResource; +import uk.gov.laa.ccms.caab.api.entity.AuditTrail; +import uk.gov.laa.ccms.caab.model.AuditDetail; + +public class AbstractControllerIntegrationTest { + + protected final String caabUserLoginId = "audit@user.com"; + + /** + * Recursively navigate the object using the fields array and set the field to null. + */ + private static void nullifyFieldRecursive(Object object, String[] fields, int index) + throws NoSuchFieldException, IllegalAccessException { + if (object == null || index >= fields.length) { + return; + } + + if (object instanceof List list) { + // Handle List objects + for (Object item : list) { + AbstractControllerIntegrationTest.nullifyFieldRecursive(item, fields, index); + } + } else { + Field field = object.getClass().getDeclaredField(fields[index]); + field.setAccessible(true); + + if (index == fields.length - 1) { + // Last field in the path, set to null + field.set(object, null); + } else { + // Not the last field, navigate to the next object or list in the path + Object nextObject = field.get(object); + AbstractControllerIntegrationTest.nullifyFieldRecursive(nextObject, fields, index + 1); + } + } + } + + @BeforeEach + public void setup() { + currentUserHolder.set(caabUserLoginId); + } + + public static boolean areAllFieldsEqual(Object obj1, Object obj2, Class clazz, List fieldsToIgnore) + throws IllegalArgumentException, IllegalAccessException { + + for (Field field : clazz.getDeclaredFields()) { + field.setAccessible(true); + + // Continue to the next field if it should be ignored + if (fieldsToIgnore.contains(field.getName())) { + continue; + } + + Object value1 = field.get(obj1); + Object value2 = field.get(obj2); + + if (!Objects.equals(value1, value2)) { + System.out.println("Field " + field.getName() + " is not equal: " + value1 + " != " + value2); + return false; + } + } + return true; + } + + /** + * Loads the JSON file from the classpath and parses it into a specified object. + * + * @param jsonFilePath The path to the JSON file to load + */ + protected T loadObjectFromJson(String jsonFilePath, Class objectType) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + ClassPathResource resource = new ClassPathResource(jsonFilePath); + return objectMapper.readValue(resource.getInputStream(), objectType); + } + + /** + * Generates a random 12-digit number string to be used as a case reference number. + */ + protected String generateTestCaseRef() { + Random random = new Random(); + StringBuilder stringBuilder = new StringBuilder(12); + + for (int i = 0; i < 12; i++) { + int digit = random.nextInt(10); // Generate a random digit (0-9) + stringBuilder.append(digit); + } + + return stringBuilder.toString(); + } + + // Utility method to resolve the method chain and get the value + protected Object getObjectToCheckFromMethod(Object initialObject, String[] methodCalls) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + + Object currentObject = initialObject; + for (String methodName : methodCalls) { + Method method = currentObject.getClass().getMethod(methodName); + currentObject = method.invoke(currentObject); + } + return currentObject; + } + + /** + * Used to assert that the audit detail is set correctly. + * + * @param auditDetail The audit trail to check + * @param expectedAuditUser The expected audit user + */ + protected void assertAuditTrail(AuditDetail auditDetail, String expectedAuditUser) { + assertNotNull(auditDetail); + assertEquals(expectedAuditUser, auditDetail.getCreatedBy()); + assertEquals(expectedAuditUser, auditDetail.getLastSavedBy()); + assertNotNull(auditDetail.getCreated()); + assertNotNull(auditDetail.getLastSaved()); + } + + /** + * Assert that the audit trail is set correctly in the object. Uses reflection to navigate the + * auditTrailMethod path and assert that the audit trail is set correctly. + */ + protected void assertAuditTrail(Object object, String auditMethod, String expectedAuditUser) + throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { + String[] methodCalls = auditMethod.split("\\."); + assertAuditTrailRecursive(object, methodCalls, 0, expectedAuditUser); + } + + /** + * Recursively navigate the object using the methodCalls array and assert that the audit trail is + * set correctly. + */ + private void assertAuditTrailRecursive(Object object, String[] methodCalls, int index, String expectedAuditUser) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + if (index >= methodCalls.length || object == null) { + return; + } + + Method method = object.getClass().getMethod(methodCalls[index]); + object = method.invoke(object); + + if (object instanceof List list) { + for (Object item : list) { + assertAuditTrailRecursive(item, methodCalls, index + 1, expectedAuditUser); + } + } else { + if (index == methodCalls.length - 1) { + assertAuditDetailsInObject(object, expectedAuditUser); + } else { + assertAuditTrailRecursive(object, methodCalls, index + 1, expectedAuditUser); + } + } + } + + /** + * Used to assert that the audit trail is set correctly in the object. + * + * @param object The object to check + * @param expectedAuditUser The expected audit user + */ + private void assertAuditDetailsInObject(Object object, String expectedAuditUser) { + if (object instanceof AuditTrail auditTrail) { + assertNotNull(auditTrail); + assertEquals(expectedAuditUser, auditTrail.getCreatedBy()); + assertEquals(expectedAuditUser, auditTrail.getLastSavedBy()); + assertNotNull(auditTrail.getCreated()); + assertNotNull(auditTrail.getLastSaved()); + } + } + + /** + * Sets the audit trail properties to null in the object. Uses reflection to navigate the + * list of auditTrailsToNull and set the audit trail to null. + */ + protected void setAuditPropertiesToNull(Object object, List auditTrailsToNull) throws NoSuchFieldException, IllegalAccessException { + if (object == null || auditTrailsToNull == null) { + return; + } + for (String trail : auditTrailsToNull) { + String[] fields = trail.split("\\."); + AbstractControllerIntegrationTest.nullifyFieldRecursive(object, fields, 0); + } + } +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseApplicationControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseApplicationControllerIntegrationTest.java index 0961501..e3c035a 100644 --- a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseApplicationControllerIntegrationTest.java +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseApplicationControllerIntegrationTest.java @@ -4,31 +4,22 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static uk.gov.laa.ccms.caab.api.audit.AuditorAwareImpl.currentUserHolder; -import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.URI; import java.util.List; -import java.util.Objects; -import java.util.Random; import java.util.stream.Stream; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.ClassPathResource; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.jdbc.Sql; import uk.gov.laa.ccms.caab.api.controller.ApplicationController; -import uk.gov.laa.ccms.caab.api.entity.AuditTrail; import uk.gov.laa.ccms.caab.api.service.ApplicationService; import uk.gov.laa.ccms.caab.model.ApplicationDetail; import uk.gov.laa.ccms.caab.model.ApplicationDetails; @@ -40,7 +31,8 @@ import uk.gov.laa.ccms.caab.model.Proceeding; import uk.gov.laa.ccms.caab.model.ScopeLimitation; -public abstract class BaseApplicationControllerIntegrationTest { +public abstract class BaseApplicationControllerIntegrationTest + extends AbstractControllerIntegrationTest { @Autowired private ApplicationController applicationController; @@ -48,39 +40,6 @@ public abstract class BaseApplicationControllerIntegrationTest { @Autowired private ApplicationService applicationService; - private final String caabUserLoginId = "audit@user.com"; - - @BeforeEach - public void setup() { - currentUserHolder.set(caabUserLoginId); - } - - /** - * Loads the JSON file from the classpath and parses it into a specified object. - * - * @param jsonFilePath The path to the JSON file to load - */ - private T loadObjectFromJson(String jsonFilePath, Class objectType) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - ClassPathResource resource = new ClassPathResource(jsonFilePath); - return objectMapper.readValue(resource.getInputStream(), objectType); - } - - - /** - * Generates a random 12-digit number string to be used as a case reference number. - */ - private String generateTestCaseRef(){ - Random random = new Random(); - StringBuilder stringBuilder = new StringBuilder(12); - - for (int i = 0; i < 12; i++) { - int digit = random.nextInt(10); // Generate a random digit (0-9) - stringBuilder.append(digit); - } - - return stringBuilder.toString(); - } private static Stream createApplicationUpdateArguments() { return Stream.of( @@ -131,40 +90,6 @@ public void testUpdateApplication(String fileInput, String methodCall, String fi ApplicationDetail.class, List.of(fieldToIgnore, "auditTrail"))); } - // Utility method to resolve the method chain and get the value - private Object getObjectToCheckFromMethod(Object initialObject, String[] methodCalls) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - - Object currentObject = initialObject; - for (String methodName : methodCalls) { - Method method = currentObject.getClass().getMethod(methodName); - currentObject = method.invoke(currentObject); - } - return currentObject; - } - - - public static boolean areAllFieldsEqual(Object obj1, Object obj2, Class clazz, List fieldsToIgnore) - throws IllegalArgumentException, IllegalAccessException { - - for (Field field : clazz.getDeclaredFields()) { - field.setAccessible(true); - - // Continue to the next field if it should be ignored - if (fieldsToIgnore.contains(field.getName())) { - continue; - } - - Object value1 = field.get(obj1); - Object value2 = field.get(obj2); - - if (!Objects.equals(value1, value2)) { - System.out.println("Field " + field.getName() + " is not equal: " + value1 + " != " + value2); - return false; - } - } - return true; - } /** * Arguments for the testCreateApplication test method. @@ -466,18 +391,6 @@ public void addApplicationProceedings() throws IOException { assertEquals(1, proceedings.size()); } - @Test - @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql"}) - public void updateProceeding() throws IOException { - Long proceedingId = 2L; - - Proceeding updatedProceeding = loadObjectFromJson("/json/proceeding_new.json", Proceeding.class); - - ResponseEntity response = applicationController.updateProceeding(proceedingId, caabUserLoginId, updatedProceeding); - - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - } - @Test @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql"}) public void getApplicationProceedings() { @@ -492,22 +405,6 @@ public void getApplicationProceedings() { assertEquals(1, proceedings.size()); } - @Test - @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql"}) - public void deleteApplicationProceedings() { - Long caseRef = 41L; - Long proceedingRef = 2L; - - applicationController.removeProceeding(proceedingRef, caabUserLoginId); - ResponseEntity> responseEntity = applicationController.getApplicationProceedings(caseRef); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - assertNotNull(responseEntity.getBody()); - - List proceedings = responseEntity.getBody(); - assertEquals(0, proceedings.size()); - } - @Test @Sql(scripts = {"/sql/application_insert.sql"}) public void addLinkedCase() throws IOException { @@ -545,22 +442,6 @@ public void getLinkedCase() { assertEquals(1, linkedCases.size()); } - @Test - @Sql(scripts = {"/sql/application_insert.sql", "/sql/linked_cases_insert.sql"}) - public void deleteLinkedCase() { - Long caseRef = 41L; - Long linkedCaseRef = 2L; - - applicationController.removeLinkedCase(linkedCaseRef, caabUserLoginId); - ResponseEntity> responseEntity = applicationController.getApplicationLinkedCases(caseRef); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - assertNotNull(responseEntity.getBody()); - - List linkedCases = responseEntity.getBody(); - assertEquals(0, linkedCases.size()); - } - @Test @Sql(scripts = {"/sql/application_insert.sql"}) public void addPriorAuthority() throws IOException { @@ -574,18 +455,6 @@ public void addPriorAuthority() throws IOException { assertEquals(HttpStatus.CREATED, response.getStatusCode()); } - @Test - @Sql(scripts = {"/sql/application_insert.sql", "/sql/prior_authority_insert.sql"}) - public void updatePriorAuthority() throws IOException { - Long priorAuthorityId = 2L; - - PriorAuthority updatedPriorAuthority = loadObjectFromJson("/json/prior_authority_new.json", PriorAuthority.class); - - ResponseEntity response = applicationController.updatePriorAuthority(priorAuthorityId, caabUserLoginId, updatedPriorAuthority); - - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - } - @Test @Sql(scripts = {"/sql/application_insert.sql", "/sql/prior_authority_insert.sql"}) public void getPriorAuthority() { @@ -600,84 +469,6 @@ public void getPriorAuthority() { assertEquals(1, priorAuthorities.size()); } - @Test - @Sql(scripts = {"/sql/application_insert.sql", "/sql/prior_authority_insert.sql"}) - public void deletePriorAuthority() { - Long caseRef = 41L; - Long priorAuthorityRef = 2L; - - applicationController.removePriorAuthority(priorAuthorityRef, caabUserLoginId); - ResponseEntity> responseEntity = applicationController.getApplicationPriorAuthorities(caseRef); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - assertNotNull(responseEntity.getBody()); - - List priorAuthorities = responseEntity.getBody(); - assertEquals(0, priorAuthorities.size()); - } - - @Test - @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql"}) - public void addScopeLimitationToProceeding() throws IOException { - Long proceedingId = 2L; - - ScopeLimitation scopeLimitation = loadObjectFromJson("/json/scope_limitation_new.json", ScopeLimitation.class); - - ResponseEntity response = applicationController.addProceedingScopeLimitation(proceedingId, caabUserLoginId, scopeLimitation); - - assertEquals(HttpStatus.CREATED, response.getStatusCode()); - } - - @Test - @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql", "/sql/scope_limitation_insert.sql"}) - public void updateScopeLimitationInProceeding() throws IOException { - Long scopeLimitationId = 3L; - - ScopeLimitation updatedScopeLimitation = loadObjectFromJson("/json/scope_limitation_new.json", ScopeLimitation.class); - - ResponseEntity response = applicationController.updateScopeLimitation(scopeLimitationId, caabUserLoginId, updatedScopeLimitation); - - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - } - - - @Test - @Sql(scripts = { - "/sql/application_insert.sql", - "/sql/proceeding_insert.sql", - "/sql/scope_limitation_insert.sql"}) - public void getScopeLimitationsForProceeding() { - Long proceedingId = 2L; - - ResponseEntity> responseEntity = applicationController.getProceedingsScopeLimitations(proceedingId); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - assertNotNull(responseEntity.getBody()); - - List scopeLimitations = responseEntity.getBody(); - assertFalse(scopeLimitations.isEmpty()); - } - - @Test - @Sql(scripts = { - "/sql/application_insert.sql", - "/sql/proceeding_insert.sql", - "/sql/scope_limitation_insert.sql"}) - public void removeScopeLimitationFromProceeding() { - Long scopeLimitationId = 3L; - - ResponseEntity response = applicationController.removeScopeLimitation(scopeLimitationId, caabUserLoginId); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - - ResponseEntity> responseEntity = applicationController.getProceedingsScopeLimitations(2L); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - assertNotNull(responseEntity.getBody()); - - List scopeLimitations = responseEntity.getBody(); - assertTrue(scopeLimitations.isEmpty()); - } - @Test @Sql(scripts = {"/sql/application_insert.sql"}) public void updateClient() throws IOException { @@ -715,19 +506,6 @@ public void addOpponentToApplication() throws IOException { assertEquals(HttpStatus.CREATED, response.getStatusCode()); } - @Test - @Sql(scripts = {"/sql/application_insert.sql", "/sql/opponent_insert.sql"}) - public void updateOpponentInApplication() throws IOException { - Long opponentId = 3L; - - Opponent updatedOpponent = loadObjectFromJson("/json/opponent_new.json", Opponent.class); - - ResponseEntity response = applicationController.updateOpponent(opponentId, caabUserLoginId, updatedOpponent); - - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - } - - @Test @Sql(scripts = { "/sql/application_insert.sql", @@ -744,121 +522,4 @@ public void getOpponentsForApplication() { assertFalse(opponents.isEmpty()); } - @Test - @Sql(scripts = { - "/sql/application_insert.sql", - "/sql/opponent_insert.sql"}) - public void removeOpponentFromApplication() { - Long caseRef = 41L; - Long opponentRef = 3L; - - ResponseEntity response = applicationController.removeOpponent( - opponentRef, caabUserLoginId); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - - ResponseEntity> responseEntity = applicationController.getApplicationOpponents( - caseRef); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - assertNotNull(responseEntity.getBody()); - - List opponents = responseEntity.getBody(); - assertTrue(opponents.isEmpty()); - } - - /** - * Assert that the audit trail is set correctly in the object. Uses reflection to navigate the - * auditTrailMethod path and assert that the audit trail is set correctly. - */ - private void assertAuditTrail(Object object, String auditMethod, String expectedAuditUser) - throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { - String[] methodCalls = auditMethod.split("\\."); - assertAuditTrailRecursive(object, methodCalls, 0, expectedAuditUser); - } - - /** - * Recursively navigate the object using the methodCalls array and assert that the audit trail is - * set correctly. - */ - private void assertAuditTrailRecursive(Object object, String[] methodCalls, int index, String expectedAuditUser) - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - if (index >= methodCalls.length || object == null) { - return; - } - - Method method = object.getClass().getMethod(methodCalls[index]); - object = method.invoke(object); - - if (object instanceof List list) { - for (Object item : list) { - assertAuditTrailRecursive(item, methodCalls, index + 1, expectedAuditUser); - } - } else { - if (index == methodCalls.length - 1) { - assertAuditDetailsInObject(object, expectedAuditUser); - } else { - assertAuditTrailRecursive(object, methodCalls, index + 1, expectedAuditUser); - } - } - } - - /** - * Used to assert that the audit trail is set correctly in the object. - * - * @param object The object to check - * @param expectedAuditUser The expected audit user - */ - private void assertAuditDetailsInObject(Object object, String expectedAuditUser) { - if (object instanceof AuditTrail auditTrail) { - assertNotNull(auditTrail); - assertEquals(expectedAuditUser, auditTrail.getCreatedBy()); - assertEquals(expectedAuditUser, auditTrail.getLastSavedBy()); - assertNotNull(auditTrail.getCreated()); - assertNotNull(auditTrail.getLastSaved()); - } - } - - /** - * Sets the audit trail properties to null in the object. Uses reflection to navigate the - * list of auditTrailsToNull and set the audit trail to null. - */ - private void setAuditPropertiesToNull(Object object, List auditTrailsToNull) throws NoSuchFieldException, IllegalAccessException { - if (object == null || auditTrailsToNull == null) { - return; - } - for (String trail : auditTrailsToNull) { - String[] fields = trail.split("\\."); - nullifyFieldRecursive(object, fields, 0); - } - } - - /** - * Recursively navigate the object using the fields array and set the field to null. - */ - private static void nullifyFieldRecursive(Object object, String[] fields, int index) - throws NoSuchFieldException, IllegalAccessException { - if (object == null || index >= fields.length) { - return; - } - - if (object instanceof List list) { - // Handle List objects - for (Object item : list) { - nullifyFieldRecursive(item, fields, index); - } - } else { - Field field = object.getClass().getDeclaredField(fields[index]); - field.setAccessible(true); - - if (index == fields.length - 1) { - // Last field in the path, set to null - field.set(object, null); - } else { - // Not the last field, navigate to the next object or list in the path - Object nextObject = field.get(object); - nullifyFieldRecursive(nextObject, fields, index + 1); - } - } - } - } 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 new file mode 100644 index 0000000..5e9c236 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseEvidenceControllerIntegrationTest.java @@ -0,0 +1,220 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.net.URI; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +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.EvidenceDocumentDetail; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetails; + +public abstract class BaseEvidenceControllerIntegrationTest + extends AbstractControllerIntegrationTest { + + @Autowired + private EvidenceController evidenceController; + + @Autowired + private EvidenceService evidenceService; + + @Test + public void testCreateEvidenceDocument() throws Exception { + + EvidenceDocumentDetail evidenceDocumentDetail = loadObjectFromJson( + "/json/evidence_document_new.json", EvidenceDocumentDetail.class); + + String auditUser = "audit@user.com"; + + // Call the createEvidenceDocument method directly + ResponseEntity responseEntity = + evidenceController.createEvidenceDocument(auditUser, evidenceDocumentDetail); + + assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode()); + URI locationUri = responseEntity.getHeaders().getLocation(); + + String path = locationUri.getPath(); + String id = path.substring(path.lastIndexOf('/') + 1); + + EvidenceDocumentDetail savedEvidenceDocumentDetails = + evidenceService.getEvidenceDocument(Long.valueOf(id)); + + assertAuditTrail(savedEvidenceDocumentDetails.getAuditTrail(), auditUser); + + // Clear the audit trail for comparison purposes. + savedEvidenceDocumentDetails.setAuditTrail(null); + + // null/ignore the ids as theses are generated by the database + savedEvidenceDocumentDetails.setId(null); + + assertEquals(evidenceDocumentDetail, savedEvidenceDocumentDetails); + } + + @Test + @Sql(scripts = "/sql/evidence_document_insert.sql") + public void testGetEvidenceDocuments_byApplicationOrOutcomeId() { + + // Call the getEvidenceDocuments method directly + ResponseEntity responseEntity = + evidenceController.getEvidenceDocuments( + "appId", + null, + null, + null, + null, + null, + Pageable.unpaged() + ); + + assertNotNull(responseEntity); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertNotNull(responseEntity.getBody()); + assertNotNull(responseEntity.getBody().getContent()); + assertEquals(2, responseEntity.getBody().getContent().size()); + + EvidenceDocumentDetail retrievedEvidenceDocumentDetails = + evidenceService.getEvidenceDocument(3L); + + assertEquals(retrievedEvidenceDocumentDetails, responseEntity.getBody().getContent().get(0)); + } + + @Test + @Sql(scripts = "/sql/evidence_document_insert.sql") + public void testGetEvidenceDocuments_usingAllFields() { + + // Call the getEvidenceDocuments method directly + ResponseEntity responseEntity = + evidenceController.getEvidenceDocuments( + "appId", + "caseref", + "provid", + "doctype", + "SUCCESS", + "B", + Pageable.unpaged() + ); + + assertNotNull(responseEntity); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertNotNull(responseEntity.getBody()); + assertNotNull(responseEntity.getBody().getContent()); + assertEquals(1, responseEntity.getBody().getContent().size()); + + EvidenceDocumentDetail retrievedEvidenceDocumentDetails = + evidenceService.getEvidenceDocument(3L); + + assertEquals(retrievedEvidenceDocumentDetails, responseEntity.getBody().getContent().get(0)); + } + + @Test + @Sql(scripts = "/sql/evidence_document_insert.sql") + public void testGetEvidenceDocument() { + + // Call the getEvidenceDocument method directly + ResponseEntity responseEntity = + evidenceController.getEvidenceDocument(3L); + + assertNotNull(responseEntity); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertNotNull(responseEntity.getBody()); + assertEquals(3, responseEntity.getBody().getId()); + } + + @Test + @Sql(scripts = "/sql/evidence_document_insert.sql") + public void testRemoveEvidenceDocument() { + + // Call the removeEvidenceDocuments method directly + ResponseEntity responseEntity = + evidenceController.removeEvidenceDocument(3L, caabUserLoginId); + + assertNotNull(responseEntity); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + + EvidenceDocumentDetails queriedDocuments = + evidenceController.getEvidenceDocuments( + "appId", + "caseref", + "provid", + "doctype", + "SUCCESS", + "B", + Pageable.unpaged() + ).getBody(); + + assertEquals(0, queriedDocuments.getContent().size()); + } + + @Test + @Sql(scripts = "/sql/evidence_document_insert.sql") + public void testRemoveEvidenceDocuments_usingAllFields() { + + // Call the removeEvidenceDocuments method directly + ResponseEntity responseEntity = + evidenceController.removeEvidenceDocuments( + "Caab-user-login-id", + "appId", + "caseref", + "provid", + "doctype", + "SUCCESS", + "B" + ); + + assertNotNull(responseEntity); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + + // Check that only 1 of the EvidenceDocuments (with ccms module B) has been deleted. + EvidenceDocumentDetails queriedDocuments = + evidenceController.getEvidenceDocuments( + "appId", + "caseref", + "provid", + "doctype", + "SUCCESS", + null, + Pageable.unpaged() + ).getBody(); + + assertEquals(1, queriedDocuments.getContent().size()); + } + + @Test + @Sql(scripts = "/sql/evidence_document_insert.sql") + public void testRemoveEvidenceDocuments_byCaseRef() { + + // Call the removeEvidenceDocuments method directly + ResponseEntity responseEntity = + evidenceController.removeEvidenceDocuments( + "Caab-user-login-id", + null, + "caseref", + null, + null, + null, + null + ); + + assertNotNull(responseEntity); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + + EvidenceDocumentDetails queriedDocuments = + evidenceController.getEvidenceDocuments( + null, + "caseref", + null, + null, + null, + null, + Pageable.unpaged() + ).getBody(); + + assertEquals(0, queriedDocuments.getContent().size()); + } +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseLinkedCaseControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseLinkedCaseControllerIntegrationTest.java new file mode 100644 index 0000000..5a7d7c9 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseLinkedCaseControllerIntegrationTest.java @@ -0,0 +1,54 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.jdbc.Sql; +import uk.gov.laa.ccms.caab.api.controller.LinkedCaseController; +import uk.gov.laa.ccms.caab.api.service.ApplicationService; +import uk.gov.laa.ccms.caab.model.LinkedCase; + +public abstract class BaseLinkedCaseControllerIntegrationTest + extends AbstractControllerIntegrationTest { + + @Autowired + private LinkedCaseController linkedCaseController; + + @Autowired + private ApplicationService applicationService; + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/linked_cases_insert.sql"}) + public void updateLinkedCase() throws Exception { + Long caseRef = 41L; + Long linkedCaseRef = 2L; + + LinkedCase linkedCase = loadObjectFromJson("/json/linked_cases_new.json", LinkedCase.class); + linkedCase.setId(linkedCaseRef.intValue()); + + linkedCaseController.updateLinkedCase(linkedCaseRef, caabUserLoginId, linkedCase); + + List linkedCases = applicationService.getLinkedCasesForApplication(caseRef); + + assertEquals(1, linkedCases.size()); + + // Remove the audittrail for comparison purposes. + LinkedCase retrievedLinkedCase = linkedCases.get(0); + retrievedLinkedCase.setAuditTrail(null); + + assertEquals(linkedCase, retrievedLinkedCase); + } + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/linked_cases_insert.sql"}) + public void deleteLinkedCase() { + Long caseRef = 41L; + Long linkedCaseRef = 2L; + + linkedCaseController.removeLinkedCase(linkedCaseRef, caabUserLoginId); + List linkedCases = applicationService.getLinkedCasesForApplication(caseRef); + assertEquals(0, linkedCases.size()); + } +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseOpponentControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseOpponentControllerIntegrationTest.java new file mode 100644 index 0000000..2c29a0b --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseOpponentControllerIntegrationTest.java @@ -0,0 +1,48 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.jdbc.Sql; +import uk.gov.laa.ccms.caab.api.controller.OpponentController; +import uk.gov.laa.ccms.caab.api.service.ApplicationService; +import uk.gov.laa.ccms.caab.model.Opponent; + +public abstract class BaseOpponentControllerIntegrationTest + extends AbstractControllerIntegrationTest { + + @Autowired + private OpponentController opponentController; + + @Autowired + private ApplicationService applicationService; + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/opponent_insert.sql"}) + public void updateOpponent() throws IOException { + Long opponentId = 3L; + + Opponent updatedOpponent = loadObjectFromJson("/json/opponent_new.json", Opponent.class); + + ResponseEntity response = opponentController.updateOpponent(opponentId, caabUserLoginId, updatedOpponent); + + assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + } + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/opponent_insert.sql"}) + public void removeOpponent() { + Long caseRef = 41L; + Long opponentId = 3L; + + opponentController.removeOpponent(opponentId, caabUserLoginId); + List opponents = applicationService.getOpponentsForApplication(caseRef); + assertEquals(0, opponents.size()); + } + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BasePriorAuthorityControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BasePriorAuthorityControllerIntegrationTest.java new file mode 100644 index 0000000..6ceeb04 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BasePriorAuthorityControllerIntegrationTest.java @@ -0,0 +1,48 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.jdbc.Sql; +import uk.gov.laa.ccms.caab.api.controller.PriorAuthorityController; +import uk.gov.laa.ccms.caab.api.service.ApplicationService; +import uk.gov.laa.ccms.caab.model.PriorAuthority; + +public abstract class BasePriorAuthorityControllerIntegrationTest + extends AbstractControllerIntegrationTest { + + @Autowired + private PriorAuthorityController priorAuthorityController; + + @Autowired + private ApplicationService applicationService; + + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/prior_authority_insert.sql"}) + public void updatePriorAuthority() throws IOException { + Long priorAuthorityId = 2L; + + PriorAuthority updatedPriorAuthority = loadObjectFromJson("/json/prior_authority_new.json", PriorAuthority.class); + + ResponseEntity response = priorAuthorityController.updatePriorAuthority(priorAuthorityId, caabUserLoginId, updatedPriorAuthority); + + assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + } + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/prior_authority_insert.sql"}) + public void deletePriorAuthority() { + Long caseRef = 41L; + Long priorAuthorityRef = 2L; + + priorAuthorityController.removePriorAuthority(priorAuthorityRef, caabUserLoginId); + List priorAuthorities = applicationService.getPriorAuthoritiesForApplication(caseRef); + assertEquals(0, priorAuthorities.size()); + } +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseProceedingControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseProceedingControllerIntegrationTest.java new file mode 100644 index 0000000..0bf10f3 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseProceedingControllerIntegrationTest.java @@ -0,0 +1,81 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.io.IOException; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.jdbc.Sql; +import uk.gov.laa.ccms.caab.api.controller.ProceedingController; +import uk.gov.laa.ccms.caab.api.service.ApplicationService; +import uk.gov.laa.ccms.caab.model.Proceeding; +import uk.gov.laa.ccms.caab.model.ScopeLimitation; + +public abstract class BaseProceedingControllerIntegrationTest + extends AbstractControllerIntegrationTest { + + @Autowired + private ProceedingController proceedingController; + + @Autowired + private ApplicationService applicationService; + + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql"}) + public void updateProceeding() throws IOException { + Long proceedingId = 2L; + + Proceeding updatedProceeding = loadObjectFromJson("/json/proceeding_new.json", Proceeding.class); + + ResponseEntity response = proceedingController.updateProceeding(proceedingId, caabUserLoginId, updatedProceeding); + + assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + } + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql"}) + public void deleteProceedings() { + Long caseRef = 41L; + Long proceedingRef = 2L; + + proceedingController.removeProceeding(proceedingRef, caabUserLoginId); + List proceedings = applicationService.getProceedingsForApplication(caseRef); + assertEquals(0, proceedings.size()); + } + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql"}) + public void addScopeLimitationToProceeding() throws IOException { + Long proceedingId = 2L; + + ScopeLimitation scopeLimitation = loadObjectFromJson("/json/scope_limitation_new.json", ScopeLimitation.class); + + ResponseEntity response = proceedingController.addProceedingScopeLimitation(proceedingId, caabUserLoginId, scopeLimitation); + + assertEquals(HttpStatus.CREATED, response.getStatusCode()); + } + + + @Test + @Sql(scripts = { + "/sql/application_insert.sql", + "/sql/proceeding_insert.sql", + "/sql/scope_limitation_insert.sql"}) + public void getScopeLimitationsForProceeding() { + Long proceedingId = 2L; + + ResponseEntity> responseEntity = proceedingController.getProceedingsScopeLimitations(proceedingId); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertNotNull(responseEntity.getBody()); + + List scopeLimitations = responseEntity.getBody(); + assertFalse(scopeLimitations.isEmpty()); + } +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseScopeLimitiationControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseScopeLimitiationControllerIntegrationTest.java new file mode 100644 index 0000000..204e249 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/BaseScopeLimitiationControllerIntegrationTest.java @@ -0,0 +1,48 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.jdbc.Sql; +import uk.gov.laa.ccms.caab.api.controller.ScopeLimitationController; +import uk.gov.laa.ccms.caab.api.service.ProceedingService; +import uk.gov.laa.ccms.caab.model.ScopeLimitation; + +public abstract class BaseScopeLimitiationControllerIntegrationTest + extends AbstractControllerIntegrationTest { + + @Autowired + private ScopeLimitationController scopeLimitationController; + + @Autowired + private ProceedingService proceedingService; + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql", "/sql/scope_limitation_insert.sql"}) + public void updateScopeLimitation() throws IOException { + Long scopeLimitationId = 3L; + + ScopeLimitation updatedScopeLimitation = loadObjectFromJson("/json/scope_limitation_new.json", ScopeLimitation.class); + + ResponseEntity response = scopeLimitationController.updateScopeLimitation(scopeLimitationId, caabUserLoginId, updatedScopeLimitation); + + assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + } + + @Test + @Sql(scripts = {"/sql/application_insert.sql", "/sql/proceeding_insert.sql", "/sql/scope_limitation_insert.sql"}) + public void deleteScopeLimitation() { + Long proceedingId = 2L; + Long scopeLimitationId = 3L; + + scopeLimitationController.removeScopeLimitation(scopeLimitationId, caabUserLoginId); + List scopeLimitations = proceedingService.getScopeLimitationsForProceeding(proceedingId); + assertEquals(0, scopeLimitations.size()); + } + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/EvidenceControllerIntegrationLocalTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/EvidenceControllerIntegrationLocalTest.java new file mode 100644 index 0000000..3d73383 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/EvidenceControllerIntegrationLocalTest.java @@ -0,0 +1,23 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@ActiveProfiles("local") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/delete_data.sql") +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/delete_data.sql") +public class EvidenceControllerIntegrationLocalTest extends BaseEvidenceControllerIntegrationTest { + + //this runs all tests in BaseEvidenceControllerIntegrationTest, do not add anything here + //this is an easy way to run the tests if you have the containerised database running locally already + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/EvidenceControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/EvidenceControllerIntegrationTest.java new file mode 100644 index 0000000..3984769 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/EvidenceControllerIntegrationTest.java @@ -0,0 +1,23 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; +import uk.gov.laa.ccms.data.api.IntegrationTestInterface; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql") +public class EvidenceControllerIntegrationTest extends BaseEvidenceControllerIntegrationTest implements + IntegrationTestInterface { + + //this runs all tests in BaseEvidenceControllerIntegrationTest, do not add anything here + //running this class takes longer than the local version, but it is used for running tests in a pipeline + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/LinkedCaseControllerIntegrationLocalTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/LinkedCaseControllerIntegrationLocalTest.java new file mode 100644 index 0000000..fdf3a0b --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/LinkedCaseControllerIntegrationLocalTest.java @@ -0,0 +1,24 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@ActiveProfiles("local") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/delete_data.sql") +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/delete_data.sql") +public class LinkedCaseControllerIntegrationLocalTest + extends BaseLinkedCaseControllerIntegrationTest { + + //this runs all tests in BaseLinkedCaseControllerIntegrationTest, do not add anything here + //this is an easy way to run the tests if you have the containerised database running locally already + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/LinkedCaseControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/LinkedCaseControllerIntegrationTest.java new file mode 100644 index 0000000..d3faddc --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/LinkedCaseControllerIntegrationTest.java @@ -0,0 +1,23 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; +import uk.gov.laa.ccms.data.api.IntegrationTestInterface; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql") +public class LinkedCaseControllerIntegrationTest extends BaseLinkedCaseControllerIntegrationTest + implements IntegrationTestInterface { + + //this runs all tests in BaseLinkedCaseControllerIntegrationTest, do not add anything here + //running this class takes longer than the local version, but it is used for running tests in a pipeline + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/OpponentControllerIntegrationLocalTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/OpponentControllerIntegrationLocalTest.java new file mode 100644 index 0000000..559e363 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/OpponentControllerIntegrationLocalTest.java @@ -0,0 +1,24 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@ActiveProfiles("local") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/delete_data.sql") +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/delete_data.sql") +public class OpponentControllerIntegrationLocalTest + extends BaseOpponentControllerIntegrationTest { + + //this runs all tests in BaseOpponentControllerIntegrationTest, do not add anything here + //this is an easy way to run the tests if you have the containerised database running locally already + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/OpponentControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/OpponentControllerIntegrationTest.java new file mode 100644 index 0000000..de7820f --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/OpponentControllerIntegrationTest.java @@ -0,0 +1,23 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; +import uk.gov.laa.ccms.data.api.IntegrationTestInterface; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql") +public class OpponentControllerIntegrationTest extends BaseOpponentControllerIntegrationTest + implements IntegrationTestInterface { + + //this runs all tests in BaseOpponentControllerIntegrationTest, do not add anything here + //running this class takes longer than the local version, but it is used for running tests in a pipeline + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/PriorAuthorityControllerIntegrationLocalTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/PriorAuthorityControllerIntegrationLocalTest.java new file mode 100644 index 0000000..0762c9d --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/PriorAuthorityControllerIntegrationLocalTest.java @@ -0,0 +1,24 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@ActiveProfiles("local") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/delete_data.sql") +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/delete_data.sql") +public class PriorAuthorityControllerIntegrationLocalTest + extends BasePriorAuthorityControllerIntegrationTest { + + //this runs all tests in BasePriorAuthorityControllerIntegrationTest, do not add anything here + //this is an easy way to run the tests if you have the containerised database running locally already + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/PriorAuthorityControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/PriorAuthorityControllerIntegrationTest.java new file mode 100644 index 0000000..7354c4d --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/PriorAuthorityControllerIntegrationTest.java @@ -0,0 +1,24 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; +import uk.gov.laa.ccms.data.api.IntegrationTestInterface; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql") +public class PriorAuthorityControllerIntegrationTest + extends BasePriorAuthorityControllerIntegrationTest + implements IntegrationTestInterface { + + //this runs all tests in BasePriorAuthorityControllerIntegrationTest, do not add anything here + //running this class takes longer than the local version, but it is used for running tests in a pipeline + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ProceedingControllerIntegrationLocalTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ProceedingControllerIntegrationLocalTest.java new file mode 100644 index 0000000..c5b5811 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ProceedingControllerIntegrationLocalTest.java @@ -0,0 +1,24 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@ActiveProfiles("local") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/delete_data.sql") +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/delete_data.sql") +public class ProceedingControllerIntegrationLocalTest + extends BaseProceedingControllerIntegrationTest { + + //this runs all tests in BaseProceedingControllerIntegrationTest, do not add anything here + //this is an easy way to run the tests if you have the containerised database running locally already + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ProceedingControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ProceedingControllerIntegrationTest.java new file mode 100644 index 0000000..d325e70 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ProceedingControllerIntegrationTest.java @@ -0,0 +1,24 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; +import uk.gov.laa.ccms.data.api.IntegrationTestInterface; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql") +public class ProceedingControllerIntegrationTest + extends BaseProceedingControllerIntegrationTest + implements IntegrationTestInterface { + + //this runs all tests in BaseProceedingControllerIntegrationTest, do not add anything here + //running this class takes longer than the local version, but it is used for running tests in a pipeline + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ScopeLimitationControllerIntegrationLocalTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ScopeLimitationControllerIntegrationLocalTest.java new file mode 100644 index 0000000..df5cdd2 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ScopeLimitationControllerIntegrationLocalTest.java @@ -0,0 +1,24 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@ActiveProfiles("local") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/delete_data.sql") +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/delete_data.sql") +public class ScopeLimitationControllerIntegrationLocalTest + extends BaseScopeLimitiationControllerIntegrationTest { + + //this runs all tests in BaseScopeLimitiationControllerIntegrationTest, do not add anything here + //this is an easy way to run the tests if you have the containerised database running locally already + +} diff --git a/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ScopeLimitationControllerIntegrationTest.java b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ScopeLimitationControllerIntegrationTest.java new file mode 100644 index 0000000..5c1ae31 --- /dev/null +++ b/caab-service/src/integrationTest/java/uk/gov/laa/ccms/data/api/controller/ScopeLimitationControllerIntegrationTest.java @@ -0,0 +1,24 @@ +package uk.gov.laa.ccms.data.api.controller; + +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_METHOD; +import static org.springframework.test.context.jdbc.SqlMergeMode.MergeMode.MERGE; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlMergeMode; +import uk.gov.laa.ccms.caab.api.CaabApiApplication; +import uk.gov.laa.ccms.data.api.IntegrationTestInterface; + +@SpringBootTest(classes = CaabApiApplication.class) +@SqlMergeMode(MERGE) +@Sql(executionPhase = BEFORE_TEST_METHOD, scripts = "/sql/application_tables_create_schema.sql") +@Sql(executionPhase = AFTER_TEST_METHOD, scripts = "/sql/application_tables_drop_schema.sql") +public class ScopeLimitationControllerIntegrationTest + extends BaseScopeLimitiationControllerIntegrationTest + implements IntegrationTestInterface { + + //this runs all tests in BaseScopeLimitiationControllerIntegrationTest, do not add anything here + //running this class takes longer than the local version, but it is used for running tests in a pipeline + +} diff --git a/caab-service/src/integrationTest/resources/json/evidence_document_new.json b/caab-service/src/integrationTest/resources/json/evidence_document_new.json new file mode 100644 index 0000000..becbc27 --- /dev/null +++ b/caab-service/src/integrationTest/resources/json/evidence_document_new.json @@ -0,0 +1,22 @@ +{ + "application_or_outcome_id": "98765", + "case_reference_number": "caseref", + "provider_id": "provid", + "document_type": { + "id": "doctype", + "display_value": "doc type" + }, + "description": "a description", + "document_sender": "sender", + "file_name": "filename.ext", + "file_extension": "ext", + "file_data": "dGhlIGZpbGUgZGF0YQ==", + "transfer_status": "stat", + "transfer_response_code": "code", + "transfer_response_description": "the code", + "transfer_retry_count": "1", + "ccms_module": "A", + "evidence_descriptions": "evidence descriptions", + "registered_document_id": "regid", + "notification_reference": "notref" +} \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/sql/application_tables_create_schema.sql b/caab-service/src/integrationTest/resources/sql/application_tables_create_schema.sql index c9c913f..6a47117 100644 --- a/caab-service/src/integrationTest/resources/sql/application_tables_create_schema.sql +++ b/caab-service/src/integrationTest/resources/sql/application_tables_create_schema.sql @@ -304,5 +304,32 @@ CREATE INDEX "XXCCMS_APPLICATION_I2" ON "XXCCMS_APPLICATION" ("FK_COST_STRUCTURE +-- Evidence Documents +CREATE TABLE XXCCMS_EVIDENCE_DOCUMENTS ( + "ID" NUMBER(19, 0) NOT NULL, + "NOTIFICATION_REFERENCE" VARCHAR2(50 CHAR), + "PROVIDER_ID" VARCHAR2(19 CHAR) NOT NULL, + "CASE_ID" VARCHAR2(20 CHAR) NOT NULL, + "DOCUMENT_TYPE" VARCHAR2(50 CHAR) NOT NULL, + "FILE_EXTENSION" VARCHAR2(20 CHAR) NOT NULL, + "TYPE_DISPLAY_VALUE" VARCHAR2(50 CHAR) NOT NULL, + "DOCUMENT_SENDER" VARCHAR2(50 CHAR) NOT NULL, + "USER_FREE_TEXT" VARCHAR2(2000 CHAR), + "FILE_NAME" VARCHAR2(255 CHAR) NOT NULL, + "DOCUMENT" BLOB NOT NULL, + "TRANSFER_STATUS" VARCHAR2(20 CHAR), + "NO_OF_RETRIES_UNDERTAKEN" NUMBER(*, 0) DEFAULT 0 NOT NULL, + "WEBSERVICE_RESPONSE_CODE" VARCHAR2(500 CHAR), + "WEBSERVICE_RESPONSE_DESC" VARCHAR2(4000 CHAR), + "DATE_CREATED" DATE DEFAULT SYSDATE NOT NULL, + "USER_CREATED" VARCHAR2(50 CHAR) DEFAULT USER NOT NULL, + "DATE_MODIFIED" DATE, + "USER_MODIFIED" VARCHAR2(50 CHAR), + "DOCHANDLER_SESSION_ID" VARCHAR2(100 CHAR), + "CCMS_MODULE" CHAR(1 CHAR) DEFAULT 'A' NOT NULL, + "EVIDENCE_DOC_DESCS" VARCHAR2(4000 CHAR), + "REGISTERED_DOCUMENT_ID" VARCHAR2(50 BYTE), + PRIMARY KEY ("ID") +); diff --git a/caab-service/src/integrationTest/resources/sql/application_tables_drop_schema.sql b/caab-service/src/integrationTest/resources/sql/application_tables_drop_schema.sql index 82983da..f8d1cda 100644 --- a/caab-service/src/integrationTest/resources/sql/application_tables_drop_schema.sql +++ b/caab-service/src/integrationTest/resources/sql/application_tables_drop_schema.sql @@ -23,5 +23,7 @@ DROP TABLE XXCCMS_REFERENCE_DATA_ITEM; DROP TABLE XXCCMS_SCOPE_LIMITATION; DROP TABLE XXCCMS_CASE_OUTCOME; +DROP TABLE XXCCMS_EVIDENCE_DOCUMENTS; + -- drop sequence DROP SEQUENCE XXCCMS_GENERATED_ID_S; \ No newline at end of file diff --git a/caab-service/src/integrationTest/resources/sql/delete_data.sql b/caab-service/src/integrationTest/resources/sql/delete_data.sql index 65f24b0..f77ea54 100644 --- a/caab-service/src/integrationTest/resources/sql/delete_data.sql +++ b/caab-service/src/integrationTest/resources/sql/delete_data.sql @@ -24,3 +24,5 @@ DELETE FROM XXCCMS_APPLICATION; DELETE FROM XXCCMS_COST_STRUCTURE; -- Clear XXCCMS_ADDRESS DELETE FROM XXCCMS_ADDRESS; +-- Clear XXCCMS_EVIDENCE_DOCUMENTS; +DELETE FROM XXCCMS_EVIDENCE_DOCUMENTS; diff --git a/caab-service/src/integrationTest/resources/sql/evidence_document_insert.sql b/caab-service/src/integrationTest/resources/sql/evidence_document_insert.sql new file mode 100644 index 0000000..3f6a88c --- /dev/null +++ b/caab-service/src/integrationTest/resources/sql/evidence_document_insert.sql @@ -0,0 +1,55 @@ +insert into XXCCMS_EVIDENCE_DOCUMENTS ( + ID, + CASE_ID, + CCMS_MODULE, + DATE_CREATED, + DATE_MODIFIED, + DOCHANDLER_SESSION_ID, + DOCUMENT, + DOCUMENT_SENDER, + DOCUMENT_TYPE, + EVIDENCE_DOC_DESCS, + FILE_EXTENSION, + FILE_NAME, + NOTIFICATION_REFERENCE, + NO_OF_RETRIES_UNDERTAKEN, + PROVIDER_ID, + REGISTERED_DOCUMENT_ID, + TRANSFER_STATUS, + TYPE_DISPLAY_VALUE, + USER_CREATED, + USER_FREE_TEXT, + USER_MODIFIED, + WEBSERVICE_RESPONSE_CODE, + WEBSERVICE_RESPONSE_DESC +) values (3, 'caseref', 'B', SYSDATE, null, 'appId', TO_BLOB('23876238476'), 'test', 'doctype', 'description of evidence', 'pdf', + 'test.pdf', 'notref', 1, 'provid', '123', 'SUCCESS', 'doc type', + 'test', 'description', null, 'code', 'the code'); + +insert into XXCCMS_EVIDENCE_DOCUMENTS ( + ID, + CASE_ID, + CCMS_MODULE, + DATE_CREATED, + DATE_MODIFIED, + DOCHANDLER_SESSION_ID, + DOCUMENT, + DOCUMENT_SENDER, + DOCUMENT_TYPE, + EVIDENCE_DOC_DESCS, + FILE_EXTENSION, + FILE_NAME, + NOTIFICATION_REFERENCE, + NO_OF_RETRIES_UNDERTAKEN, + PROVIDER_ID, + REGISTERED_DOCUMENT_ID, + TRANSFER_STATUS, + TYPE_DISPLAY_VALUE, + USER_CREATED, + USER_FREE_TEXT, + USER_MODIFIED, + WEBSERVICE_RESPONSE_CODE, + WEBSERVICE_RESPONSE_DESC +) values (4, 'caseref', 'A', SYSDATE, null, 'appId', TO_BLOB('23876238476'), 'test', 'doctype', 'description of evidence', 'pdf', + 'test.pdf', 'notref', 1, 'provid', '123', 'SUCCESS', 'doc type', + 'test', 'description', null, 'code', 'the code'); \ No newline at end of file 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 4212728..420aa97 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,18 +11,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import uk.gov.laa.ccms.caab.api.ApplicationsApi; -import uk.gov.laa.ccms.caab.api.ClientsApi; -import uk.gov.laa.ccms.caab.api.LinkedCasesApi; -import uk.gov.laa.ccms.caab.api.OpponentsApi; -import uk.gov.laa.ccms.caab.api.PriorAuthoritiesApi; -import uk.gov.laa.ccms.caab.api.ProceedingsApi; -import uk.gov.laa.ccms.caab.api.ScopeLimitationsApi; import uk.gov.laa.ccms.caab.api.service.ApplicationService; -import uk.gov.laa.ccms.caab.api.service.LinkedCaseService; -import uk.gov.laa.ccms.caab.api.service.OpponentService; -import uk.gov.laa.ccms.caab.api.service.PriorAuthorityService; -import uk.gov.laa.ccms.caab.api.service.ProceedingService; -import uk.gov.laa.ccms.caab.api.service.ScopeLimitationService; import uk.gov.laa.ccms.caab.model.Address; import uk.gov.laa.ccms.caab.model.ApplicationDetail; import uk.gov.laa.ccms.caab.model.ApplicationDetails; @@ -34,7 +23,6 @@ import uk.gov.laa.ccms.caab.model.Opponent; import uk.gov.laa.ccms.caab.model.PriorAuthority; import uk.gov.laa.ccms.caab.model.Proceeding; -import uk.gov.laa.ccms.caab.model.ScopeLimitation; /** * Represents the main controller handling application-related requests. @@ -44,15 +32,9 @@ */ @RestController @RequiredArgsConstructor -public class ApplicationController implements ApplicationsApi, LinkedCasesApi, ProceedingsApi, - ScopeLimitationsApi, PriorAuthoritiesApi, ClientsApi, OpponentsApi { +public class ApplicationController implements ApplicationsApi { private final ApplicationService applicationService; - private final LinkedCaseService linkedCaseService; - private final ProceedingService proceedingService; - private final PriorAuthorityService priorAuthorityService; - private final ScopeLimitationService scopeLimitationService; - private final OpponentService opponentService; /** * Creates a new application and returns the URI of the created resource. @@ -283,38 +265,6 @@ public ResponseEntity addApplicationLinkedCase( return new ResponseEntity<>(HttpStatus.CREATED); } - /** - * Updates a linked case. - * - * @param linkedCaseId the unique identifier of the linked case - * @param caabUserLoginId the user login ID used for audit trail - * @param linkedCase the updated linked case - * @return a ResponseEntity with no content - */ - @Override - public ResponseEntity updateLinkedCase( - final Long linkedCaseId, - final String caabUserLoginId, - final LinkedCase linkedCase) { - linkedCaseService.updateLinkedCase(linkedCaseId, linkedCase); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - /** - * Removes a linked case from a specific application. - * - * @param linkedCaseId the unique identifier of the linked case - * @param caabUserLoginId the user login ID used for audit trail - * @return a ResponseEntity indicating the case was successfully removed - */ - @Override - public ResponseEntity removeLinkedCase( - final Long linkedCaseId, - final String caabUserLoginId) { - linkedCaseService.removeLinkedCase(linkedCaseId); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - //proceedings @Override @@ -333,59 +283,6 @@ public ResponseEntity> getApplicationProceedings( return new ResponseEntity<>(proceedings, HttpStatus.OK); } - @Override - public ResponseEntity removeProceeding( - final Long proceedingId, - final String caabUserLoginId) { - proceedingService.removeProceeding(proceedingId); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Override - public ResponseEntity updateProceeding( - final Long proceedingId, - final String caabUserLoginId, - final Proceeding proceeding) { - proceedingService.updateProceeding(proceedingId, proceeding); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - //scope limitations - - @Override - public ResponseEntity addProceedingScopeLimitation( - final Long proceedingId, - final String caabUserLoginId, - final ScopeLimitation scopeLimitation) { - proceedingService.createScopeLimitationForProceeding(proceedingId, scopeLimitation); - return new ResponseEntity<>(HttpStatus.CREATED); - } - - @Override - public ResponseEntity> getProceedingsScopeLimitations( - final Long proceedingId) { - List scopeLimitations = - proceedingService.getScopeLimitationsForProceeding(proceedingId); - return new ResponseEntity<>(scopeLimitations, HttpStatus.OK); - } - - @Override - public ResponseEntity removeScopeLimitation( - final Long scopeLimitationId, - final String caabUserLoginId) { - scopeLimitationService.removeScopeLimitation(scopeLimitationId); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Override - public ResponseEntity updateScopeLimitation( - final Long scopeLimitationId, - final String caabUserLoginId, - final ScopeLimitation scopeLimitation) { - scopeLimitationService.updateScopeLimitation(scopeLimitationId, scopeLimitation); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - //prior authorities @Override @@ -405,23 +302,6 @@ public ResponseEntity> getApplicationPriorAuthorities( return new ResponseEntity<>(priorAuthorities, HttpStatus.OK); } - @Override - public ResponseEntity removePriorAuthority( - final Long priorAuthorityId, - final String caabUserLoginId) { - priorAuthorityService.removePriorAuthority(priorAuthorityId); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Override - public ResponseEntity updatePriorAuthority( - final Long priorAuthorityId, - final String caabUserLoginId, - final PriorAuthority priorAuthority) { - priorAuthorityService.updatePriorAuthority(priorAuthorityId, priorAuthority); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - //clients @Override public ResponseEntity updateApplicationClient( @@ -445,18 +325,4 @@ public ResponseEntity addApplicationOpponent( applicationService.createOpponentForApplication(id, opponent); return new ResponseEntity<>(HttpStatus.CREATED); } - - @Override - public ResponseEntity updateOpponent( - final Long opponentId, final String caabUserLoginId, final Opponent opponent) { - opponentService.updateOpponent(opponentId, opponent); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - - @Override - public ResponseEntity removeOpponent( - final Long opponentId, final String caabUserLoginId) { - opponentService.removeOpponent(opponentId); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } } diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/EvidenceController.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/EvidenceController.java new file mode 100644 index 0000000..a80915a --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/EvidenceController.java @@ -0,0 +1,105 @@ +package uk.gov.laa.ccms.caab.api.controller; + + +import java.net.URI; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import uk.gov.laa.ccms.caab.api.EvidenceApi; +import uk.gov.laa.ccms.caab.api.service.EvidenceService; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetail; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetails; + +/** + * Controller handling evidence-related requests. + * Implements the {@code EvidenceApi} interface for standardized + * endpoint definitions and provides the necessary endpoints to manage + * and retrieve evidence data. + */ +@RestController +@RequiredArgsConstructor +public class EvidenceController implements EvidenceApi { + + private final EvidenceService evidenceService; + + @Override + public ResponseEntity getEvidenceDocuments( + final String applicationOrOutcomeId, + final String caseReferenceNumber, + final String providerId, + final String documentType, + final String transferStatus, + final String ccmsModule, + final Pageable pageable) { + + EvidenceDocumentDetails evidenceDocumentDetails = evidenceService.getEvidenceDocuments( + applicationOrOutcomeId, + caseReferenceNumber, + providerId, + documentType, + transferStatus, + ccmsModule, + pageable); + + return new ResponseEntity<>(evidenceDocumentDetails, HttpStatus.OK); + } + + @Override + public ResponseEntity getEvidenceDocument(final Long evidenceDocumentId) { + + EvidenceDocumentDetail evidenceDocumentDetail = + evidenceService.getEvidenceDocument(evidenceDocumentId); + + return new ResponseEntity<>(evidenceDocumentDetail, HttpStatus.OK); + } + + @Override + public ResponseEntity createEvidenceDocument( + final String caabUserLoginId, + final EvidenceDocumentDetail evidenceDocumentDetail) { + Long evidenceDocumentId = evidenceService.createEvidenceDocument(evidenceDocumentDetail); + + URI uri = ServletUriComponentsBuilder.fromCurrentRequest() + .path("/{id}") + .buildAndExpand(evidenceDocumentId) + .toUri(); + + HttpHeaders headers = new HttpHeaders(); + headers.setLocation(uri); + + return new ResponseEntity<>(headers, HttpStatus.CREATED); + } + + @Override + public ResponseEntity removeEvidenceDocument( + final Long evidenceDocumentId, final String caabUserLoginId) { + evidenceService.removeEvidenceDocument(evidenceDocumentId); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Override + public ResponseEntity removeEvidenceDocuments( + final String caabUserLoginId, + final String applicationOrOutcomeId, + final String caseReferenceNumber, + final String providerId, + final String documentType, + final String transferStatus, + final String ccmsModule) { + + evidenceService.removeEvidenceDocuments( + applicationOrOutcomeId, + caseReferenceNumber, + providerId, + documentType, + transferStatus, + ccmsModule); + + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/LinkedCaseController.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/LinkedCaseController.java new file mode 100644 index 0000000..7a6c482 --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/LinkedCaseController.java @@ -0,0 +1,55 @@ +package uk.gov.laa.ccms.caab.api.controller; + + +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.laa.ccms.caab.api.LinkedCasesApi; +import uk.gov.laa.ccms.caab.api.service.LinkedCaseService; +import uk.gov.laa.ccms.caab.model.LinkedCase; + +/** + * Controller handling linked case-related requests. + * Implements the {@code LinkedCasesApi} interface for standardized + * endpoint definitions and provides the necessary endpoints to manage + * and retrieve linked case data. + */ +@RestController +@RequiredArgsConstructor +public class LinkedCaseController implements LinkedCasesApi { + + private final LinkedCaseService linkedCaseService; + + /** + * Updates a linked case. + * + * @param linkedCaseId the unique identifier of the linked case + * @param caabUserLoginId the user login ID used for audit trail + * @param linkedCase the updated linked case + * @return a ResponseEntity with no content + */ + @Override + public ResponseEntity updateLinkedCase( + final Long linkedCaseId, + final String caabUserLoginId, + final LinkedCase linkedCase) { + linkedCaseService.updateLinkedCase(linkedCaseId, linkedCase); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + /** + * Removes a linked case from a specific application. + * + * @param linkedCaseId the unique identifier of the linked case + * @param caabUserLoginId the user login ID used for audit trail + * @return a ResponseEntity indicating the case was successfully removed + */ + @Override + public ResponseEntity removeLinkedCase( + final Long linkedCaseId, + final String caabUserLoginId) { + linkedCaseService.removeLinkedCase(linkedCaseId); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/OpponentController.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/OpponentController.java new file mode 100644 index 0000000..6426538 --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/OpponentController.java @@ -0,0 +1,37 @@ +package uk.gov.laa.ccms.caab.api.controller; + + +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.laa.ccms.caab.api.OpponentsApi; +import uk.gov.laa.ccms.caab.api.service.OpponentService; +import uk.gov.laa.ccms.caab.model.Opponent; + +/** + * Controller handling opponent-related requests. + * Implements the {@code OpponentsApi} interface for standardized + * endpoint definitions and provides the necessary endpoints to manage + * and retrieve opponent data. + */ +@RestController +@RequiredArgsConstructor +public class OpponentController implements OpponentsApi { + + private final OpponentService opponentService; + + @Override + public ResponseEntity updateOpponent( + final Long opponentId, final String caabUserLoginId, final Opponent opponent) { + opponentService.updateOpponent(opponentId, opponent); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Override + public ResponseEntity removeOpponent( + final Long opponentId, final String caabUserLoginId) { + opponentService.removeOpponent(opponentId); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/PriorAuthorityController.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/PriorAuthorityController.java new file mode 100644 index 0000000..9178160 --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/PriorAuthorityController.java @@ -0,0 +1,40 @@ +package uk.gov.laa.ccms.caab.api.controller; + + +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.laa.ccms.caab.api.PriorAuthoritiesApi; +import uk.gov.laa.ccms.caab.api.service.PriorAuthorityService; +import uk.gov.laa.ccms.caab.model.PriorAuthority; + +/** + * Controller handling prior authorities-related requests. + * Implements the {@code PriorAuthoritiesApi} interface for standardized + * endpoint definitions and provides the necessary endpoints to manage + * and retrieve prior authorities data. + */ +@RestController +@RequiredArgsConstructor +public class PriorAuthorityController implements PriorAuthoritiesApi { + + private final PriorAuthorityService priorAuthorityService; + + @Override + public ResponseEntity removePriorAuthority( + final Long priorAuthorityId, + final String caabUserLoginId) { + priorAuthorityService.removePriorAuthority(priorAuthorityId); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Override + public ResponseEntity updatePriorAuthority( + final Long priorAuthorityId, + final String caabUserLoginId, + final PriorAuthority priorAuthority) { + priorAuthorityService.updatePriorAuthority(priorAuthorityId, priorAuthority); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ProceedingController.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ProceedingController.java new file mode 100644 index 0000000..c542571 --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ProceedingController.java @@ -0,0 +1,59 @@ +package uk.gov.laa.ccms.caab.api.controller; + + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.laa.ccms.caab.api.ProceedingsApi; +import uk.gov.laa.ccms.caab.api.service.ProceedingService; +import uk.gov.laa.ccms.caab.model.Proceeding; +import uk.gov.laa.ccms.caab.model.ScopeLimitation; + +/** + * Controller handling proceedings-related requests. + * Implements the {@code ProceedingsApi} interface for standardized + * endpoint definitions and provides the necessary endpoints to manage + * and retrieve proceedings data. + */ +@RestController +@RequiredArgsConstructor +public class ProceedingController implements ProceedingsApi { + + private final ProceedingService proceedingService; + + @Override + public ResponseEntity removeProceeding( + final Long proceedingId, + final String caabUserLoginId) { + proceedingService.removeProceeding(proceedingId); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Override + public ResponseEntity updateProceeding( + final Long proceedingId, + final String caabUserLoginId, + final Proceeding proceeding) { + proceedingService.updateProceeding(proceedingId, proceeding); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Override + public ResponseEntity> getProceedingsScopeLimitations( + final Long proceedingId) { + List scopeLimitations = + proceedingService.getScopeLimitationsForProceeding(proceedingId); + return new ResponseEntity<>(scopeLimitations, HttpStatus.OK); + } + + @Override + public ResponseEntity addProceedingScopeLimitation( + final Long proceedingId, + final String caabUserLoginId, + final ScopeLimitation scopeLimitation) { + proceedingService.createScopeLimitationForProceeding(proceedingId, scopeLimitation); + return new ResponseEntity<>(HttpStatus.CREATED); + } +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ScopeLimitationController.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ScopeLimitationController.java new file mode 100644 index 0000000..2baa36a --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/controller/ScopeLimitationController.java @@ -0,0 +1,40 @@ +package uk.gov.laa.ccms.caab.api.controller; + + +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.laa.ccms.caab.api.ScopeLimitationsApi; +import uk.gov.laa.ccms.caab.api.service.ScopeLimitationService; +import uk.gov.laa.ccms.caab.model.ScopeLimitation; + +/** + * Controller handling scope limitation-related requests. + * Implements the {@code ScopeLimitationsApi} interface for standardized + * endpoint definitions and provides the necessary endpoints to manage + * and retrieve scope limitation data. + */ +@RestController +@RequiredArgsConstructor +public class ScopeLimitationController implements ScopeLimitationsApi { + + private final ScopeLimitationService scopeLimitationService; + + @Override + public ResponseEntity removeScopeLimitation( + final Long scopeLimitationId, + final String caabUserLoginId) { + scopeLimitationService.removeScopeLimitation(scopeLimitationId); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Override + public ResponseEntity updateScopeLimitation( + final Long scopeLimitationId, + final String caabUserLoginId, + final ScopeLimitation scopeLimitation) { + scopeLimitationService.updateScopeLimitation(scopeLimitationId, scopeLimitation); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/EvidenceDocument.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/EvidenceDocument.java new file mode 100644 index 0000000..0798d76 --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/entity/EvidenceDocument.java @@ -0,0 +1,174 @@ +package uk.gov.laa.ccms.caab.api.entity; + +import jakarta.persistence.AttributeOverride; +import jakarta.persistence.AttributeOverrides; +import jakarta.persistence.Column; +import jakarta.persistence.Embedded; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import java.io.Serializable; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + + +/** + * Represents an evidence document entity associated with the "XXCCMS_EVIDENCE_DOCUMENTS" table. + * + *

This entity is utilized to manage and persist evidence document data + * within the CCMS system. It makes use of the "XXCCMS_GENERATED_ID_S" + * sequence for generating unique identifiers.

+ */ +@Entity +@EntityListeners(AuditingEntityListener.class) +@Table(name = "XXCCMS_EVIDENCE_DOCUMENTS") +@SequenceGenerator( + allocationSize = 1, + sequenceName = "XXCCMS_GENERATED_ID_S", + name = "XXCCMS_EVIDENCE_DOCUMENTS_S") +@Getter +@Setter +@RequiredArgsConstructor +public class EvidenceDocument implements Serializable { + + /** + * The unique identifier for the EvidenceDocument. + */ + @Id + @GeneratedValue(generator = "XXCCMS_EVIDENCE_DOCUMENTS_S") + private Long id; + + /** + * The application or case outcome id to which this evidence relates. + * Originally a sessionid used by an external document handler. + */ + @Column(name = "DOCHANDLER_SESSION_ID") + private String applicationOrOutcomeId; + + /** + * The related case reference number. + */ + @Column(name = "CASE_ID", length = 20) + private String caseReferenceNumber; + + /** + * The related provider id. + */ + @Column(name = "PROVIDER_ID", length = 19) + private String providerId; + + /** + * The type of document. + */ + @Column(name = "DOCUMENT_TYPE", length = 50) + private String documentType; + + /** + * The display value for the document type. + */ + @Column(name = "TYPE_DISPLAY_VALUE", length = 50) + private String documentTypeDisplayValue; + + /** + * The description of the file. + */ + @Column(name = "USER_FREE_TEXT") + private String description; + + /** + * The document sender. + */ + @Column(name = "DOCUMENT_SENDER", length = 50) + private String documentSender; + + /** + * The document file name. + */ + @Column(name = "FILE_NAME") + private String fileName; + + /** + * The extension of the file. + * This is automatically populated via an INSERT trigger on XXCCMS_EVIDENCE_DOCUMENTS. + */ + @Column(name = "FILE_EXTENSION", length = 20) + private String fileExtension; + + /** + * The document file data. + */ + @Column(name = "DOCUMENT") + @Lob + private byte[] fileBytes; + + /** + * The status of the file transfer. + */ + @Column(name = "TRANSFER_STATUS") + private String transferStatus; + + /** + * The transfer response code. + */ + @Column(name = "WEBSERVICE_RESPONSE_CODE") + private String transferResponseCode; + + /** + * The transfer response description. + */ + @Column(name = "WEBSERVICE_RESPONSE_DESC") + private String transferResponseDescription; + + /** + * The number of attempts to transfer the file. + * Possibly legacy attribute from dochandler process. + */ + @Column(name = "NO_OF_RETRIES_UNDERTAKEN") + private Integer transferRetryCount; + + /** + * The CCMS Module to which this evidence document relates. + */ + @Column(name = "CCMS_MODULE") + private String ccmsModule; + + /** + * A delimited list of descriptions of the evidence represented by this document. + */ + @Column(name = "EVIDENCE_DOC_DESCS") + private String evidenceDescriptions; + + /** + * The pre-registered document id for this evidence. + */ + @Column(name = "REGISTERED_DOCUMENT_ID") + private String registeredDocumentId; + + /** + * The reference of the related notification, if relevant. + */ + @Column(name = "NOTIFICATION_REFERENCE") + private String notificationReference; + + /** + * The audit trail information. + */ + @Embedded + @AttributeOverrides({ + @AttributeOverride(name = "created", + column = @Column(name = "DATE_CREATED")), + @AttributeOverride(name = "createdBy", + column = @Column(name = "USER_CREATED")), + @AttributeOverride(name = "lastSaved", + column = @Column(name = "DATE_MODIFIED")), + @AttributeOverride(name = "lastSavedBy", + column = @Column(name = "USER_MODIFIED")) + }) + private AuditTrail auditTrail = new AuditTrail(); +} 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 new file mode 100644 index 0000000..a80b253 --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/mapper/EvidenceMapper.java @@ -0,0 +1,44 @@ +package uk.gov.laa.ccms.caab.api.mapper; + + +import java.util.Base64; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.springframework.data.domain.Page; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetail; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetails; + +/** + * Interface responsible for mapping and transforming objects related + * to the evidence domain. It bridges the gap between the data model + * and the service or API layers, ensuring consistent object translation. + */ + +@Mapper(componentModel = "spring", + uses = CommonMapper.class) +public interface EvidenceMapper { + + EvidenceDocumentDetails toEvidenceDocumentDetails( + final Page evidenceDocuments); + + @Mapping(target = "documentType.id", source = "documentType") + @Mapping(target = "documentType.displayValue", source = "documentTypeDisplayValue") + @Mapping(target = "fileData", source = "fileBytes") + EvidenceDocumentDetail toEvidenceDocumentDetail( + final uk.gov.laa.ccms.caab.api.entity.EvidenceDocument evidenceDocument); + + @InheritInverseConfiguration + @Mapping(target = "auditTrail", ignore = true) + uk.gov.laa.ccms.caab.api.entity.EvidenceDocument toEvidenceDocument( + final EvidenceDocumentDetail evidenceDocumentDetail); + + default String toBase64String(byte[] bytes) { + return bytes != null ? Base64.getEncoder().encodeToString(bytes) : null; + } + + default byte[] toByteArrayFromBase64EncodedString(String base64EncodedString) { + return Base64.getDecoder().decode(base64EncodedString); + } + +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/repository/EvidenceDocumentRepository.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/repository/EvidenceDocumentRepository.java new file mode 100644 index 0000000..c2e434f --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/repository/EvidenceDocumentRepository.java @@ -0,0 +1,18 @@ +package uk.gov.laa.ccms.caab.api.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import uk.gov.laa.ccms.caab.api.entity.EvidenceDocument; + +/** + * Repository interface for managing {@link EvidenceDocument} + * entities. + * + *

This interface provides CRUD (Create, Read, Update, Delete) operations + * for the {@link EvidenceDocument} entity, leveraging the power of + * Spring Data JPA. It automatically provides methods to save, find, and delete evidence documents, + * amongst other common operations found within + * {@link JpaRepository}.

+ */ +public interface EvidenceDocumentRepository extends JpaRepository { + +} diff --git a/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/EvidenceService.java b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/EvidenceService.java new file mode 100644 index 0000000..d697120 --- /dev/null +++ b/caab-service/src/main/java/uk/gov/laa/ccms/caab/api/service/EvidenceService.java @@ -0,0 +1,151 @@ +package uk.gov.laa.ccms.caab.api.service; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import uk.gov.laa.ccms.caab.api.entity.EvidenceDocument; +import uk.gov.laa.ccms.caab.api.exception.CaabApiException; +import uk.gov.laa.ccms.caab.api.mapper.EvidenceMapper; +import uk.gov.laa.ccms.caab.api.repository.EvidenceDocumentRepository; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetail; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetails; + +/** + * Service responsible for handling evidence document operations. + * + * @see EvidenceDocumentRepository + * @see EvidenceMapper + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class EvidenceService { + + private final EvidenceDocumentRepository repository; + private final EvidenceMapper mapper; + + /** + * Get a Page of EvidenceDocuments for the supplied search criteria. + * + * @param applicationOrOutcomeId - the application or outcome id. + * @param caseReferenceNumber - the case reference number. + * @param providerId - the provider id. + * @param documentType - the document type. + * @param transferStatus - the transfer status. + * @param ccmsModule - the ccms module. + * @param pageable - the pageable settings. + * @return EvidenceDocumentDetails wrapping a page of EvidenceDocuments. + */ + public EvidenceDocumentDetails getEvidenceDocuments(final String applicationOrOutcomeId, + final String caseReferenceNumber, + final String providerId, + final String documentType, + final String transferStatus, + final String ccmsModule, + final Pageable pageable) { + EvidenceDocument exampleDocument = buildExampleDocument( + applicationOrOutcomeId, + caseReferenceNumber, + providerId, + documentType, + transferStatus, + ccmsModule); + + return mapper.toEvidenceDocumentDetails(repository.findAll( + Example.of(exampleDocument), pageable)); + } + + /** + * Get a single EvidenceDocumentDetail by id. + * + * @param id - the evidence document id. + * @return EvidenceDocumentDetail with the matching id, or else an error. + */ + public EvidenceDocumentDetail getEvidenceDocument(final Long id) { + + return repository.findById(id) + .map(mapper::toEvidenceDocumentDetail) + .orElseThrow(() -> new CaabApiException( + String.format("Failed to find evidence with id: %s", id), + HttpStatus.NOT_FOUND)); + } + + /** + * Create a new EvidenceDocument entry. + * + * @param evidenceDocumentDetail - the evidence to create. + * @return the id of the newly created evidence document. + */ + public Long createEvidenceDocument(final EvidenceDocumentDetail evidenceDocumentDetail) { + uk.gov.laa.ccms.caab.api.entity.EvidenceDocument createdEvidenceDocument = + repository.save(mapper.toEvidenceDocument(evidenceDocumentDetail)); + + return createdEvidenceDocument.getId(); + } + + /** + * Removes an evidence document entry. + * If the evidence is not found, a CaabApiException is thrown. + * + * @param evidenceDocumentId The unique identifier of the evidence to be removed. + * @throws CaabApiException If the evidence with the specified ID is not found. + */ + @Transactional + public void removeEvidenceDocument(final Long evidenceDocumentId) { + if (repository.existsById(evidenceDocumentId)) { + repository.deleteById(evidenceDocumentId); + } else { + throw new CaabApiException( + String.format("EvidenceDocument with id: %s not found", evidenceDocumentId), + HttpStatus.NOT_FOUND); + } + } + + /** + * Remove all evidence documents which match the provided search criteria. + * + * @param applicationOrOutcomeId - the application or outcome id. + * @param caseReferenceNumber - the case reference number. + * @param providerId - the provider id. + * @param documentType - the document type. + * @param transferStatus - the transfer status. + * @param ccmsModule - the ccms module. + */ + @Transactional + public void removeEvidenceDocuments( + final String applicationOrOutcomeId, + final String caseReferenceNumber, + final String providerId, + final String documentType, + final String transferStatus, + final String ccmsModule) { + EvidenceDocument exampleDocument = buildExampleDocument( + applicationOrOutcomeId, + caseReferenceNumber, + providerId, + documentType, + transferStatus, + ccmsModule); + + repository.deleteAll(repository.findAll(Example.of(exampleDocument))); + } + + private static EvidenceDocument buildExampleDocument(String applicationOrOutcomeId, + String caseReferenceNumber, String providerId, String documentType, String transferStatus, + String ccmsModule) { + EvidenceDocument exampleDocument = + new EvidenceDocument(); + exampleDocument.setApplicationOrOutcomeId(applicationOrOutcomeId); + exampleDocument.setCaseReferenceNumber(caseReferenceNumber); + exampleDocument.setProviderId(providerId); + exampleDocument.setDocumentType(documentType); + exampleDocument.setTransferStatus(transferStatus); + exampleDocument.setCcmsModule(ccmsModule); + return exampleDocument; + } + +} 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 8cb7ab4..98b0bc1 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 @@ -5,7 +5,6 @@ import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -30,11 +29,6 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import uk.gov.laa.ccms.caab.api.service.ApplicationService; -import uk.gov.laa.ccms.caab.api.service.LinkedCaseService; -import uk.gov.laa.ccms.caab.api.service.OpponentService; -import uk.gov.laa.ccms.caab.api.service.PriorAuthorityService; -import uk.gov.laa.ccms.caab.api.service.ProceedingService; -import uk.gov.laa.ccms.caab.api.service.ScopeLimitationService; import uk.gov.laa.ccms.caab.model.Address; import uk.gov.laa.ccms.caab.model.ApplicationDetail; import uk.gov.laa.ccms.caab.model.ApplicationDetails; @@ -47,7 +41,6 @@ import uk.gov.laa.ccms.caab.model.Opponent; import uk.gov.laa.ccms.caab.model.PriorAuthority; import uk.gov.laa.ccms.caab.model.Proceeding; -import uk.gov.laa.ccms.caab.model.ScopeLimitation; import uk.gov.laa.ccms.caab.model.StringDisplayValue; @ExtendWith(SpringExtension.class) @@ -57,18 +50,6 @@ class ApplicationControllerTest { @Mock private ApplicationService applicationService; - @Mock - private LinkedCaseService linkedCaseService; - @Mock - private ProceedingService proceedingService; - @Mock - private PriorAuthorityService priorAuthorityService; - @Mock - private ScopeLimitationService scopeLimitationService; - @Mock - private OpponentService opponentService; - - @InjectMocks private ApplicationController applicationController; @@ -263,37 +244,6 @@ public void addApplicationLinkedCase_isCreated() throws Exception { verify(applicationService).createLinkedCaseForApplication(id, linkedCase); } - @Test - public void updateApplicationLinkedCase_noContent() throws Exception { - Long linkedCaseId = 2L; - String caabUserLoginId = "userLoginId"; - LinkedCase linkedCase = new LinkedCase(); // Set up updated linked case details as required - - doNothing().when(linkedCaseService).updateLinkedCase(linkedCaseId, linkedCase); - - this.mockMvc.perform(patch("/linked-cases/{linkedCaseId}", linkedCaseId) - .header("Caab-User-Login-Id", caabUserLoginId) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(linkedCase))) - .andExpect(status().isNoContent()); - - verify(linkedCaseService).updateLinkedCase(linkedCaseId, linkedCase); - } - - @Test - public void removeLinkedCase_noContent() throws Exception { - Long linkedCaseId = 2L; - String caabUserLoginId = "userLoginId"; - - doNothing().when(linkedCaseService).removeLinkedCase(linkedCaseId); - - this.mockMvc.perform(delete("/linked-cases/{linkedCaseId}", linkedCaseId) - .header("Caab-User-Login-Id", caabUserLoginId)) - .andExpect(status().isNoContent()); - - verify(linkedCaseService).removeLinkedCase(linkedCaseId); - } - @Test public void getApplications() throws Exception { String caseRef = "caseref"; @@ -398,36 +348,6 @@ public void getApplicationProceedings_ReturnsProceedingsList() throws Exception verify(applicationService).getProceedingsForApplication(applicationId); } - @Test - public void removeProceeding_RemovesProceeding() throws Exception { - Long proceedingId = 2L; - - doNothing().when(proceedingService).removeProceeding(proceedingId); - - this.mockMvc.perform(delete("/proceedings/{proceedingId}", proceedingId) - .header("Caab-User-Login-Id", caabUserLoginId)) - .andExpect(status().isNoContent()); - - verify(proceedingService).removeProceeding(proceedingId); - } - - @Test - public void updateProceeding_UpdatesProceeding() throws Exception { - Long proceedingId = 2L; - Proceeding proceeding = new Proceeding(); - - - doNothing().when(proceedingService).updateProceeding(proceedingId, proceeding); - - this.mockMvc.perform(patch("/proceedings/{proceeding-id}", proceedingId) - .contentType(MediaType.APPLICATION_JSON) - .header("Caab-User-Login-Id", caabUserLoginId) - .content(objectMapper.writeValueAsString(proceeding))) - .andExpect(status().isNoContent()); - - verify(proceedingService).updateProceeding(proceedingId, proceeding); - } - @Test public void addApplicationPriorAuthority_CreatesPriorAuthority() throws Exception { Long id = 1L; @@ -457,93 +377,6 @@ public void getApplicationPriorAuthorities_ReturnsPriorAuthoritiesList() throws verify(applicationService).getPriorAuthoritiesForApplication(id); } - @Test - public void removePriorAuthority_RemovesPriorAuthority() throws Exception { - Long priorAuthorityId = 2L; - - doNothing().when(priorAuthorityService).removePriorAuthority(priorAuthorityId); - - this.mockMvc.perform(delete("/prior-authorities/{priorAuthorityId}", priorAuthorityId) - .header("Caab-User-Login-Id", caabUserLoginId)) - .andExpect(status().isNoContent()); - - verify(priorAuthorityService).removePriorAuthority(priorAuthorityId); - } - - @Test - public void updatePriorAuthority_UpdatesPriorAuthority() throws Exception { - Long priorAuthorityId = 2L; - PriorAuthority priorAuthority = new PriorAuthority(); - - doNothing().when(priorAuthorityService).updatePriorAuthority(priorAuthorityId, priorAuthority); - - this.mockMvc.perform(patch("/prior-authorities/{priorAuthorityId}", priorAuthorityId) - .header("Caab-User-Login-Id", caabUserLoginId) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(priorAuthority))) - .andExpect(status().isNoContent()); - - verify(priorAuthorityService).updatePriorAuthority(priorAuthorityId, priorAuthority); - } - - @Test - public void addProceedingScopeLimitation_CreatesScopeLimitation() throws Exception { - Long proceedingId = 1L; - ScopeLimitation scopeLimitation = new ScopeLimitation(); - - doNothing().when(proceedingService).createScopeLimitationForProceeding(proceedingId, scopeLimitation); - - this.mockMvc.perform(post("/proceedings/{proceedingId}/scope-limitations", proceedingId) - .header("Caab-User-Login-Id", caabUserLoginId) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(scopeLimitation))) - .andExpect(status().isCreated()); - - verify(proceedingService).createScopeLimitationForProceeding(proceedingId, scopeLimitation); - } - - @Test - public void getApplicationScopeLimitations_ReturnsScopeLimitations() throws Exception { - Long proceedingId = 1L; - List scopeLimitations = List.of(new ScopeLimitation()); - - when(proceedingService.getScopeLimitationsForProceeding(proceedingId)).thenReturn(scopeLimitations); - - this.mockMvc.perform(get("/proceedings/{proceedingId}/scope-limitations", proceedingId)) - .andExpect(status().isOk()); - - verify(proceedingService).getScopeLimitationsForProceeding(proceedingId); - } - - @Test - public void removeScopeLimitation_RemovesScopeLimitation() throws Exception { - Long scopeLimitationId = 2L; - - doNothing().when(scopeLimitationService).removeScopeLimitation(scopeLimitationId); - - this.mockMvc.perform(delete("/scope-limitations/{scopeLimitationId}", scopeLimitationId) - .header("Caab-User-Login-Id", caabUserLoginId)) - .andExpect(status().isNoContent()); - - verify(scopeLimitationService).removeScopeLimitation(scopeLimitationId); - } - - @Test - public void updateScopeLimitation_UpdatesScopeLimitation() throws Exception { - Long scopeLimitationId = 2L; - ScopeLimitation scopeLimitation = new ScopeLimitation(); - - doNothing().when(scopeLimitationService).updateScopeLimitation(scopeLimitationId, scopeLimitation); - - this.mockMvc.perform(patch("/scope-limitations/{scopeLimitationId}", scopeLimitationId) - .header("Caab-User-Login-Id", caabUserLoginId) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(scopeLimitation))) - .andExpect(status().isNoContent()); - - verify(scopeLimitationService).updateScopeLimitation(scopeLimitationId, scopeLimitation); - } - @Test public void addApplicationOpponent_CreatesOpponent() throws Exception { Long applicationId = 1L; @@ -572,33 +405,4 @@ public void getApplicationOpponents_ReturnsOpponents() throws Exception { verify(applicationService).getOpponentsForApplication(applicationId); } - - @Test - public void removeOpponent_RemovesOpponent() throws Exception { - Long opponentId = 2L; - - doNothing().when(opponentService).removeOpponent(opponentId); - - this.mockMvc.perform(delete("/opponents/{opponentId}", opponentId) - .header("Caab-User-Login-Id", caabUserLoginId)) - .andExpect(status().isNoContent()); - - verify(opponentService).removeOpponent(opponentId); - } - - @Test - public void updateOpponent_UpdatesOpponent() throws Exception { - Long opponentId = 2L; - Opponent opponent = new Opponent(); - - doNothing().when(opponentService).updateOpponent(opponentId, opponent); - - this.mockMvc.perform(patch("/opponents/{opponentId}", opponentId) - .header("Caab-User-Login-Id", caabUserLoginId) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(opponent))) - .andExpect(status().isNoContent()); - - verify(opponentService).updateOpponent(opponentId, opponent); - } } \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/EvidenceControllerTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/EvidenceControllerTest.java new file mode 100644 index 0000000..e6a59dc --- /dev/null +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/EvidenceControllerTest.java @@ -0,0 +1,149 @@ +package uk.gov.laa.ccms.caab.api.controller; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; +import static uk.gov.laa.ccms.caab.api.util.ModelUtils.buildEvidenceDocumentDetail; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import uk.gov.laa.ccms.caab.api.service.EvidenceService; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetail; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetails; + +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +class EvidenceControllerTest { + + private final String caabUserLoginId = "userLoginId"; + @Mock + private EvidenceService evidenceService; + @InjectMocks + private EvidenceController evidenceController; + private MockMvc mockMvc; + private ObjectMapper objectMapper; + + @BeforeEach + public void setup() { + mockMvc = standaloneSetup(evidenceController).setCustomArgumentResolvers( + new PageableHandlerMethodArgumentResolver()).build(); + + objectMapper = new ObjectMapper(); + } + + @Test + public void removeEvidenceDocument_RemovesEntry() throws Exception { + Long evidenceDocumentId = 2L; + + doNothing().when(evidenceService).removeEvidenceDocument(evidenceDocumentId); + + this.mockMvc.perform( + delete("/evidence/{evidenceDocumentId}", evidenceDocumentId) + .header("Caab-User-Login-Id", caabUserLoginId)) + .andExpect(status().isNoContent()); + + verify(evidenceService).removeEvidenceDocument(evidenceDocumentId); + } + + @Test + public void getEvidenceDocuments_returnsCorrectly() throws Exception { + EvidenceDocumentDetail evidenceDocumentDetail = buildEvidenceDocumentDetail(); + + when( + evidenceService.getEvidenceDocuments(eq(evidenceDocumentDetail.getApplicationOrOutcomeId()), + eq(evidenceDocumentDetail.getCaseReferenceNumber()), + eq(evidenceDocumentDetail.getProviderId()), + eq(evidenceDocumentDetail.getDocumentType().getId()), + eq(evidenceDocumentDetail.getTransferStatus()), + eq(evidenceDocumentDetail.getCcmsModule()), any(Pageable.class))).thenReturn( + new EvidenceDocumentDetails()); + + this.mockMvc.perform(get("/evidence").param("application-or-outcome-id", + evidenceDocumentDetail.getApplicationOrOutcomeId()) + .param("case-reference-number", evidenceDocumentDetail.getCaseReferenceNumber()) + .param("provider-id", evidenceDocumentDetail.getProviderId()) + .param("document-type", evidenceDocumentDetail.getDocumentType().getId()) + .param("transfer-status", evidenceDocumentDetail.getTransferStatus()) + .param("ccms-module", evidenceDocumentDetail.getCcmsModule())).andDo(print()) + .andExpect(status().isOk()); + + verify(evidenceService).getEvidenceDocuments( + eq(evidenceDocumentDetail.getApplicationOrOutcomeId()), + eq(evidenceDocumentDetail.getCaseReferenceNumber()), + eq(evidenceDocumentDetail.getProviderId()), + eq(evidenceDocumentDetail.getDocumentType().getId()), + eq(evidenceDocumentDetail.getTransferStatus()), eq(evidenceDocumentDetail.getCcmsModule()), + any(Pageable.class)); + } + + @Test + public void getEvidenceDocument_returnsCorrectly() throws Exception { + EvidenceDocumentDetail evidenceDocumentDetail = buildEvidenceDocumentDetail(); + + when( + evidenceService.getEvidenceDocument(evidenceDocumentDetail.getId().longValue())).thenReturn( + new EvidenceDocumentDetail()); + + this.mockMvc.perform( + get("/evidence/{evidence-document-id}", evidenceDocumentDetail.getId().longValue())) + .andDo(print()).andExpect(status().isOk()); + + verify(evidenceService).getEvidenceDocument(evidenceDocumentDetail.getId().longValue()); + } + + @Test + public void createEvidenceDocument_isCreated() throws Exception { + EvidenceDocumentDetail evidenceDocumentDetail = buildEvidenceDocumentDetail(); + + when(evidenceService.createEvidenceDocument(evidenceDocumentDetail)).thenReturn( + evidenceDocumentDetail.getId().longValue()); + + this.mockMvc.perform(post("/evidence").header("Caab-User-Login-Id", caabUserLoginId) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(evidenceDocumentDetail))) + .andExpect(status().isCreated()).andExpect( + header().string("Location", "http://localhost/evidence/" + evidenceDocumentDetail.getId())); + } + + @Test + public void removeEvidenceDocuments_callsServiceMethod() throws Exception { + EvidenceDocumentDetail evidenceDocumentDetail = buildEvidenceDocumentDetail(); + + this.mockMvc.perform(delete("/evidence") + .header("Caab-User-Login-Id", caabUserLoginId) + .param("application-or-outcome-id", evidenceDocumentDetail.getApplicationOrOutcomeId()) + .param("case-reference-number", evidenceDocumentDetail.getCaseReferenceNumber()) + .param("provider-id", evidenceDocumentDetail.getProviderId()) + .param("document-type", evidenceDocumentDetail.getDocumentType().getId()) + .param("transfer-status", evidenceDocumentDetail.getTransferStatus()) + .param("ccms-module", evidenceDocumentDetail.getCcmsModule())).andDo(print()) + .andExpect(status().isNoContent()); + + verify(evidenceService).removeEvidenceDocuments( + evidenceDocumentDetail.getApplicationOrOutcomeId(), + evidenceDocumentDetail.getCaseReferenceNumber(), + evidenceDocumentDetail.getProviderId(), + evidenceDocumentDetail.getDocumentType().getId(), + evidenceDocumentDetail.getTransferStatus(), + evidenceDocumentDetail.getCcmsModule()); + } +} \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/LinkedCaseControllerTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/LinkedCaseControllerTest.java new file mode 100644 index 0000000..58e7d8b --- /dev/null +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/LinkedCaseControllerTest.java @@ -0,0 +1,76 @@ +package uk.gov.laa.ccms.caab.api.controller; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.verify; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import uk.gov.laa.ccms.caab.api.service.LinkedCaseService; +import uk.gov.laa.ccms.caab.model.LinkedCase; + +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +class LinkedCaseControllerTest { + + @Mock + private LinkedCaseService linkedCaseService; + + @InjectMocks + private LinkedCaseController linkedCaseController; + + private MockMvc mockMvc; + + private ObjectMapper objectMapper; + + private final String caabUserLoginId = "userLoginId"; + + @BeforeEach + public void setup() { + mockMvc = standaloneSetup(linkedCaseController) + .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) + .build(); + objectMapper = new ObjectMapper(); + } + + @Test + public void updateLinkedCase_noContent() throws Exception { + Long linkedCaseId = 2L; + LinkedCase linkedCase = new LinkedCase(); // Set up updated linked case details as required + + doNothing().when(linkedCaseService).updateLinkedCase(linkedCaseId, linkedCase); + + this.mockMvc.perform(patch("/linked-cases/{linkedCaseId}", linkedCaseId) + .header("Caab-User-Login-Id", caabUserLoginId) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(linkedCase))) + .andExpect(status().isNoContent()); + + verify(linkedCaseService).updateLinkedCase(linkedCaseId, linkedCase); + } + + @Test + public void removeLinkedCase_noContent() throws Exception { + Long linkedCaseId = 2L; + + doNothing().when(linkedCaseService).removeLinkedCase(linkedCaseId); + + this.mockMvc.perform(delete("/linked-cases/{linkedCaseId}", linkedCaseId) + .header("Caab-User-Login-Id", caabUserLoginId)) + .andExpect(status().isNoContent()); + + verify(linkedCaseService).removeLinkedCase(linkedCaseId); + } +} \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/OpponentControllerTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/OpponentControllerTest.java new file mode 100644 index 0000000..10e9ee4 --- /dev/null +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/OpponentControllerTest.java @@ -0,0 +1,76 @@ +package uk.gov.laa.ccms.caab.api.controller; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.verify; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import uk.gov.laa.ccms.caab.api.service.OpponentService; +import uk.gov.laa.ccms.caab.model.Opponent; + +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +class OpponentControllerTest { + @Mock + private OpponentService opponentService; + + + @InjectMocks + private OpponentController opponentController; + + private MockMvc mockMvc; + + private ObjectMapper objectMapper; + + private final String caabUserLoginId = "userLoginId"; + + @BeforeEach + public void setup() { + mockMvc = standaloneSetup(opponentController) + .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) + .build(); + objectMapper = new ObjectMapper(); + } + + @Test + public void removeOpponent_RemovesOpponent() throws Exception { + Long opponentId = 2L; + + doNothing().when(opponentService).removeOpponent(opponentId); + + this.mockMvc.perform(delete("/opponents/{opponentId}", opponentId) + .header("Caab-User-Login-Id", caabUserLoginId)) + .andExpect(status().isNoContent()); + + verify(opponentService).removeOpponent(opponentId); + } + + @Test + public void updateOpponent_UpdatesOpponent() throws Exception { + Long opponentId = 2L; + Opponent opponent = new Opponent(); + + doNothing().when(opponentService).updateOpponent(opponentId, opponent); + + this.mockMvc.perform(patch("/opponents/{opponentId}", opponentId) + .header("Caab-User-Login-Id", caabUserLoginId) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(opponent))) + .andExpect(status().isNoContent()); + + verify(opponentService).updateOpponent(opponentId, opponent); + } +} \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/PriorAuthorityControllerTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/PriorAuthorityControllerTest.java new file mode 100644 index 0000000..864254f --- /dev/null +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/PriorAuthorityControllerTest.java @@ -0,0 +1,76 @@ +package uk.gov.laa.ccms.caab.api.controller; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.verify; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import uk.gov.laa.ccms.caab.api.service.PriorAuthorityService; +import uk.gov.laa.ccms.caab.model.PriorAuthority; + +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +class PriorAuthorityControllerTest { + @Mock + private PriorAuthorityService priorAuthorityService; + + @InjectMocks + private PriorAuthorityController priorAuthorityController; + + private MockMvc mockMvc; + + private ObjectMapper objectMapper; + + private final String caabUserLoginId = "userLoginId"; + + @BeforeEach + public void setup() { + mockMvc = standaloneSetup(priorAuthorityController) + .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) + .build(); + objectMapper = new ObjectMapper(); + } + + @Test + public void removePriorAuthority_RemovesPriorAuthority() throws Exception { + Long priorAuthorityId = 2L; + + doNothing().when(priorAuthorityService).removePriorAuthority(priorAuthorityId); + + this.mockMvc.perform(delete("/prior-authorities/{priorAuthorityId}", priorAuthorityId) + .header("Caab-User-Login-Id", caabUserLoginId)) + .andExpect(status().isNoContent()); + + verify(priorAuthorityService).removePriorAuthority(priorAuthorityId); + } + + @Test + public void updatePriorAuthority_UpdatesPriorAuthority() throws Exception { + Long priorAuthorityId = 2L; + PriorAuthority priorAuthority = new PriorAuthority(); + + doNothing().when(priorAuthorityService).updatePriorAuthority(priorAuthorityId, priorAuthority); + + this.mockMvc.perform(patch("/prior-authorities/{priorAuthorityId}", priorAuthorityId) + .header("Caab-User-Login-Id", caabUserLoginId) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(priorAuthority))) + .andExpect(status().isNoContent()); + + verify(priorAuthorityService).updatePriorAuthority(priorAuthorityId, priorAuthority); + } + +} \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ProceedingControllerTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ProceedingControllerTest.java new file mode 100644 index 0000000..25ec032 --- /dev/null +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ProceedingControllerTest.java @@ -0,0 +1,111 @@ +package uk.gov.laa.ccms.caab.api.controller; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import uk.gov.laa.ccms.caab.api.service.ProceedingService; +import uk.gov.laa.ccms.caab.model.Proceeding; +import uk.gov.laa.ccms.caab.model.ScopeLimitation; + +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +class ProceedingControllerTest { + + @Mock + private ProceedingService proceedingService; + + @InjectMocks + private ProceedingController proceedingController; + + private MockMvc mockMvc; + + private ObjectMapper objectMapper; + + private final String caabUserLoginId = "userLoginId"; + + @BeforeEach + public void setup() { + mockMvc = standaloneSetup(proceedingController) + .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) + .build(); + objectMapper = new ObjectMapper(); + } + + @Test + public void removeProceeding_RemovesProceeding() throws Exception { + Long proceedingId = 2L; + + doNothing().when(proceedingService).removeProceeding(proceedingId); + + this.mockMvc.perform(delete("/proceedings/{proceedingId}", proceedingId) + .header("Caab-User-Login-Id", caabUserLoginId)) + .andExpect(status().isNoContent()); + + verify(proceedingService).removeProceeding(proceedingId); + } + + @Test + public void updateProceeding_UpdatesProceeding() throws Exception { + Long proceedingId = 2L; + Proceeding proceeding = new Proceeding(); + + + doNothing().when(proceedingService).updateProceeding(proceedingId, proceeding); + + this.mockMvc.perform(patch("/proceedings/{proceeding-id}", proceedingId) + .contentType(MediaType.APPLICATION_JSON) + .header("Caab-User-Login-Id", caabUserLoginId) + .content(objectMapper.writeValueAsString(proceeding))) + .andExpect(status().isNoContent()); + + verify(proceedingService).updateProceeding(proceedingId, proceeding); + } + + @Test + public void addProceedingScopeLimitation_CreatesScopeLimitation() throws Exception { + Long proceedingId = 1L; + ScopeLimitation scopeLimitation = new ScopeLimitation(); + + doNothing().when(proceedingService).createScopeLimitationForProceeding(proceedingId, scopeLimitation); + + this.mockMvc.perform(post("/proceedings/{proceedingId}/scope-limitations", proceedingId) + .header("Caab-User-Login-Id", caabUserLoginId) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(scopeLimitation))) + .andExpect(status().isCreated()); + + verify(proceedingService).createScopeLimitationForProceeding(proceedingId, scopeLimitation); + } + + @Test + public void getApplicationScopeLimitations_ReturnsScopeLimitations() throws Exception { + Long proceedingId = 1L; + List scopeLimitations = List.of(new ScopeLimitation()); + + when(proceedingService.getScopeLimitationsForProceeding(proceedingId)).thenReturn(scopeLimitations); + + this.mockMvc.perform(get("/proceedings/{proceedingId}/scope-limitations", proceedingId)) + .andExpect(status().isOk()); + + verify(proceedingService).getScopeLimitationsForProceeding(proceedingId); + } +} \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ScopeLimitationControllerTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ScopeLimitationControllerTest.java new file mode 100644 index 0000000..75067e9 --- /dev/null +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/controller/ScopeLimitationControllerTest.java @@ -0,0 +1,75 @@ +package uk.gov.laa.ccms.caab.api.controller; + +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.verify; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import uk.gov.laa.ccms.caab.api.service.ScopeLimitationService; +import uk.gov.laa.ccms.caab.model.ScopeLimitation; + +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +class ScopeLimitationControllerTest { + @Mock + private ScopeLimitationService scopeLimitationService; + + @InjectMocks + private ScopeLimitationController scopeLimitationController; + + private MockMvc mockMvc; + + private ObjectMapper objectMapper; + + private final String caabUserLoginId = "userLoginId"; + + @BeforeEach + public void setup() { + mockMvc = standaloneSetup(scopeLimitationController) + .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver()) + .build(); + objectMapper = new ObjectMapper(); + } + + @Test + public void removeScopeLimitation_RemovesScopeLimitation() throws Exception { + Long scopeLimitationId = 2L; + + doNothing().when(scopeLimitationService).removeScopeLimitation(scopeLimitationId); + + this.mockMvc.perform(delete("/scope-limitations/{scopeLimitationId}", scopeLimitationId) + .header("Caab-User-Login-Id", caabUserLoginId)) + .andExpect(status().isNoContent()); + + verify(scopeLimitationService).removeScopeLimitation(scopeLimitationId); + } + + @Test + public void updateScopeLimitation_UpdatesScopeLimitation() throws Exception { + Long scopeLimitationId = 2L; + ScopeLimitation scopeLimitation = new ScopeLimitation(); + + doNothing().when(scopeLimitationService).updateScopeLimitation(scopeLimitationId, scopeLimitation); + + this.mockMvc.perform(patch("/scope-limitations/{scopeLimitationId}", scopeLimitationId) + .header("Caab-User-Login-Id", caabUserLoginId) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(scopeLimitation))) + .andExpect(status().isNoContent()); + + verify(scopeLimitationService).updateScopeLimitation(scopeLimitationId, scopeLimitation); + } +} \ No newline at end of file diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/EvidenceMapperTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/EvidenceMapperTest.java new file mode 100644 index 0000000..3b9152d --- /dev/null +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/mapper/EvidenceMapperTest.java @@ -0,0 +1,112 @@ +package uk.gov.laa.ccms.caab.api.mapper; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static uk.gov.laa.ccms.caab.api.util.ModelUtils.buildEvidenceDocument; +import static uk.gov.laa.ccms.caab.api.util.ModelUtils.buildEvidenceDocumentDetail; + +import java.text.ParseException; +import java.util.Base64; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import uk.gov.laa.ccms.caab.api.entity.EvidenceDocument; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetail; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetails; + +@ExtendWith(MockitoExtension.class) +public class EvidenceMapperTest { + @InjectMocks + private final EvidenceMapper mapper = new EvidenceMapperImpl(); + + @BeforeEach + public void setup() throws ParseException { + } + + @Test + public void testToEvidenceDocumentDetails_null() { + EvidenceDocumentDetails evidenceDocumentDetails = mapper.toEvidenceDocumentDetails(null); + assertNull(evidenceDocumentDetails); + } + + @Test + public void testToEvidenceDocumentDetails() { + Page evidenceDocuments = new PageImpl<>(List.of(new EvidenceDocument())); + + EvidenceDocumentDetails result = mapper.toEvidenceDocumentDetails(evidenceDocuments); + + assertNotNull(result); + assertNotNull(result.getContent()); + assertEquals(1, result.getContent().size()); + } + + @Test + public void testToEvidenceDocumentDetail() { + // Construct EvidenceDocument + EvidenceDocument evidenceDocument = buildEvidenceDocument(); + + // Convert EvidenceDocument to EvidenceDocumentDetail + EvidenceDocumentDetail result = mapper.toEvidenceDocumentDetail(evidenceDocument); + + assertNotNull(result); + assertEquals(evidenceDocument.getApplicationOrOutcomeId(), result.getApplicationOrOutcomeId()); + assertNotNull(result.getAuditTrail()); + assertEquals(evidenceDocument.getCaseReferenceNumber(), result.getCaseReferenceNumber()); + assertEquals(evidenceDocument.getCcmsModule(), result.getCcmsModule()); + assertEquals(evidenceDocument.getDescription(), result.getDescription()); + assertEquals(evidenceDocument.getDocumentSender(), result.getDocumentSender()); + assertEquals(evidenceDocument.getDocumentType(), result.getDocumentType().getId()); + assertEquals(evidenceDocument.getDocumentTypeDisplayValue(), result.getDocumentType().getDisplayValue()); + assertEquals(evidenceDocument.getEvidenceDescriptions(), result.getEvidenceDescriptions()); + assertEquals(Base64.getEncoder().encodeToString(evidenceDocument.getFileBytes()), result.getFileData()); + assertEquals(evidenceDocument.getFileExtension(), result.getFileExtension()); + assertEquals(evidenceDocument.getFileName(), result.getFileName()); + assertEquals(evidenceDocument.getId().intValue(), result.getId()); + assertEquals(evidenceDocument.getNotificationReference(), result.getNotificationReference()); + assertEquals(evidenceDocument.getProviderId(), result.getProviderId()); + assertEquals(evidenceDocument.getRegisteredDocumentId(), result.getRegisteredDocumentId()); + assertEquals(evidenceDocument.getTransferResponseCode(), result.getTransferResponseCode()); + assertEquals(evidenceDocument.getTransferResponseDescription(), result.getTransferResponseDescription()); + assertEquals(evidenceDocument.getTransferRetryCount(), result.getTransferRetryCount()); + assertEquals(evidenceDocument.getTransferStatus(), result.getTransferStatus()); + } + + @Test + public void testToEvidenceDocument() { + // Construct EvidenceDocumentDetail + EvidenceDocumentDetail evidenceDocumentDetail = buildEvidenceDocumentDetail(); + + // Convert EvidenceDocumentDetail to EvidenceDocument + EvidenceDocument result = mapper.toEvidenceDocument(evidenceDocumentDetail); + + assertNotNull(result); + assertEquals(evidenceDocumentDetail.getApplicationOrOutcomeId(), result.getApplicationOrOutcomeId()); + assertNotNull(result.getAuditTrail()); + assertEquals(evidenceDocumentDetail.getCaseReferenceNumber(), result.getCaseReferenceNumber()); + assertEquals(evidenceDocumentDetail.getCcmsModule(), result.getCcmsModule()); + assertEquals(evidenceDocumentDetail.getDescription(), result.getDescription()); + assertEquals(evidenceDocumentDetail.getDocumentSender(), result.getDocumentSender()); + assertEquals(evidenceDocumentDetail.getDocumentType().getId(), result.getDocumentType()); + assertEquals(evidenceDocumentDetail.getDocumentType().getDisplayValue(), result.getDocumentTypeDisplayValue()); + assertEquals(evidenceDocumentDetail.getEvidenceDescriptions(), result.getEvidenceDescriptions()); + assertArrayEquals(Base64.getDecoder().decode(evidenceDocumentDetail.getFileData()), result.getFileBytes()); + assertEquals(evidenceDocumentDetail.getFileExtension(), result.getFileExtension()); + assertEquals(evidenceDocumentDetail.getFileName(), result.getFileName()); + assertEquals(evidenceDocumentDetail.getId().intValue(), result.getId()); + assertEquals(evidenceDocumentDetail.getNotificationReference(), result.getNotificationReference()); + assertEquals(evidenceDocumentDetail.getProviderId(), result.getProviderId()); + assertEquals(evidenceDocumentDetail.getRegisteredDocumentId(), result.getRegisteredDocumentId()); + assertEquals(evidenceDocumentDetail.getTransferResponseCode(), result.getTransferResponseCode()); + assertEquals(evidenceDocumentDetail.getTransferResponseDescription(), result.getTransferResponseDescription()); + assertEquals(evidenceDocumentDetail.getTransferRetryCount(), result.getTransferRetryCount()); + assertEquals(evidenceDocumentDetail.getTransferStatus(), result.getTransferStatus()); + } + +} diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/EvidenceServiceTest.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/EvidenceServiceTest.java new file mode 100644 index 0000000..452c88f --- /dev/null +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/service/EvidenceServiceTest.java @@ -0,0 +1,188 @@ +package uk.gov.laa.ccms.caab.api.service; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static uk.gov.laa.ccms.caab.api.util.ModelUtils.buildEvidenceDocument; +import static uk.gov.laa.ccms.caab.api.util.ModelUtils.buildEvidenceDocumentDetail; + +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import uk.gov.laa.ccms.caab.api.entity.EvidenceDocument; +import uk.gov.laa.ccms.caab.api.exception.CaabApiException; +import uk.gov.laa.ccms.caab.api.mapper.EvidenceMapper; +import uk.gov.laa.ccms.caab.api.repository.EvidenceDocumentRepository; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetail; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetails; + +@ExtendWith(MockitoExtension.class) +class EvidenceServiceTest { + @Mock + private EvidenceDocumentRepository repository; + + @Mock + private EvidenceMapper mapper; + + @InjectMocks + private EvidenceService evidenceService; + + @Test + void createEvidence_createsEvidenceDocument() { + EvidenceDocumentDetail evidenceDocumentDetail = new EvidenceDocumentDetail(); + EvidenceDocument evidenceDocument = buildEvidenceDocument(); + + when(mapper.toEvidenceDocument(evidenceDocumentDetail)).thenReturn(evidenceDocument); + when(repository.save(evidenceDocument)).thenReturn(evidenceDocument); + + Long result = evidenceService.createEvidenceDocument(evidenceDocumentDetail); + + assertNotNull(result); + assertEquals(evidenceDocument.getId(), result); + + verify(mapper).toEvidenceDocument(evidenceDocumentDetail); + verify(repository).save(evidenceDocument); + } + + @Test + void getEvidenceDocumentDetails_queriesBasedOnExample() { + EvidenceDocument evidenceDocument = new EvidenceDocument(); + evidenceDocument.setApplicationOrOutcomeId("appOutId"); + evidenceDocument.setCaseReferenceNumber("caseRef"); + evidenceDocument.setProviderId("provId"); + evidenceDocument.setDocumentType("docType"); + evidenceDocument.setTransferStatus("status"); + evidenceDocument.setCcmsModule("module"); + + EvidenceDocumentDetails expectedResponse = new EvidenceDocumentDetails(); + + Page evidenceDocumentPage = new PageImpl<>( + List.of(buildEvidenceDocument())); + + final ArgumentCaptor> exampleArgumentCaptor = + ArgumentCaptor.forClass(Example.class); + + when(repository.findAll(exampleArgumentCaptor.capture(), eq(Pageable.unpaged()))).thenReturn(evidenceDocumentPage); + when(mapper.toEvidenceDocumentDetails(evidenceDocumentPage)).thenReturn(expectedResponse); + + EvidenceDocumentDetails result = evidenceService.getEvidenceDocuments( + evidenceDocument.getApplicationOrOutcomeId(), + evidenceDocument.getCaseReferenceNumber(), + evidenceDocument.getProviderId(), + evidenceDocument.getDocumentType(), + evidenceDocument.getTransferStatus(), + evidenceDocument.getCcmsModule(), + Pageable.unpaged()); + + assertNotNull(result); + assertEquals(expectedResponse, result); + + verify(repository).findAll(any(Example.class), eq(Pageable.unpaged())); + verify(mapper).toEvidenceDocumentDetails(evidenceDocumentPage); + + // Check that the example EvidenceDocument was initialised based on the method params. + checkExampleDocument(evidenceDocument, exampleArgumentCaptor.getValue().getProbe()); + } + + @Test + void getEvidenceDocumentDetail_retrievesCorrectly() { + EvidenceDocumentDetail evidenceDocumentDetail = buildEvidenceDocumentDetail(); + + EvidenceDocument evidenceDocument = buildEvidenceDocument(); + + when(repository.findById(evidenceDocumentDetail.getId().longValue())).thenReturn(Optional.of(evidenceDocument)); + when(mapper.toEvidenceDocumentDetail(evidenceDocument)).thenReturn(evidenceDocumentDetail); + + EvidenceDocumentDetail result = evidenceService.getEvidenceDocument(evidenceDocumentDetail.getId().longValue()); + + assertNotNull(result); + assertEquals(evidenceDocumentDetail, result); + + verify(repository).findById(evidenceDocumentDetail.getId().longValue()); + verify(mapper).toEvidenceDocumentDetail(evidenceDocument); + } + + @Test + void removeEvidenceDocument_whenExists_removesEntry() { + Long evidenceDocumentId = 1L; + when(repository.existsById(evidenceDocumentId)).thenReturn(true); + doNothing().when(repository).deleteById(evidenceDocumentId); + + evidenceService.removeEvidenceDocument(evidenceDocumentId); + + verify(repository).existsById(evidenceDocumentId); + verify(repository).deleteById(evidenceDocumentId); + } + + @Test + void removeEvidenceDocument_whenNotExists_throwsException() { + Long evidenceDocumentId = 1L; + when(repository.existsById(evidenceDocumentId)).thenReturn(false); + + CaabApiException exception = assertThrows(CaabApiException.class, () -> + evidenceService.removeEvidenceDocument(evidenceDocumentId)); + + assertEquals("EvidenceDocument with id: 1 not found", exception.getMessage()); + assertEquals(HttpStatus.NOT_FOUND, exception.getHttpStatus()); + } + + @Test + void removeEvidenceDocumentDetails_deletesBasedOnExample() { + EvidenceDocument evidenceDocument = new EvidenceDocument(); + evidenceDocument.setApplicationOrOutcomeId("appOutId"); + evidenceDocument.setCaseReferenceNumber("caseRef"); + evidenceDocument.setProviderId("provId"); + evidenceDocument.setDocumentType("docType"); + evidenceDocument.setTransferStatus("status"); + evidenceDocument.setCcmsModule("module"); + + List evidenceDocuments = + List.of(buildEvidenceDocument()); + + final ArgumentCaptor> exampleArgumentCaptor = + ArgumentCaptor.forClass(Example.class); + + when(repository.findAll(exampleArgumentCaptor.capture())).thenReturn(evidenceDocuments); + + evidenceService.removeEvidenceDocuments( + evidenceDocument.getApplicationOrOutcomeId(), + evidenceDocument.getCaseReferenceNumber(), + evidenceDocument.getProviderId(), + evidenceDocument.getDocumentType(), + evidenceDocument.getTransferStatus(), + evidenceDocument.getCcmsModule()); + + verify(repository).findAll(any(Example.class)); + verify(repository).deleteAll(evidenceDocuments); + + // Check that the example EvidenceDocument was initialised based on the method params. + checkExampleDocument(evidenceDocument, exampleArgumentCaptor.getValue().getProbe()); + } + + private static void checkExampleDocument(EvidenceDocument evidenceDocument, + EvidenceDocument exampleDocument) { + assertEquals(evidenceDocument.getApplicationOrOutcomeId(), exampleDocument.getApplicationOrOutcomeId()); + assertEquals(evidenceDocument.getCaseReferenceNumber(), exampleDocument.getCaseReferenceNumber()); + assertEquals(evidenceDocument.getProviderId(), exampleDocument.getProviderId()); + assertEquals(evidenceDocument.getDocumentType(), exampleDocument.getDocumentType()); + assertEquals(evidenceDocument.getTransferStatus(), exampleDocument.getTransferStatus()); + assertEquals(evidenceDocument.getCcmsModule(), exampleDocument.getCcmsModule()); + } + +} + diff --git a/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/util/ModelUtils.java b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/util/ModelUtils.java new file mode 100644 index 0000000..3eb8d3b --- /dev/null +++ b/caab-service/src/test/java/uk/gov/laa/ccms/caab/api/util/ModelUtils.java @@ -0,0 +1,87 @@ +package uk.gov.laa.ccms.caab.api.util; + +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.util.Base64; +import java.util.Date; +import uk.gov.laa.ccms.caab.api.entity.AuditTrail; +import uk.gov.laa.ccms.caab.api.entity.EvidenceDocument; +import uk.gov.laa.ccms.caab.model.AuditDetail; +import uk.gov.laa.ccms.caab.model.EvidenceDocumentDetail; +import uk.gov.laa.ccms.caab.model.StringDisplayValue; + +public class ModelUtils { + public static EvidenceDocument buildEvidenceDocument() { + EvidenceDocument evidenceDocument = new EvidenceDocument(); + evidenceDocument.setApplicationOrOutcomeId("appOutId"); + evidenceDocument.setAuditTrail(buildAuditTrail()); + evidenceDocument.setCaseReferenceNumber("caseref"); + evidenceDocument.setCcmsModule("module"); + evidenceDocument.setDescription("descr"); + evidenceDocument.setDocumentSender("docsend"); + evidenceDocument.setDocumentType("doctype"); + evidenceDocument.setDocumentTypeDisplayValue("doc type"); + evidenceDocument.setEvidenceDescriptions("evidence descr"); + evidenceDocument.setFileBytes("the file data".getBytes()); + evidenceDocument.setFileExtension("ext"); + evidenceDocument.setFileName("name"); + evidenceDocument.setId(123L); + evidenceDocument.setNotificationReference("notref"); + evidenceDocument.setProviderId("provId"); + evidenceDocument.setRegisteredDocumentId("regDocId"); + evidenceDocument.setTransferResponseCode("code"); + evidenceDocument.setTransferResponseDescription("the code"); + evidenceDocument.setTransferRetryCount(10); + evidenceDocument.setTransferStatus("stat"); + + return evidenceDocument; + } + + public static EvidenceDocumentDetail buildEvidenceDocumentDetail() { + return new EvidenceDocumentDetail() + .applicationOrOutcomeId("appOutId") + .auditTrail(buildAuditDetail()) + .caseReferenceNumber("caseref") + .ccmsModule("module") + .description("descr") + .documentSender("docsend") + .documentType(new StringDisplayValue() + .id("doctype") + .displayValue("doc type")) + .evidenceDescriptions("evidence descr") + .fileData(Base64.getEncoder().encodeToString("the file data".getBytes())) + .fileExtension("ext") + .fileName("name") + .id(123) + .notificationReference("notref") + .providerId("provId") + .registeredDocumentId("regDocId") + .transferResponseCode("code") + .transferResponseDescription("the code") + .transferRetryCount(10) + .transferStatus("stat"); + } + + public static AuditDetail buildAuditDetail() { + AuditDetail auditDetail = new AuditDetail(); + // Ensure a difference between created and last saved dates + auditDetail.setCreated( + Date.from(LocalDate.of(2000, 1, 1).atStartOfDay() + .toInstant(ZoneOffset.UTC))); + auditDetail.setCreatedBy("CreatedBy"); + auditDetail.setLastSaved(new Date()); + auditDetail.setLastSavedBy("LastSavedBy"); + return auditDetail; + } + + public static AuditTrail buildAuditTrail() { + AuditTrail auditTrail = new AuditTrail(); + auditTrail.setCreated(Date.from(LocalDate.of(2000, 1, 1).atStartOfDay() + .toInstant(ZoneOffset.UTC))); + auditTrail.setCreatedBy("CreatedBy"); + auditTrail.setLastSaved(new Date()); + auditTrail.setLastSavedBy("LastSavedBy"); + return auditTrail; + } + +}