From 9e927978cca0b1291aee86255314fcee124d33d8 Mon Sep 17 00:00:00 2001 From: kaanaktas Date: Wed, 18 Dec 2024 13:28:40 +0000 Subject: [PATCH] add integration tests --- .../uk/gov/hmcts/ccd/WireMockBaseTest.java | 2 +- .../endpoint/std/CaseDetailsEndpointIT.java | 414 ++++++++++++ ...ase-definition-cu-permission-filtered.json | 612 ++++++++++++++++++ src/test/resources/sql/insert_cases.sql | 94 +++ 4 files changed, 1121 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/mappings/bookcase-definition-cu-permission-filtered.json diff --git a/src/test/java/uk/gov/hmcts/ccd/WireMockBaseTest.java b/src/test/java/uk/gov/hmcts/ccd/WireMockBaseTest.java index 5d88508928..2bb1170136 100644 --- a/src/test/java/uk/gov/hmcts/ccd/WireMockBaseTest.java +++ b/src/test/java/uk/gov/hmcts/ccd/WireMockBaseTest.java @@ -67,7 +67,7 @@ public abstract class WireMockBaseTest extends AbstractBaseIntegrationTest { public static final String CASE_01_TYPE = "TestAddressBookCase"; public static final String CASE_02_TYPE = "TestAddressBookCase"; public static final String CASE_03_TYPE = "TestAddressBookCase"; - public static final int NUMBER_OF_CASES = 23; + public static final int NUMBER_OF_CASES = 25; public static final JSONObject responseJson1 = new JSONObject(""" { "user_task": { diff --git a/src/test/java/uk/gov/hmcts/ccd/endpoint/std/CaseDetailsEndpointIT.java b/src/test/java/uk/gov/hmcts/ccd/endpoint/std/CaseDetailsEndpointIT.java index 8f39f546f3..3942836008 100644 --- a/src/test/java/uk/gov/hmcts/ccd/endpoint/std/CaseDetailsEndpointIT.java +++ b/src/test/java/uk/gov/hmcts/ccd/endpoint/std/CaseDetailsEndpointIT.java @@ -1,5 +1,9 @@ package uk.gov.hmcts.ccd.endpoint.std; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -13,6 +17,7 @@ import org.mockito.MockitoAnnotations; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; +import org.slf4j.LoggerFactory; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.http.MediaType; import org.springframework.jdbc.core.BeanPropertyRowMapper; @@ -46,6 +51,7 @@ import uk.gov.hmcts.ccd.domain.model.std.CaseDataContent; import uk.gov.hmcts.ccd.domain.model.std.Event; import uk.gov.hmcts.ccd.domain.model.std.MessageQueueCandidate; +import uk.gov.hmcts.ccd.domain.service.common.RestrictedFieldProcessor; import javax.inject.Inject; import java.nio.charset.StandardCharsets; @@ -65,6 +71,7 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; @@ -104,6 +111,7 @@ public class CaseDetailsEndpointIT extends WireMockBaseTest { private static final String UPLOAD_TIMESTAMP = "2000-02-29T00:00:00.000000000"; private static final JsonNodeFactory JSON_NODE_FACTORY = new JsonNodeFactory(false); private static final String CASE_TYPE = "TestAddressBookCase"; + private static final String CASE_TYPE_FILTERED = "TestAddressBookCaseFiltered"; private static final String CASE_TYPE_VALIDATE = "TestAddressBookCaseValidate"; private static final String CASE_TYPE_VALIDATE_MULTI_PAGE = "TestAddressBookCaseValidateMultiPage"; private static final String CASE_TYPE_NO_CREATE_CASE_ACCESS = "TestAddressBookCaseNoCreateCaseAccess"; @@ -5596,6 +5604,412 @@ public void shouldReturn201CaseCreatedButNotInsertCaseLinkInDBWhenCaseLinkIsBLan assertCaseLinks(expectedCaseId, Collections.emptyList()); } + private Logger logger; + private ListAppender listAppender; + private List loggingEventList; + + private Logger setupLogging() { + listAppender = new ListAppender<>(); + listAppender.start(); + logger = (Logger) LoggerFactory.getLogger(RestrictedFieldProcessor.class); + logger.detachAndStopAllAppenders(); + if (loggingEventList != null && !loggingEventList.isEmpty()) { + loggingEventList.clear(); + } + logger.addAppender(listAppender); + return logger; + } + + @Test + @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_cases.sql"}) + public void shouldNotPerformActionWhenFieldsMissingAndReadFalseCreateTrueMismatch() throws Exception { + final String caseReference = "1504259907353529"; + final String URL = + "/caseworkers/" + UID + "/jurisdictions/" + JURISDICTION + "/case-types/" + CASE_TYPE + + "/cases/" + caseReference + "/events"; + final CaseDataContent caseDetailsToSave = newCaseDataContent().build(); + caseDetailsToSave.setEvent(createEvent(PRE_STATES_EVENT_ID, SUMMARY, DESCRIPTION)); + + final JsonNode sanitizedData = mapper.readTree( + "{" + + "\"PersonAddress\":{" + + "\"Country\":\"_ Wales\"," + + "\"Postcode\":\"W11 5DF\"," + + "\"AddressLine1\":\"_ Flat 9\"," + + "\"AddressLine3\":\"_ ButtonVillie\"}," + + "\"PersonLastName\":\"_ Roof\"," + + "\"PersonFirstName\":\"_ George\"," + + "\"D8Document\":{" + + " \"document_url\": \"http://localhost:" + getPort() + + "/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d0\"," + + " \"document_binary_url\": \"http://localhost:[port]/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d0" + + "/binary\"," + + " \"document_filename\": \"Seagulls_Square.jpg\"" + + "}" + + "}"); + + final JsonNode data = mapper.readTree(createExampleEventDataWithMissingItems()); + caseDetailsToSave.setData(JacksonUtils.convertValue(data)); + final String expectedClassificationString = "{" + + " \"PersonAddress\":{" + + " \"classification\": \"PUBLIC\"," + + " \"value\": {" + + " \"Country\":\"PUBLIC\"," + + " \"Postcode\":\"PUBLIC\"," + + " \"AddressLine1\":\"PUBLIC\"," + + " \"AddressLine3\":\"PUBLIC\"" + + " }" + + " }," + + " \"PersonLastName\":\"PUBLIC\"," + + " \"PersonFirstName\":\"PUBLIC\"," + + " \"D8Document\": \"PUBLIC\"" + + "}"; + final String token = generateEventToken(template, + UID, JURISDICTION, CASE_TYPE, caseReference, PRE_STATES_EVENT_ID); + caseDetailsToSave.setToken(token); + + final Level logLevel = Level.DEBUG; + setupLogging().setLevel(logLevel); + + final MvcResult mvcResult = mockMvc.perform(post(URL) + .contentType(JSON_CONTENT_TYPE) + .content(mapper.writeValueAsBytes(caseDetailsToSave)) + ).andExpect(status().is(201)) + .andReturn(); + + final String expectedLogMessage = "Missing field 'AddressLine2' under 'PersonAddress'."; + loggingEventList = listAppender.list; + + assertTrue("Expected log message not found: " + expectedLogMessage, + loggingEventList.stream().anyMatch(log -> log.getLevel() == logLevel + && log.getFormattedMessage().equals(expectedLogMessage))); + assertEqualsSanitizedData(sanitizedData, mvcResult); + + final List caseDetailsList = template.query("SELECT * FROM case_data", this::mapCaseData); + assertEquals("Incorrect number of cases: No case should be created", NUMBER_OF_CASES, caseDetailsList.size()); + + final CaseDetails savedCaseDetails = caseDetailsList.stream() + .filter(c -> caseReference.equals(c.getReference().toString())) + .findFirst() + .orElse(null); + assertNotNull(savedCaseDetails); + assertEquals("Incorrect Case Type", CASE_TYPE, savedCaseDetails.getCaseTypeId()); + Map sanitizedDataMap = JacksonUtils.convertValue(sanitizedData); + assertThat( + "Incorrect Data content: Data should have changed", + savedCaseDetails.getData().entrySet(), + containsInAnyOrder(sanitizedDataMap.entrySet().toArray()) + ); + assertEquals("State should have been updated", "state4", savedCaseDetails.getState()); + JSONAssert.assertEquals(expectedClassificationString, + mapper.convertValue(savedCaseDetails.getDataClassification(), JsonNode.class).toString(), JSONCompareMode + .LENIENT); + + final List caseAuditEventList = template.query("SELECT * FROM case_event", this::mapAuditEvent); + assertEquals("A new event should have been created", 6, caseAuditEventList.size()); + + // Assertion belows are for creation event + final AuditEvent caseAuditEvent = caseAuditEventList.getLast(); + assertAll( + () -> assertEquals(sanitizedDataMap, caseAuditEvent.getData()), + () -> assertEquals("123", caseAuditEvent.getUserId()), + () -> assertEquals("Strife", caseAuditEvent.getUserLastName()), + () -> assertEquals("Cloud", caseAuditEvent.getUserFirstName()), + () -> assertEquals("HAS PRE STATES EVENT", caseAuditEvent.getEventName()), + () -> assertEquals(savedCaseDetails.getId(), caseAuditEvent.getCaseDataId()), + () -> assertEquals(savedCaseDetails.getCaseTypeId(), caseAuditEvent.getCaseTypeId()), + () -> assertEquals(1, caseAuditEvent.getCaseTypeVersion().intValue()), + () -> assertEquals(savedCaseDetails.getState(), caseAuditEvent.getStateId()), + () -> assertEquals("Case in state 4", caseAuditEvent.getStateName()), + () -> assertEquals(savedCaseDetails.getData(), caseAuditEvent.getData()), + () -> assertEquals(SUMMARY, caseAuditEvent.getSummary()), + () -> assertEquals(DESCRIPTION, caseAuditEvent.getDescription()), + () -> JSONAssert.assertEquals(expectedClassificationString, + mapper.convertValue(caseAuditEvent.getDataClassification(), JsonNode.class).toString(), + JSONCompareMode.LENIENT) + ); + } + + @Test + @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_cases.sql"}) + public void shouldAddMissingFieldsBackToDataWhenReadFalseCreateTrueMatch() throws Exception { + final String caseReference = "1202264432028419"; + final String URL = + "/caseworkers/" + UID + "/jurisdictions/" + JURISDICTION + "/case-types/" + CASE_TYPE_FILTERED + + "/cases/" + caseReference + "/events"; + final CaseDataContent caseDetailsToSave = newCaseDataContent().build(); + caseDetailsToSave.setEvent(createEvent(PRE_STATES_EVENT_ID, SUMMARY, DESCRIPTION)); + + final JsonNode sanitizedData = mapper.readTree( + "{" + + "\"PersonAddress\":{" + + "\"Country\":\"_ Wales\"," + + "\"Postcode\":\"W11 5DF\"," + + "\"AddressLine1\":\"_ Flat 9\"," + + "\"AddressLine2\":\"Fake Street\"," + + "\"AddressLine3\":\"_ ButtonVillie\"}," + + "\"PersonLastName\":\"_ Roof\"," + + "\"PersonFirstName\":\"_ George\"," + + "\"D8Document\":{" + + " \"document_url\": \"http://localhost:" + getPort() + + "/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d0\"," + + " \"document_binary_url\": \"http://localhost:[port]/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d0" + + "/binary\"," + + " \"document_filename\": \"Seagulls_Square.jpg\"" + + "}" + + "}"); + + final JsonNode data = mapper.readTree(createExampleEventDataWithMissingItems()); + caseDetailsToSave.setData(JacksonUtils.convertValue(data)); + final String expectedClassificationString = "{" + + " \"PersonAddress\":{" + + " \"classification\": \"PUBLIC\"," + + " \"value\": {" + + " \"Country\":\"PUBLIC\"," + + " \"Postcode\":\"PUBLIC\"," + + " \"AddressLine1\":\"PUBLIC\"," + + " \"AddressLine3\":\"PUBLIC\"" + + " }" + + " }," + + " \"PersonLastName\":\"PUBLIC\"," + + " \"PersonFirstName\":\"PUBLIC\"," + + " \"D8Document\": \"PUBLIC\"" + + "}"; + final String token = generateEventToken(template, + UID, JURISDICTION, CASE_TYPE_FILTERED, caseReference, PRE_STATES_EVENT_ID); + caseDetailsToSave.setToken(token); + + final Level logLevel = Level.INFO; + setupLogging().setLevel(logLevel); + + final MvcResult mvcResult = mockMvc.perform(post(URL) + .contentType(JSON_CONTENT_TYPE) + .content(mapper.writeValueAsBytes(caseDetailsToSave)) + ).andExpect(status().is(201)) + .andReturn(); + + assertNotNull(mvcResult); + + final String expectedLogMessage = "Adding missing field 'AddressLine2' under 'PersonAddress'."; + loggingEventList = listAppender.list; + + assertTrue("Expected log message not found: " + expectedLogMessage, + loggingEventList.stream().anyMatch(log -> log.getLevel() == logLevel + && log.getFormattedMessage().equals(expectedLogMessage))); + + final List caseDetailsList = template.query("SELECT * FROM case_data", this::mapCaseData); + assertEquals("Incorrect number of cases: No case should be created", NUMBER_OF_CASES, caseDetailsList.size()); + + final CaseDetails savedCaseDetails = caseDetailsList.stream() + .filter(c -> caseReference.equals(c.getReference().toString())) + .findFirst() + .orElse(null); + assertNotNull(savedCaseDetails); + assertEquals("Incorrect Case Type", CASE_TYPE_FILTERED, savedCaseDetails.getCaseTypeId()); + Map sanitizedDataMap = JacksonUtils.convertValue(sanitizedData); + assertThat( + "Incorrect Data content: Data should have changed", + savedCaseDetails.getData().entrySet(), + containsInAnyOrder(sanitizedDataMap.entrySet().toArray()) + ); + assertEquals("State should have been updated", "state4", savedCaseDetails.getState()); + JSONAssert.assertEquals(expectedClassificationString, + mapper.convertValue(savedCaseDetails.getDataClassification(), JsonNode.class).toString(), JSONCompareMode + .LENIENT); + + final List caseAuditEventList = template.query("SELECT * FROM case_event", this::mapAuditEvent); + assertEquals("A new event should have been created", 6, caseAuditEventList.size()); + + final AuditEvent caseAuditEvent = caseAuditEventList.getLast(); + assertAll( + () -> assertEquals(sanitizedDataMap, caseAuditEvent.getData()), + () -> assertEquals("123", caseAuditEvent.getUserId()), + () -> assertEquals("Strife", caseAuditEvent.getUserLastName()), + () -> assertEquals("Cloud", caseAuditEvent.getUserFirstName()), + () -> assertEquals("HAS PRE STATES EVENT", caseAuditEvent.getEventName()), + () -> assertEquals(savedCaseDetails.getId(), caseAuditEvent.getCaseDataId()), + () -> assertEquals(savedCaseDetails.getCaseTypeId(), caseAuditEvent.getCaseTypeId()), + () -> assertEquals(1, caseAuditEvent.getCaseTypeVersion().intValue()), + () -> assertEquals(savedCaseDetails.getState(), caseAuditEvent.getStateId()), + () -> assertEquals("Case in state 4", caseAuditEvent.getStateName()), + () -> assertEquals(savedCaseDetails.getData(), caseAuditEvent.getData()), + () -> assertEquals(SUMMARY, caseAuditEvent.getSummary()), + () -> assertEquals(DESCRIPTION, caseAuditEvent.getDescription()), + () -> JSONAssert.assertEquals(expectedClassificationString, + mapper.convertValue(caseAuditEvent.getDataClassification(), JsonNode.class).toString(), + JSONCompareMode.LENIENT) + ); + } + + @Test + @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_cases.sql"}) + public void shouldAddMissingCollectionFieldsBackToDataWhenReadFalseCreateTrueMatch() throws Exception { + final String caseReference = "6512245793128983"; + final String URL = + "/caseworkers/" + UID + "/jurisdictions/" + JURISDICTION + "/case-types/" + CASE_TYPE_FILTERED + + "/cases/" + caseReference + "/events"; + final CaseDataContent caseDetailsToSave = newCaseDataContent().build(); + caseDetailsToSave.setEvent(createEvent(PRE_STATES_EVENT_ID, SUMMARY, DESCRIPTION)); + + final JsonNode sanitizedData = mapper.readTree( + "{" + + "\"PersonAddress\":{" + + "\"Country\":\"_ Wales\"," + + "\"Postcode\":\"W11 5DF\"," + + "\"AddressLine1\":\"_ Flat 9\"," + + "\"AddressLine2\":\"Fake Street\"," + + "\"AddressLine3\":\"_ ButtonVillie\"}," + + "\"Aliases\":[" + + "{\"id\":\"2\",\"value\":\"Alias2\"}," + + "{\"id\":\"1\",\"value\":\"Alias1\"}," + + "{\"id\":\"3\",\"value\":\"Alias3\"}" + + "]," + + "\"PersonLastName\":\"_ Roof\"," + + "\"PersonFirstName\":\"_ George\"," + + "\"D8Document\":{" + + " \"document_url\": \"http://localhost:" + getPort() + + "/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d0\"," + + " \"document_binary_url\": \"http://localhost:[port]/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d0" + + "/binary\"," + + " \"document_filename\": \"Seagulls_Square.jpg\"" + + "}" + + "}"); + + final JsonNode data = mapper.readTree(createExampleEventDataWithCollectionMissingItems()); + caseDetailsToSave.setData(JacksonUtils.convertValue(data)); + final String expectedClassificationString = "{" + + " \"PersonAddress\":{" + + " \"classification\": \"PUBLIC\"," + + " \"value\": {" + + " \"Country\":\"PUBLIC\"," + + " \"Postcode\":\"PUBLIC\"," + + " \"AddressLine1\":\"PUBLIC\"," + + " \"AddressLine3\":\"PUBLIC\"" + + " }" + + " }," + + " \"PersonLastName\":\"PUBLIC\"," + + " \"PersonFirstName\":\"PUBLIC\"," + + " \"D8Document\": \"PUBLIC\"" + + "}"; + final String token = generateEventToken(template, + UID, JURISDICTION, CASE_TYPE_FILTERED, caseReference, PRE_STATES_EVENT_ID); + caseDetailsToSave.setToken(token); + + final Level logLevel = Level.INFO; + + setupLogging().setLevel(logLevel); + + final MvcResult mvcResult = mockMvc.perform(post(URL) + .contentType(JSON_CONTENT_TYPE) + .content(mapper.writeValueAsBytes(caseDetailsToSave)) + ).andExpect(status().is(201)) + .andReturn(); + + assertNotNull(mvcResult); + + final List expectedLogMessages = List.of( + "Adding missing field 'AddressLine2' under 'PersonAddress'.", + "Adding missing collection item with ID '\"1\"' under 'Aliases'.", + "Adding missing collection item with ID '\"3\"' under 'Aliases'."); + loggingEventList = listAppender.list; + List actualLogMessages = loggingEventList.stream() + .filter(log -> log.getLevel() == logLevel) + .map(ILoggingEvent::getFormattedMessage) + .toList(); + + List missingMessages = expectedLogMessages.stream() + .filter(expected -> !actualLogMessages.contains(expected)) + .toList(); + assertTrue( + "The following expected log messages were not found: " + missingMessages, + missingMessages.isEmpty() + ); + List unexpectedMessages = actualLogMessages.stream() + .filter(actual -> !expectedLogMessages.contains(actual)) + .toList(); + assertTrue( + "The following unexpected log messages were found: " + unexpectedMessages, + unexpectedMessages.isEmpty() + ); + + final List caseDetailsList = template.query("SELECT * FROM case_data", this::mapCaseData); + assertEquals("Incorrect number of cases: No case should be created", NUMBER_OF_CASES, caseDetailsList.size()); + + final CaseDetails savedCaseDetails = caseDetailsList.stream() + .filter(c -> caseReference.equals(c.getReference().toString())) + .findFirst() + .orElse(null); + assertNotNull(savedCaseDetails); + assertEquals("Incorrect Case Type", CASE_TYPE_FILTERED, savedCaseDetails.getCaseTypeId()); + Map sanitizedDataMap = JacksonUtils.convertValue(sanitizedData); + assertThat( + "Incorrect Data content: Data should have changed", + savedCaseDetails.getData().entrySet(), + containsInAnyOrder(sanitizedDataMap.entrySet().toArray()) + ); + assertEquals("State should have been updated", "state4", savedCaseDetails.getState()); + JSONAssert.assertEquals(expectedClassificationString, + mapper.convertValue(savedCaseDetails.getDataClassification(), JsonNode.class).toString(), JSONCompareMode + .LENIENT); + + final List caseAuditEventList = template.query("SELECT * FROM case_event", this::mapAuditEvent); + assertEquals("A new event should have been created", 6, caseAuditEventList.size()); + + final AuditEvent caseAuditEvent = caseAuditEventList.getLast(); + assertAll( + () -> assertEquals(sanitizedDataMap, caseAuditEvent.getData()), + () -> assertEquals("123", caseAuditEvent.getUserId()), + () -> assertEquals("Cloud", caseAuditEvent.getUserFirstName()), + () -> assertEquals("HAS PRE STATES EVENT", caseAuditEvent.getEventName()), + () -> assertEquals(savedCaseDetails.getId(), caseAuditEvent.getCaseDataId()), + () -> assertEquals(savedCaseDetails.getCaseTypeId(), caseAuditEvent.getCaseTypeId()), + () -> assertEquals(1, caseAuditEvent.getCaseTypeVersion().intValue()), + () -> assertEquals(savedCaseDetails.getState(), caseAuditEvent.getStateId()), + () -> assertEquals("Case in state 4", caseAuditEvent.getStateName()), + () -> assertEquals(savedCaseDetails.getData(), caseAuditEvent.getData()), + () -> assertEquals(SUMMARY, caseAuditEvent.getSummary()), + () -> assertEquals(DESCRIPTION, caseAuditEvent.getDescription()), + () -> JSONAssert.assertEquals(expectedClassificationString, + mapper.convertValue(caseAuditEvent.getDataClassification(), JsonNode.class).toString(), + JSONCompareMode.LENIENT) + ); + } + + private String createExampleEventDataWithMissingItems() { + return "{" + + "\"PersonAddress\":{" + + "\"Country\":\"_ Wales\"," + + "\"Postcode\":\"W11 5DF\"," + + "\"AddressLine1\":\"_ Flat 9\"," + + "\"AddressLine3\":\"_ ButtonVillie\"}," + + "\"PersonLastName\":\"_ Roof\"," + + "\"PersonFirstName\":\"_ George\"," + + "\"D8Document\":{" + + "\"document_url\": \"http://localhost:" + getPort() + + "/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d0\"" + + "}" + + "}"; + } + + private String createExampleEventDataWithCollectionMissingItems() { + return "{" + + "\"PersonAddress\":{" + + "\"Country\":\"_ Wales\"," + + "\"Postcode\":\"W11 5DF\"," + + "\"AddressLine1\":\"_ Flat 9\"," + + "\"AddressLine3\":\"_ ButtonVillie\"}," + + "\"PersonLastName\":\"_ Roof\"," + + "\"PersonFirstName\":\"_ George\"," + + "\"Aliases\":[" + + "{\"id\":\"2\",\"value\":\"Alias2\"}" + + "]," + + "\"D8Document\":{" + + "\"document_url\": \"http://localhost:" + getPort() + + "/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d0\"" + + "}" + + "}"; + } + private void assertCaseLinks(Long expectedCaseId, List expectedCaseLinks) { List caseLinks = template.query( String.format("SELECT * FROM case_link where case_id=%s", expectedCaseId), diff --git a/src/test/resources/mappings/bookcase-definition-cu-permission-filtered.json b/src/test/resources/mappings/bookcase-definition-cu-permission-filtered.json new file mode 100644 index 0000000000..141083c5c6 --- /dev/null +++ b/src/test/resources/mappings/bookcase-definition-cu-permission-filtered.json @@ -0,0 +1,612 @@ +{ + "request": { + "method": "GET", + "url": "/api/data/case-type/TestAddressBookCaseFiltered" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "jsonBody": { + "id": "TestAddressBookCaseFiltered", + "version": { + "number": 1, + "live_from": "2017-01-01" + }, + "name": "Test Address Book Case", + "description": "Test Address Book Case", + "jurisdiction": { + "id": "PROBATE", + "name": "Test", + "description": "Test Jurisdiction" + }, + "security_classification": "PUBLIC", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "caseworker-probate-private", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "caseworker-test-public", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "citizen", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "role-citizen", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "basic-profile", + "create": false, + "read": true, + "update": false, + "delete": false + } + ], + "roleToAccessProfiles": [ + { + "case_type_id": "TestAddressBookCaseFiltered", + "disabled": false, + "read_only": false, + "authorisations": null, + "access_profiles": "caseworker-probate-public", + "live_from": "2017-01-01", + "live_to": null, + "role_name": "idam:caseworker-probate-public", + "case_access_categories": null + }, + { + "case_type_id": "TestAddressBookCaseFiltered", + "disabled": false, + "read_only": false, + "authorisations": null, + "access_profiles": "caseworker-probate-private", + "live_from": "2017-01-01", + "live_to": null, + "role_name": "idam:caseworker-probate-private", + "case_access_categories": null + }, + { + "case_type_id": "TestAddressBookCaseFiltered", + "disabled": false, + "read_only": false, + "authorisations": null, + "access_profiles": "caseworker-test-public", + "live_from": "2017-01-01", + "live_to": null, + "role_name": "idam:caseworker-test-public", + "case_access_categories": null + }, + { + "case_type_id": "TestAddressBookCaseFiltered", + "disabled": false, + "read_only": false, + "authorisations": null, + "access_profiles": "citizen", + "live_from": "2017-01-01", + "live_to": null, + "role_name": "idam:citizen", + "case_access_categories": null + }, + { + "case_type_id": "TestAddressBookCaseFiltered", + "disabled": false, + "read_only": false, + "authorisations": null, + "access_profiles": "role-citizen", + "live_from": "2017-01-01", + "live_to": null, + "role_name": "idam:role-citizen", + "case_access_categories": null + }, + { + "case_type_id": "TestAddressBookCaseFiltered", + "disabled": false, + "read_only": false, + "authorisations": null, + "access_profiles": "[CREATOR]", + "live_from": "2017-01-01", + "live_to": null, + "role_name": "[CREATOR]", + "case_access_categories": null + }, + { + "case_type_id": "TestAddressBookCaseFiltered", + "disabled": false, + "read_only": false, + "authorisations": null, + "access_profiles": "basic-profile", + "live_from": "2017-01-01", + "live_to": null, + "role_name": "hmcts-legal-operations", + "case_access_categories": null + }, + { + "case_type_id": "TestAddressBookCaseFiltered", + "disabled": false, + "read_only": false, + "authorisations": null, + "access_profiles": "basic-profile", + "live_from": "2017-01-01", + "live_to": null, + "role_name": "hmcts-judiciary", + "case_access_categories": null + } + ], + "events": [ + { + "id": "HAS_PRE_STATES_EVENT", + "name": "HAS PRE STATES EVENT", + "description": "Test event for non null pre-states", + "order": 1, + "case_fields": [ + { + "case_field_id": "PersonFirstName", + "display_context": "READONLY", + "show_summary_content_option": 2 + }, + { + "case_field_id": "PersonLastName", + "display_context": "OPTIONAL", + "show_summary_content_option": 1 + } + ], + "pre_states": [ + "some-state", + "CaseCreated" + ], + "post_states": [{ + "enabling_condition" : null, + "priority" : 99, + "post_state_reference" : "state4" + }], + "security_classification": "PRIVATE", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": true, + "update": false, + "delete": false + }], + "show_event_notes": false, + "can_save_draft": false + }, + { + "id": "NO_PRE_STATES_EVENT", + "name": "NO PRE STATES EVENT", + "description": "Test event for null pre-states", + "order": 1, + "case_fields": [ + { + "case_field_id": "PersonFirstName", + "display_context": "READONLY" + }, + { + "case_field_id": "PersonLastName", + "display_context": "OPTIONAL" + } + ], + "pre_states": [ + ], + "post_states": [{ + "enabling_condition" : null, + "priority" : 99, + "post_state_reference" : "state4" + }], + "security_classification": "PRIVATE", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": true, + "update": false, + "delete": false + }], + "show_event_notes": true, + "can_save_draft": true + }, + { + "id": "TEST_EVENT", + "name": "TEST EVENT NAME", + "description": "Just a test", + "case_fields": [ + ], + "pre_states": [ + ], + "post_states": [{ + "enabling_condition" : null, + "priority" : 99, + "post_state_reference" : "state3" + }], + "security_classification": "PRIVATE", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": true, + "update": false, + "delete": false + }], + "show_event_notes": true, + "publish": true, + "can_save_draft": true + }, + { + "id": "Goodness", + "name": "GRACIOUS", + "description": "This is an event", + "order": 3, + "case_fields": [], + "pre_states": [ + "CaseCreated" + ], + "post_states": [{ + "enabling_condition" : null, + "priority" : 99, + "post_state_reference" : "state4" + }], + "security_classification": "PRIVATE", + "acls": [ + { + "role": "caseworker-probate-public", + "create": false, + "read": true, + "update": false, + "delete": false + }], + "show_event_notes": true, + "can_save_draft": false + }, + { + "id": "Create2", + "name": "CREATE_2", + "description": "Another creation event", + "order": 4, + "case_fields": [], + "pre_states": [], + "post_states": [{ + "enabling_condition" : null, + "priority" : 99, + "post_state_reference" : "state4" + }], + "security_classification": "PRIVATE", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": true, + "update": false, + "delete": false + }], + "show_event_notes": true, + "can_save_draft": true + } + ], + "states": [ + { + "id": "CaseCreated", + "name": "Case Created", + "acls": [ + { + "role": "caseworker-probate-public", + "create": false, + "read": true, + "update": true, + "delete": false + }, + { + "role": "caseworker-probate-private", + "create": false, + "read": true, + "update": true, + "delete": false + }, + { + "role": "role-citizen", + "create": false, + "read": true, + "update": true, + "delete": false + }, + { + "role": "basic-profile", + "create": false, + "read": true, + "update": false, + "delete": false + }] + }, + { + "id": "CaseEnteredIntoLegacy", + "name": "Case Has Been Entered Into Legacy", + "acls": [ + { + "role": "caseworker-probate-public", + "create": false, + "read": true, + "update": true, + "delete": false + }] + }, + { + "id": "CaseStopped", + "name": "Put case on hold", + "acls": [ + { + "role": "caseworker-probate-public", + "create": false, + "read": true, + "update": true, + "delete": false + }] + }, + { + "id": "state3", + "name": "Case in state 3", + "acls": [ + { + "role": "caseworker-probate-public", + "create": false, + "read": true, + "update": true, + "delete": false + }] + }, + { + "id": "state4", + "name": "Case in state 4", + "acls": [ + { + "role": "caseworker-probate-public", + "create": false, + "read": true, + "update": true, + "delete": false + }] + }, + { + "id": "some-state", + "name": "Case in some state", + "acls": [ + { + "role": "caseworker-probate-public", + "create": false, + "read": true, + "update": false, + "delete": false + }, + { + "role": "caseworker-probate-private", + "create": false, + "read": true, + "update": true, + "delete": false + }] + } + ], + "case_fields": [ + { + "id": "PersonFirstName", + "case_type_id": "TestAddressBookCaseFiltered", + "label": "First name", + "security_classification": "PUBLIC", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "caseworker-test-public", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "caseworker-probate-private", + "create": true, + "read": true, + "update": true, + "delete": false + }], + "field_type": { + "type": "Text", + "id": "Text" + } + }, + { + "id": "PersonLastName", + "case_type_id": "TestAddressBookCaseFiltered", + "label": "Last name", + "security_classification": "PUBLIC", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "caseworker-test-public", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "caseworker-probate-private", + "create": true, + "read": true, + "update": true, + "delete": false + }], + "field_type": { + "type": "Text", + "id": "Text" + } + }, + { + "id": "PersonAddress", + "case_type_id": "TestAddressBookCaseFiltered", + "label": "Address", + "security_classification": "PUBLIC", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": false, + "update": true, + "delete": false + }, + { + "role": "caseworker-test-public", + "create": true, + "read": true, + "update": true, + "delete": false + }, + { + "role": "caseworker-probate-private", + "create": true, + "read": true, + "update": true, + "delete": false + }], + "field_type": { + "id": "Address", + "type": "Complex", + "complex_fields": [ + { + "id": "AddressLine1", + "label": "Line1", + "security_classification": "PUBLIC", + "field_type": { + "id": "Text", + "type": "Text" + } + }, + { + "id": "AddressLine2", + "label": "Line 2", + "security_classification": "PUBLIC", + "field_type": { + "id": "Text", + "type": "Text" + } + }, + { + "id": "AddressLine3", + "label": "Line 3", + "security_classification": "PUBLIC", + "field_type": { + "id": "Text", + "type": "Text" + } + }, + { + "id": "Postcode", + "label": "Postcode", + "security_classification": "PUBLIC", + "field_type": { + "id": "Postcode", + "type": "Postcode" + } + }, + { + "id": "Country", + "label": "Country", + "security_classification": "PUBLIC", + "field_type": { + "id": "Text", + "type": "Text" + } + } + ] + } + }, + { + "id": "Aliases", + "case_type_id": "TestAddressBookCaseFiltered", + "label": "Aliases", + "security_classification": "PUBLIC", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": false, + "update": true, + "delete": true + }, + { + "role": "caseworker-probate-private", + "create": true, + "read": true, + "update": true, + "delete": false + }], + "field_type": { + "type": "Collection", + "id": "Collection", + "collection_field_type": { + "type": "Text", + "id": "Text" + } + } + }, + { + "id": "D8Document", + "case_type_id": "TestAddressBookCaseFiltered", + "label": "Document", + "security_classification": "PUBLIC", + "acls": [ + { + "role": "caseworker-probate-public", + "create": true, + "read": false, + "update": true, + "delete": false + }, + { + "role": "caseworker-probate-private", + "create": true, + "read": true, + "update": true, + "delete": false + }], + "field_type": { + "type": "Document", + "id": "Document" + } + } + ] + } + } +} diff --git a/src/test/resources/sql/insert_cases.sql b/src/test/resources/sql/insert_cases.sql index cc793788a9..7427dda841 100644 --- a/src/test/resources/sql/insert_cases.sql +++ b/src/test/resources/sql/insert_cases.sql @@ -1,6 +1,100 @@ DELETE FROM case_event; DELETE FROM case_data; +INSERT INTO case_data (id, case_type_id, jurisdiction, state, security_classification, data, data_classification, reference, created_date, last_modified, last_state_modified_date) +VALUES (25, 'TestAddressBookCaseFiltered', 'PROBATE', 'CaseCreated', 'PUBLIC', + '{ + "PersonFirstName": "Janet", + "PersonLastName": "Parker", + "PersonAddress": { + "AddressLine1": "123", + "AddressLine2": "Fake Street", + "AddressLine3": "Hexton", + "Country": "England", + "Postcode": "HX08 5TG" + }, + "Aliases": [ + { + "id": "1", + "value": "Alias1" + }, + { + "id": "2", + "value": "Alias2" + }, + { + "id": "3", + "value": "Alias3" + } + ], + "D8Document": { + "category_id": "detailsOfClaim", + "document_url": "http://localhost:[port]/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d1", + "document_binary_url": "http://localhost:[port]/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d1/binary", + "document_filename": "Seagulls_Square.jpg" + } + }', + '{ + "PersonFirstName": "PUBLIC", + "PersonLastName": "PUBLIC", + "PersonAddress": { + "classification" : "PUBLIC", + "value" : { + "AddressLine1": "PUBLIC", + "AddressLine2": "PUBLIC", + "AddressLine3": "PUBLIC", + "Country": "PUBLIC", + "Postcode": "PUBLIC" + } + }, + "D8Document": "PUBLIC" + }', + '6512245793128983', + '2016-06-22 20:44:52.824', + '2016-06-24 20:44:52.824', + '2016-06-24 20:44:52.824' +); + +INSERT INTO case_data (id, case_type_id, jurisdiction, state, security_classification, data, data_classification, reference, created_date, last_modified, last_state_modified_date) +VALUES (24, 'TestAddressBookCaseFiltered', 'PROBATE', 'CaseCreated', 'PUBLIC', + '{ + "PersonFirstName": "Janet", + "PersonLastName": "Parker", + "PersonAddress": { + "AddressLine1": "123", + "AddressLine2": "Fake Street", + "AddressLine3": "Hexton", + "Country": "England", + "Postcode": "HX08 5TG" + }, + "D8Document": { + "category_id": "detailsOfClaim", + "document_url": "http://localhost:[port]/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d1", + "document_binary_url": "http://localhost:[port]/documents/05e7cd7e-7041-4d8a-826a-7bb49dfd83d1/binary", + "document_filename": "Seagulls_Square.jpg" + } + }', + '{ + "PersonFirstName": "PUBLIC", + "PersonLastName": "PUBLIC", + "PersonAddress": { + "classification" : "PUBLIC", + "value" : { + "AddressLine1": "PUBLIC", + "AddressLine2": "PUBLIC", + "AddressLine3": "PUBLIC", + "Country": "PUBLIC", + "Postcode": "PUBLIC" + } + }, + "D8Document": "PUBLIC" + }', + '1202264432028419', + '2016-06-22 20:44:52.824', + '2016-06-24 20:44:52.824', + '2016-06-24 20:44:52.824' +); + INSERT INTO case_data (id, case_type_id, jurisdiction, state, security_classification, data, data_classification, reference, created_date, last_modified, last_state_modified_date) VALUES (1, 'TestAddressBookCase', 'PROBATE', 'CaseCreated', 'PUBLIC', '{