diff --git a/Jenkinsfile_CNP b/Jenkinsfile_CNP index 816cc713b6..21ea5ee12d 100644 --- a/Jenkinsfile_CNP +++ b/Jenkinsfile_CNP @@ -20,8 +20,8 @@ def branchesToSync = ['demo', 'ithc', 'perftest', 'develop'] // Variables to switch pipeline logic and wiring per type of build -def definitionStoreDevelopPr = "PR-575" // This doesn't change frequently, but when it does, only change this value. -def dataStoreApiDevelopPr = "PR-1260" // This doesn't change frequently, but when it does, only change this value. +def definitionStoreDevelopPr = "PR-1540" // This doesn't change frequently, but when it does, only change this value. +def dataStoreApiDevelopPr = "PR-2552" // This doesn't change frequently, but when it does, only change this value. def prsToUseAat = "PR-1793,PR-1888" // Set this value to a PR number, or add it as a comma-separated value, if it's to follow CI/CD. def secrets = [ diff --git a/README.md b/README.md index 0ca15dfae1..617508e2d6 100644 --- a/README.md +++ b/README.md @@ -109,16 +109,22 @@ To find out more about BEFTA Framework, see the repository and its README [here] ##### All Functional Tests Will run all the FT's: - ./gradlew functional +```bash +./gradlew functional +``` ##### Some Functional Tests Will run both F-1023 and F-777: - ./gradlew functional -P tags="@F-1023 or @F-777" +```bash +./gradlew functional -P tags="@F-1023 or @F-777" +``` Will run only S-1023.5: - ./gradlew functional -P tags="@S-1023.5" +```bash +./gradlew functional -P tags="@S-1023.5" +``` ## LICENSE diff --git a/charts/ccd-data-store-api/values.preview.template.yaml b/charts/ccd-data-store-api/values.preview.template.yaml index 31c16a7631..921c152fb1 100644 --- a/charts/ccd-data-store-api/values.preview.template.yaml +++ b/charts/ccd-data-store-api/values.preview.template.yaml @@ -27,7 +27,7 @@ java: DATA_STORE_DB_PASSWORD: "{{ .Values.postgresql.auth.password}}" DATA_STORE_DB_OPTIONS: "?stringtype=unspecified" DATA_STORE_DB_MAX_POOL_SIZE: 10 - DEFINITION_STORE_HOST: http://ccd-definition-store-api-pr-575-java/ + DEFINITION_STORE_HOST: http://ccd-definition-store-api-pr-1540-java/ USER_PROFILE_HOST: http://ccd-user-profile-api-pr-399-java/ ELASTIC_SEARCH_ENABLED: true # enable whenever ES required on a particular PR ELASTIC_SEARCH_NODES_DISCOVERY_ENABLED: true diff --git a/src/aat/resources/features/F-065a - Get Case V2 Internal/F-065a.feature b/src/aat/resources/features/F-065a - Get Case V2 Internal/F-065a.feature new file mode 100644 index 0000000000..48a1c78719 --- /dev/null +++ b/src/aat/resources/features/F-065a - Get Case V2 Internal/F-065a.feature @@ -0,0 +1,52 @@ +#========================================================== +@F-065a + Feature: F-065a: Retrieve access metadata for a given case ID +#========================================================== + +Background: Load test data for the scenario + Given an appropriate test context as detailed in the test data source + +#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + @S-065a.1 + Scenario: must return case access metadata when the case reference exists + + Given a case that has just been created as in [Standard_Full_Case_Creation_Data], + And a user with [an active profile in CCD], + And a successful call [to get an event token for just created case] as in [S-065a-Prerequisite], + And another successful call [to update case with the token just created] as in [S-065a-Prerequisite_Case_Update], + + When a request is prepared with appropriate values, + And the request [contains a case that has just been created as in Standard_Full_Case_Creation_Data], + And it is submitted to call the [Retrieve access metadata for a given case ID] operation of [CCD Data Store], + + Then a positive response is received, + And the response [contains details of the case just created, along with an HTTP-200 OK], + And the response [contains the case access metadata], + And the response has all other details as expected. + +#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + @S-065a.2 + Scenario: must return null when case reference does NOT exist + + Given a user with [an active profile in CCD], + + When a request is prepared with appropriate values, + And the request [uses case-reference which does not exist in CCD], + And it is submitted to call the [Retrieve access metadata for a given case ID] operation of [CCD Data Store], + + Then a positive response is received, + And the response [has an HTTP-200 OK], + And the response [contains the case access metadata with null], + +#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + @S-065a.3 + Scenario: must return 400 when case reference is invalid + + Given a user with [an active profile in CCD], + + When a request is prepared with appropriate values, + And the request [uses an invalid case-reference], + And it is submitted to call the [Retrieve access metadata for a given case ID] operation of [CCD Data Store], + + Then a negative response is received, + And the response [has an HTTP-400 code] diff --git a/src/aat/resources/features/F-065a - Get Case V2 Internal/F-065a_Test_Data_Access_Metadata_Base.td.json b/src/aat/resources/features/F-065a - Get Case V2 Internal/F-065a_Test_Data_Access_Metadata_Base.td.json new file mode 100644 index 0000000000..5749551637 --- /dev/null +++ b/src/aat/resources/features/F-065a - Get Case V2 Internal/F-065a_Test_Data_Access_Metadata_Base.td.json @@ -0,0 +1,31 @@ +{ + "_guid_": "F-065a_Test_Data_Access_Metadata_Base", + + "productName": "CCD Data Store", + "operationName": "Retrieve access metadata for a given case ID", + + "method": "GET", + "uri": "/internal/cases/{cid}/access-metadata", + + "user": { + "_extends_": "Common_User_For_Request" + }, + + "request": { + "_extends_": "Common_Request", + "headers": { + "experimental": true + }, + "pathVariables": { + "cid": "1234567890123456" + } + }, + + "expectedResponse": { + "headers": { + "_extends_": "Common_Response_Headers", + "Content-Type": "[[ANYTHING_PRESENT]]", + "Content-Encoding": "gzip" + } + } +} diff --git a/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a-Prerequisite.td.json b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a-Prerequisite.td.json new file mode 100644 index 0000000000..ffc823cb5f --- /dev/null +++ b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a-Prerequisite.td.json @@ -0,0 +1,44 @@ +{ + "_guid_": "S-065a-Prerequisite", + "title": "should create an event token for correct inputs", + + "productName": "CCD Data Store", + "operationName": "Retrieve a create token", + + "method": "GET", + "uri": "/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases/{cid}/event-triggers/{etid}/token", + + "specs": [ + "to get an event token for just created case" + ], + + "user": { + "_extends_": "Common_User_For_Request" + }, + + "request": { + "headers": { + "_extends_": "Common_Request_Headers" + }, + "pathVariables": { + "uid": "[[DEFAULT_AUTO_VALUE]]", + "jid": "AUTOTEST1", + "ctid": "AAT_AUTH_15", + "cid": "${[scenarioContext][parentContext][childContexts][Standard_Full_Case_Creation_Data][testData][actualResponse][body][id]}", + "etid": "UPDATE" + } + }, + + "expectedResponse": { + "_extends_": "Common_200_Response", + "headers": { + "Content-Encoding": "gzip", + "Content-Length": "[[ANYTHING_PRESENT]]" + }, + "body": { + "token": "[[ANYTHING_PRESENT]]", + "case_details": "[[ANYTHING_PRESENT]]", + "event_id": "UPDATE" + } + } +} diff --git a/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a-Prerequisite_Case_Update.td.json b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a-Prerequisite_Case_Update.td.json new file mode 100644 index 0000000000..02cabcf186 --- /dev/null +++ b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a-Prerequisite_Case_Update.td.json @@ -0,0 +1,184 @@ +{ + "_guid_": "S-065a-Prerequisite_Case_Update", + "title": "should update an existing case with correct inputs", + + "productName": "CCD Data Store", + "operationName": "Submit update case event", + + "method": "POST", + "uri": "/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases/{cid}/events", + + "specs": [ + "to update case with the token just created" + ], + + "user": { + "_extends_": "Common_User_For_Request" + }, + + "request": { + "headers": { + "_extends_": "Common_Request_Headers" + }, + "pathVariables": { + "uid": "[[DEFAULT_AUTO_VALUE]]", + "jid": "AUTOTEST1", + "ctid": "AAT_AUTH_15", + "cid": "${[scenarioContext][parentContext][childContexts][Standard_Full_Case_Creation_Data][testData][actualResponse][body][id]}" + }, + "body": { + "data": { + "MoneyGBPField": "4300", + "FixedListField": "VALUE3", + "AddressUKField": { + "County": "Greater London", + "Country": "UK", + "PostCode": "SW1H 9AJ", + "PostTown": "Westminster", + "AddressLine1": "102 Petty France", + "AddressLine2": "CCD", + "AddressLine3": "c/o HMCTS Reform" + }, + "ComplexField": { + "ComplexTextField": "Nested text", + "ComplexFixedListField": "VALUE2" + }, + "DateTimeField": "1988-07-07T22:20:00", + "PhoneUKField": "07123456789", + "NumberField": "164528", + "MultiSelectListField": [ + "OPTION2", + "OPTION4" + ], + "YesOrNoField": "Yes", + "EmailField": "ccd@hmcts.net", + "TextField": "Some Text", + "DateField": "2017-02-13", + "TextAreaField": "Line1\nLine2", + "CollectionField": [ + { + "id": "4926d94c-1fa3-4c16-b5ba-5a122d8c622d", + "value": "Alias 1" + }, + { + "id": "936b6a65-a179-474f-bdff-1d4f961e9a8c", + "value": "Alias 2" + } + ] + }, + "event": { + "id": "UPDATE", + "summary": "", + "description": "" + }, + "event_token": "${[scenarioContext][parentContext][childContexts][S-065a-Prerequisite][testData][actualResponse][body][token]}", + "ignore_warning": false + } + }, + + "expectedResponse": { + "_extends_": "Common_201_Response", + "headers": { + "vary": "accept-encoding", + "Content-Length": "[[ANYTHING_PRESENT]]", + "Content-Encoding": "gzip" + }, + "body": { + "id": "[[ANYTHING_PRESENT]]", + "jurisdiction": "AUTOTEST1", + "state": "TODO", + "version": 1, + "case_type_id": "AAT_AUTH_15", + "last_state_modified_date": "[[ANYTHING_PRESENT]]", + "created_date": "[[ANYTHING_PRESENT]]", + "last_modified": "[[ANYTHING_PRESENT]]", + "security_classification": "PUBLIC", + "case_data": { + "MoneyGBPField": "[[ANYTHING_PRESENT]]", + "FixedListField": "VALUE3", + "AddressUKField": { + "County": "Greater London", + "Country": "UK", + "PostCode": "SW1H 9AJ", + "PostTown": "Westminster", + "AddressLine1": "102 Petty France", + "AddressLine2": "CCD", + "AddressLine3": "c/o HMCTS Reform" + }, + "ComplexField": { + "ComplexTextField": "Nested text", + "ComplexFixedListField": "VALUE2" + }, + "DateTimeField": "[[ANYTHING_PRESENT]]", + "PhoneUKField": "07123456789", + "NumberField": "164528", + "MultiSelectListField": [ + "OPTION2", + "OPTION4" + ], + "YesOrNoField": "Yes", + "EmailField": "ccd@hmcts.net", + "TextField": "Some Text", + "DateField": "2017-02-13", + "TextAreaField": "Line1\nLine2", + "CollectionField": [ + { + "value": "Alias 1", + "id": "[[ANYTHING_PRESENT]]" + }, + { + "value": "Alias 2", + "id": "[[ANYTHING_PRESENT]]" + } + ] + }, + "data_classification": { + "MoneyGBPField": "PUBLIC", + "FixedListField": "PUBLIC", + "AddressUKField": { + "classification": "PUBLIC", + "value": { + "County": "PUBLIC", + "Country": "PUBLIC", + "PostCode": "PUBLIC", + "PostTown": "PUBLIC", + "AddressLine1": "PUBLIC", + "AddressLine2": "PUBLIC", + "AddressLine3": "PUBLIC" + } + }, + "DateTimeField": "PUBLIC", + "PhoneUKField": "PUBLIC", + "NumberField": "PUBLIC", + "MultiSelectListField": "PUBLIC", + "YesOrNoField": "PUBLIC", + "EmailField": "PUBLIC", + "TextField": "PUBLIC", + "DateField": "PUBLIC", + "TextAreaField": "PUBLIC", + "CollectionField": { + "classification": "PUBLIC", + "value": [ + { + "__ordering__": "ordered" + }, + { + "id": "[[ANYTHING_PRESENT]]", + "classification": "PUBLIC" + }, + { + "id": "[[ANYTHING_PRESENT]]", + "classification": "PUBLIC" + } + ] + } + }, + "supplementary_data": null, + "after_submit_callback_response": null, + "callback_response_status_code": null, + "callback_response_status": null, + "delete_draft_response_status_code": null, + "delete_draft_response_status": null + } + } +} diff --git a/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a.1.td.json b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a.1.td.json new file mode 100644 index 0000000000..516a47da04 --- /dev/null +++ b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a.1.td.json @@ -0,0 +1,31 @@ +{ + "_guid_": "S-065a.1", + "_extends_": "F-065a_Test_Data_Access_Metadata_Base", + "title": "must return case view history when the case reference exists", + + "specs": [ + "an active profile in CCD", + "contains a case that has just been created as in Standard_Full_Case_Creation_Data", + "contains details of the case just created, along with an HTTP-200 OK", + "contains the case access metadata" + ], + + "request": { + "pathVariables": { + "cid": "${[scenarioContext][childContexts][Standard_Full_Case_Creation_Data][testData][actualResponse][body][id]}" + } + }, + + "expectedResponse": { + "_extends_": "Common_200_Response", + "headers": { + "Vary": "Accept-Encoding", + "Transfer-Encoding": "chunked", + "Content-Type": "application/vnd.uk.gov.hmcts.ccd-data-store-api.ui-case-access-metadata.v2+json;charset=UTF-8" + }, + "body": { + "accessGrants" : [ "STANDARD" ], + "accessProcess" : "NONE" + } + } +} diff --git a/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a.2.td.json b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a.2.td.json new file mode 100644 index 0000000000..45edfec8d8 --- /dev/null +++ b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a.2.td.json @@ -0,0 +1,33 @@ +{ + "_guid_": "S-065a.2", + "_extends_": "F-065a_Test_Data_Access_Metadata_Base", + "title": "must return null when case reference does NOT exist", + + "specs": [ + "an active profile in CCD", + "uses case-reference which does not exist in CCD", + "has an HTTP-200 OK", + "contains the case access metadata with null" + ], + + "request": { + "pathVariables": { + "cid": "1234123412341238" + } + }, + + "expectedResponse": { + "_extends_": "Common_404_Response", + "headers": { + "Content-Length": "[[ANY_INTEGER_NOT_NULLABLE]]" + }, + "body": { + "exception": "uk.gov.hmcts.ccd.endpoint.exceptions.ResourceNotFoundException", + "message": "No case found", + "path": "/internal/cases/1234123412341238", + "details": null, + "callbackErrors": null, + "callbackWarnings": null + } + } +} diff --git a/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a.3.td.json b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a.3.td.json new file mode 100644 index 0000000000..8a59dcf8c8 --- /dev/null +++ b/src/aat/resources/features/F-065a - Get Case V2 Internal/S-065a.3.td.json @@ -0,0 +1,32 @@ +{ + "_guid_": "S-065a.3", + "_extends_": "F-065a_Test_Data_Access_Metadata_Base", + "title": "must return 400 when case reference is invalid", + + "specs": [ + "an active profile in CCD", + "uses an invalid case-reference", + "has an HTTP-400 code" + ], + + "request": { + "pathVariables": { + "cid": "dummyid" + } + }, + + "expectedResponse": { + "_extends_": "Common_400_Response", + "headers": { + "Content-Length": "[[ANY_INTEGER_NOT_NULLABLE]]" + }, + "body": { + "exception": "uk.gov.hmcts.ccd.endpoint.exceptions.BadRequestException", + "message": "Case ID is not valid", + "path": "/internal/cases/dummyid", + "details": null, + "callbackErrors": null, + "callbackWarnings": null + } + } +} diff --git a/src/main/java/uk/gov/hmcts/ccd/domain/model/casedataaccesscontrol/CaseAccessMetadata.java b/src/main/java/uk/gov/hmcts/ccd/domain/model/casedataaccesscontrol/CaseAccessMetadata.java index f158037fd3..f57233e5b3 100644 --- a/src/main/java/uk/gov/hmcts/ccd/domain/model/casedataaccesscontrol/CaseAccessMetadata.java +++ b/src/main/java/uk/gov/hmcts/ccd/domain/model/casedataaccesscontrol/CaseAccessMetadata.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.ccd.domain.model.casedataaccesscontrol; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import uk.gov.hmcts.ccd.domain.model.casedataaccesscontrol.enums.GrantType; @@ -19,6 +20,12 @@ public class CaseAccessMetadata { private List accessGrants; private AccessProcess accessProcess; + @JsonIgnore + private String accessGrantsString; + + @JsonIgnore + private String accessProcessString; + public String getAccessGrantsString() { if (accessGrants == null) { return null; diff --git a/src/main/java/uk/gov/hmcts/ccd/v2/V2.java b/src/main/java/uk/gov/hmcts/ccd/v2/V2.java index 13931e5ac7..86332ff872 100644 --- a/src/main/java/uk/gov/hmcts/ccd/v2/V2.java +++ b/src/main/java/uk/gov/hmcts/ccd/v2/V2.java @@ -65,6 +65,9 @@ private MediaType() { public static final String CASE_EVENTS = "application/vnd.uk.gov.hmcts.ccd-data-store-api.case-events.v2+json;charset=UTF-8"; + public static final String UI_CASE_ACCESS_METADATA = + "application/vnd.uk.gov.hmcts.ccd-data-store-api.ui-case-access-metadata.v2+json;charset=UTF-8"; + } public final class Error { diff --git a/src/main/java/uk/gov/hmcts/ccd/v2/internal/controller/UICaseController.java b/src/main/java/uk/gov/hmcts/ccd/v2/internal/controller/UICaseController.java index abd477b68f..2b86aad3d6 100644 --- a/src/main/java/uk/gov/hmcts/ccd/v2/internal/controller/UICaseController.java +++ b/src/main/java/uk/gov/hmcts/ccd/v2/internal/controller/UICaseController.java @@ -13,10 +13,12 @@ import uk.gov.hmcts.ccd.auditlog.LogAudit; import uk.gov.hmcts.ccd.domain.model.aggregated.CaseHistoryView; import uk.gov.hmcts.ccd.domain.model.aggregated.CaseView; +import uk.gov.hmcts.ccd.domain.model.casedataaccesscontrol.CaseAccessMetadata; import uk.gov.hmcts.ccd.domain.service.aggregated.AuthorisedGetCaseHistoryViewOperation; import uk.gov.hmcts.ccd.domain.service.aggregated.AuthorisedGetCaseViewOperation; import uk.gov.hmcts.ccd.domain.service.aggregated.GetCaseHistoryViewOperation; import uk.gov.hmcts.ccd.domain.service.aggregated.GetCaseViewOperation; +import uk.gov.hmcts.ccd.domain.service.casedataaccesscontrol.CaseDataAccessControl; import uk.gov.hmcts.ccd.domain.service.common.UIDService; import uk.gov.hmcts.ccd.endpoint.exceptions.BadRequestException; import uk.gov.hmcts.ccd.v2.V2; @@ -34,16 +36,19 @@ public class UICaseController { private final GetCaseViewOperation getCaseViewOperation; private final GetCaseHistoryViewOperation getCaseHistoryViewOperation; private final UIDService caseReferenceService; + private final CaseDataAccessControl caseDataAccessControl; @Autowired public UICaseController( @Qualifier(AuthorisedGetCaseViewOperation.QUALIFIER) GetCaseViewOperation getCaseViewOperation, @Qualifier(AuthorisedGetCaseHistoryViewOperation.QUALIFIER) GetCaseHistoryViewOperation getCaseHistoryOperation, - UIDService caseReferenceService + UIDService caseReferenceService, + CaseDataAccessControl caseDataAccessControl ) { this.getCaseViewOperation = getCaseViewOperation; this.getCaseHistoryViewOperation = getCaseHistoryOperation; this.caseReferenceService = caseReferenceService; + this.caseDataAccessControl = caseDataAccessControl; } @GetMapping( @@ -126,4 +131,44 @@ public ResponseEntity getCaseHistoryView(@PathVariable( return ResponseEntity.ok(new CaseHistoryViewResource(caseHistoryView, caseId)); } + + @GetMapping( + path = "/{caseId}/access-metadata", + headers = { + V2.EXPERIMENTAL_HEADER + }, + produces = { + V2.MediaType.UI_CASE_ACCESS_METADATA + } + ) + @ApiOperation( + value = "Retrieve access metadata for a given case ID", + notes = V2.EXPERIMENTAL_WARNING + ) + @ApiResponses({ + @ApiResponse( + code = 200, + message = "Success", + response = CaseAccessMetadata.class + ), + @ApiResponse( + code = 400, + message = ERROR_CASE_ID_INVALID + ), + @ApiResponse( + code = 404, + message = "Case not found" + ) + }) + @LogAudit(operationType = CASE_ACCESSED, caseId = "#caseId", + caseType = "#result.body.caseType.id") + public ResponseEntity getCaseAccessMetadata(@PathVariable("caseId") String caseId) { + if (!caseReferenceService.validateUID(caseId)) { + throw new BadRequestException(ERROR_CASE_ID_INVALID); + } + + final CaseAccessMetadata caseAccessMetadata = caseDataAccessControl.generateAccessMetadata(caseId); + + return ResponseEntity.ok(caseAccessMetadata); + } } diff --git a/src/test/java/uk/gov/hmcts/ccd/v2/internal/controller/UICaseControllerTest.java b/src/test/java/uk/gov/hmcts/ccd/v2/internal/controller/UICaseControllerTest.java index 0707079561..e7184cacd9 100644 --- a/src/test/java/uk/gov/hmcts/ccd/v2/internal/controller/UICaseControllerTest.java +++ b/src/test/java/uk/gov/hmcts/ccd/v2/internal/controller/UICaseControllerTest.java @@ -12,19 +12,27 @@ import uk.gov.hmcts.ccd.domain.model.aggregated.CaseHistoryView; import uk.gov.hmcts.ccd.domain.model.aggregated.CaseView; import uk.gov.hmcts.ccd.domain.model.aggregated.CaseViewEvent; +import uk.gov.hmcts.ccd.domain.model.casedataaccesscontrol.AccessProcess; +import uk.gov.hmcts.ccd.domain.model.casedataaccesscontrol.CaseAccessMetadata; +import uk.gov.hmcts.ccd.domain.model.casedataaccesscontrol.enums.GrantType; import uk.gov.hmcts.ccd.domain.service.aggregated.GetCaseHistoryViewOperation; import uk.gov.hmcts.ccd.domain.service.aggregated.GetCaseViewOperation; +import uk.gov.hmcts.ccd.domain.service.casedataaccesscontrol.CaseDataAccessControl; import uk.gov.hmcts.ccd.domain.service.common.UIDService; import uk.gov.hmcts.ccd.endpoint.exceptions.BadRequestException; import uk.gov.hmcts.ccd.v2.internal.resource.CaseHistoryViewResource; import uk.gov.hmcts.ccd.v2.internal.resource.CaseViewResource; +import java.util.List; + import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @DisplayName("UICaseController") @@ -41,6 +49,9 @@ class UICaseControllerTest { @Mock private UIDService caseReferenceService; + @Mock + private CaseDataAccessControl caseDataAccessControl; + @Mock private CaseView caseView; @@ -62,6 +73,7 @@ void setUp() { when(caseHistoryView.getEvent()).thenReturn(caseViewEvent); when(caseViewEvent.getId()).thenReturn(EVENT_ID); + when(caseDataAccessControl.generateAccessMetadata(CASE_REFERENCE)).thenReturn(new CaseAccessMetadata()); when(caseReferenceService.validateUID(CASE_REFERENCE)).thenReturn(TRUE); when(getCaseViewOperation.execute(CASE_REFERENCE)).thenReturn(caseView); when(getCaseHistoryViewOperation.execute(CASE_REFERENCE, EVENT_ID)).thenReturn(caseHistoryView); @@ -137,4 +149,44 @@ void shouldPropagateExceptionWhenThrown() { } } + @Nested + @DisplayName("GET /internal/cases/{caseId}/access-metadata") + class GetCaseAccessMetadataForId { + + @Test + @DisplayName("should return 200 when metadata found") + void accessMetadataFound() { + CaseAccessMetadata caseAccessMetadata = new CaseAccessMetadata(); + caseAccessMetadata.setAccessGrants(List.of(GrantType.STANDARD, GrantType.SPECIFIC, GrantType.CHALLENGED)); + caseAccessMetadata.setAccessProcess(AccessProcess.NONE); + doReturn(caseAccessMetadata).when(caseDataAccessControl).generateAccessMetadata(CASE_REFERENCE); + + final ResponseEntity response + = caseController.getCaseAccessMetadata(CASE_REFERENCE); + + assertAll( + () -> assertThat(response.getStatusCode(), is(HttpStatus.OK)), + () -> assertThat(response.getBody().getAccessGrants(), hasItem(GrantType.STANDARD)), + () -> assertThat(response.getBody().getAccessProcess(), is(AccessProcess.NONE)) + ); + } + + @Test + @DisplayName("should propagate BadRequestException when case reference not valid") + void caseReferenceNotValid() { + when(caseReferenceService.validateUID(CASE_REFERENCE)).thenReturn(FALSE); + + assertThrows(BadRequestException.class, + () -> caseController.getCaseAccessMetadata(CASE_REFERENCE)); + } + + @Test + @DisplayName("should propagate exception") + void shouldPropagateExceptionWhenThrown() { + when(caseDataAccessControl.generateAccessMetadata(CASE_REFERENCE)).thenThrow(RuntimeException.class); + + assertThrows(Exception.class, + () -> caseController.getCaseAccessMetadata(CASE_REFERENCE)); + } + } }