diff --git a/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/F-1026.feature b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/F-1026.feature new file mode 100644 index 0000000000..9dae868647 --- /dev/null +++ b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/F-1026.feature @@ -0,0 +1,37 @@ +@F-1026 +Feature: F-1026: Get jurisdictions available to the user + + Background: Load test data for the scenario + Given an appropriate test context as detailed in the test data source + + @S-1026.1 + Scenario: must return a list of jurisdictions for a valid user + Given a user with [an active profile in CCD having create case access for a jurisdiction], + When a request is prepared with appropriate values, + And the request [has CREATE as case access parameter], + And it is submitted to call the [Get jurisdictions available to the user] operation of [CCD Data Store], + Then a positive response is received, + And the response [contains HTTP 200 Ok status code], + And the response [contains the list of jurisdictions a user has access to], + And the response has all other details as expected. + + @S-1026.2 + Scenario: must return 400 if access type is not in create, read or update + Given a user with [a detailed profile in CCD having create case access for a jurisdiction], + When a request is prepared with appropriate values, + And the request [has DELETE as case access parameter], + And it is submitted to call the [Get jurisdictions available to the user] operation of [CCD Data Store], + Then a negative response is received, + And the response [contains HTTP 400 Bad Request], + And the response [contains an error message : Access can only be 'create', 'read' or 'update'], + And the response has all other details as expected. + + @S-1026.3 + Scenario: must return a list of jurisdictions for a valid user with no user profile + Given a user with [appropriate idam roles but no CCD user profile], + When a request is prepared with appropriate values, + And the request [has CREATE as case access parameter], + And it is submitted to call the [Get jurisdictions available to the user] operation of [CCD Data Store], + Then a positive response is received, + And the response [contains the list of jurisdictions a user has access to], + And the response has all other details as expected. diff --git a/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/F-1026_Test_Data_Base.td.json b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/F-1026_Test_Data_Base.td.json new file mode 100644 index 0000000000..888c1e150b --- /dev/null +++ b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/F-1026_Test_Data_Base.td.json @@ -0,0 +1,25 @@ +{ + "_guid_": "F-1026_Test_Data_Base", + "title": "Get jurisdictions available to the user", + "productName": "CCD Data Store", + "operationName": "Get jurisdictions available to the user", + "method": "GET", + "uri": "/aggregated/caseworkers/{uid}/jurisdictions-lite", + "request": { + "_extends_": "Common_Request", + "pathVariables": { + "uid": "[[DEFAULT_AUTO_VALUE]]" + } + }, + "user": { + "_extends_": "BeftaCaseworker1" + }, + "expectedResponse": { + "headers": { + "_extends_": "Common_Response_Headers", + "Content-Length": "[[ANYTHING_PRESENT]]", + "Content-Type": "[[ANYTHING_PRESENT]]", + "Content-Encoding": "[[ANYTHING_PRESENT]]" + } + } +} diff --git a/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/S-1026.1.td.json b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/S-1026.1.td.json new file mode 100644 index 0000000000..2ac534bd3f --- /dev/null +++ b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/S-1026.1.td.json @@ -0,0 +1,70 @@ +{ + "_guid_": "S-1026.1", + "_extends_": "F-1026_Test_Data_Base", + "title": "Get jurisdictions available to the user", + "specs": [ + "an active profile in CCD having create case access for a jurisdiction", + "has CREATE as case access parameter", + "contains HTTP 200 Ok status code", + "contains the list of jurisdictions a user has access to" + ], + "request": { + "_extends_": "Common_Request", + "queryParams": { + "access": "create" + } + }, + "expectedResponse": { + "_extends_": "Common_200_Response", + "body": { + "arrayInMap": [ + { + "id": "BEFTA_JURISDICTION_1", + "name": "BEFTA_JURISDICTION_1", + "description": "Content for the Test Jurisdiction.", + "caseTypes": [ + { + "__ordering__": "unordered" + }, + { + "id": "BEFTA_CASETYPE_1_1", + "description": "Create a case of type BEFTA_CASETYPE_1_1", + "version": null, + "name": "BEFTA Case Type 1 1", + "events": "[[ANYTHING_PRESENT]]", + "states": "[[ANYTHING_PRESENT]]", + "security_classification": null + }, + { + "id" : "BEFTA_CASETYPE_NO_READ", + "description" : "Create a case of type BEFTA_CASETYPE_NO_READ", + "version" : null, + "name" : "BEFTA Case Type No Read", + "events": "[[ANYTHING_PRESENT]]", + "states": "[[ANYTHING_PRESENT]]", + "security_classification": null + }, + { + "id": "CASE_TYPE_WITH_NO_CASES", + "description": "Create a case of type CASE_TYPE_WITH_NO_CASES", + "version": null, + "name": "CT With No Cases -Don't Create", + "events": "[[ANYTHING_PRESENT]]", + "states": "[[ANYTHING_PRESENT]]", + "security_classification": null + }, + { + "id" : "CaseAccessGroups_Casetype", + "description" : "For testing Case Access Group", + "version" : null, + "name" : "CaseAccessGroups_Casetype", + "events": "[[ANYTHING_PRESENT]]", + "states": "[[ANYTHING_PRESENT]]", + "security_classification": null + } + ] + } + ] + } + } +} diff --git a/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/S-1026.2.td.json b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/S-1026.2.td.json new file mode 100644 index 0000000000..277343d093 --- /dev/null +++ b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/S-1026.2.td.json @@ -0,0 +1,31 @@ +{ + "_guid_": "S-1026.2", + "_extends_": "F-1026_Test_Data_Base", + "title": "must return 400 if access type is not in create, read or update", + "specs": [ + "a detailed profile in CCD having create case access for a jurisdiction", + "contains HTTP 400 Bad Request", + "has DELETE as case access parameter", + "contains an error message : Access can only be 'create', 'read' or 'update'" + ], + "request": { + "queryParams": { + "access": "delete" + } + }, + "expectedResponse": { + "_extends_": "Common_400_Response", + "headers": { + "_extends_": "Common_400_Response_Headers" + }, + "body": { + "_extends_": "Common_400_Response_Body", + "exception": "uk.gov.hmcts.ccd.endpoint.exceptions.BadRequestException", + "message": "Access can only be 'create', 'read' or 'update'", + "path": "[[ANYTHING_PRESENT]]", + "details": null, + "callbackErrors": null, + "callbackWarnings": null + } + } +} diff --git a/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/S-1026.3.td.json b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/S-1026.3.td.json new file mode 100644 index 0000000000..83c1d72bee --- /dev/null +++ b/src/aat/resources/features/F-1026 - Get Jurisdictions Lite/S-1026.3.td.json @@ -0,0 +1,507 @@ +{ + "_guid_": "S-1026.3", + "_extends_": "F-1026_Test_Data_Base", + "title": "Get jurisdictions available to the user", + + "specs": [ + "appropriate idam roles but no CCD user profile", + "has CREATE as case access parameter", + "contains HTTP 200 Ok status code", + "contains the list of jurisdictions a user has access to" + ], + + "user": { + "username": "befta.caseworker.1.noprofile@gmail.com", + "password": "[[$CCD_BEFTA_CASEWORKER_1_NO_PROFILE_PWD]]" + }, + + "request": { + "_extends_": "Common_Request", + "queryParams": { + "access": "create" + } + }, + + "expectedResponse": { + "_extends_": "Common_200_Response", + "body": { + "arrayInMap": [ + { + "__ordering__": "unordered" + }, + { + "id": "BEFTA_JURISDICTION_1", + "name": "BEFTA_JURISDICTION_1", + "description": "Content for the Test Jurisdiction.", + "caseTypes": [ + { + "__ordering__": "unordered" + }, + { + "id": "BEFTA_CASETYPE_1_1", + "description": "Create a case of type BEFTA_CASETYPE_1_1", + "version": null, + "name": "BEFTA Case Type 1 1", + "events": [ + { + "__ordering__": "unordered" + }, + { + "id": "REVIEW", + "name": "Review", + "description": null, + "pre_states": [ + "*" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + }, + { + "id": "UPDATE", + "name": "Update", + "description": null, + "pre_states": [ + "*" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + }, + { + "_extends_": "CaseworkerCaaAccessControlList" + } + ] + }, + { + "id": "COMPLETE", + "name": "Mark as done", + "description": null, + "pre_states": [ + "IN_PROGRESS" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + }, + { + "id": "STOP_PROGRESS", + "name": "Stop", + "description": null, + "pre_states": [ + "IN_PROGRESS" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + }, + { + "id": "START_PROGRESS", + "name": "Start", + "description": null, + "pre_states": [ + "TODO" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + }, + { + "id": "CREATE", + "name": "Create a new case", + "description": null, + "pre_states": [], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + } + ], + "states": [ + { + "__ordering__": "unordered", + "__elementId__": "id" + }, + { + "id": "TODO", + "name": "To do", + "description": null + }, + { + "id": "IN_PROGRESS", + "name": "In progress", + "description": null + }, + { + "id": "DONE", + "name": "Done", + "description": null + } + ], + "security_classification": null + }, + { + "id" : "BEFTA_CASETYPE_NO_READ", + "description" : "Create a case of type BEFTA_CASETYPE_NO_READ", + "version" : null, + "name" : "BEFTA Case Type No Read", + "events": [ + { + "__ordering__": "unordered" + }, + { + "id": "REVIEW", + "name": "Review", + "description": null, + "pre_states": [ + "*" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1NoReadAccessControlList" + } + ] + }, + { + "id": "UPDATE", + "name": "Update", + "description": null, + "pre_states": [ + "*" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1NoReadAccessControlList" + }, + { + "_extends_": "CaseworkerCaaNoReadAccessControlList" + } + ] + }, + { + "id": "COMPLETE", + "name": "Mark as done", + "description": null, + "pre_states": [ + "IN_PROGRESS" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1NoReadAccessControlList" + } + ] + }, + { + "id": "STOP_PROGRESS", + "name": "Stop", + "description": null, + "pre_states": [ + "IN_PROGRESS" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1NoReadAccessControlList" + } + ] + }, + { + "id": "START_PROGRESS", + "name": "Start", + "description": null, + "pre_states": [ + "TODO" + ], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1NoReadAccessControlList" + } + ] + }, + { + "id": "CREATE", + "name": "Create a new case", + "description": null, + "pre_states": [], + "acls": [ + { + "__ordering__": "unordered", + "__elementId__": "role" + }, + { + "_extends_": "CaseworkerBeftaJurisdiction1NoReadAccessControlList" + } + ] + } + ], + "states": [ + { + "__ordering__": "unordered", + "__elementId__": "id" + }, + { + "id": "TODO", + "name": "To do", + "description": null + }, + { + "id": "IN_PROGRESS", + "name": "In progress", + "description": null + }, + { + "id": "DONE", + "name": "Done", + "description": null + } + ], + "security_classification": null + }, + { + "id": "CASE_TYPE_WITH_NO_CASES", + "description": "Create a case of type CASE_TYPE_WITH_NO_CASES", + "version": null, + "name": "CT With No Cases -Don't Create", + "events": [ + { + "__ordering__": "unordered" + }, + { + "id": "REVIEW", + "name": "Review", + "description": null, + "pre_states": [ + "*" + ], + "acls": [ + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + }, + { + "id": "UPDATE", + "name": "Update", + "description": null, + "pre_states": [ + "*" + ], + "acls": [ + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + }, + { + "id": "COMPLETE", + "name": "Mark as done", + "description": null, + "pre_states": [ + "IN_PROGRESS" + ], + "acls": [ + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + }, + { + "id": "STOP_PROGRESS", + "name": "Stop", + "description": null, + "pre_states": [ + "IN_PROGRESS" + ], + "acls": [ + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + }, + { + "id": "START_PROGRESS", + "name": "Start", + "description": null, + "pre_states": [ + "TODO" + ], + "acls": [ + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + }, + { + "id": "CREATE", + "name": "Create a new case", + "description": null, + "pre_states": [], + "acls": [ + { + "_extends_": "CaseworkerBeftaJurisdiction1AccessControlList" + } + ] + } + ], + "states": [ + { + "__ordering__": "unordered" + }, + { + "id": "TODO", + "name": "To do", + "description": null + }, + { + "id": "IN_PROGRESS", + "name": "In progress", + "description": null + }, + { + "id": "DONE", + "name": "Done", + "description": null + } + ], + "security_classification": null + }, + { + "id" : "ROLE_TO_ACCESS_PROFILE_CASE_TYPE", + "description" : "For testing role to access profile case type", + "version" : null, + "name" : "RTAP_CASE_TYPE", + "security_classification" : null, + "events" : [ + { + "__ordering__": "unordered" + }, + { + "id" : "CREATE", + "name" : "Create a new case", + "description" : null, + "pre_states" : [ ], + "acls" : [ { + "create" : true, + "read" : true, + "update" : true, + "delete" : false, + "role" : "caseworker-caa" + } ] + } ], + "states" : [ + { + "__ordering__": "unordered" + }, + { + "id" : "TODO", + "name" : "To do", + "description" : null + } ] + }, + { + "id" : "CaseAccessGroups_Casetype", + "description" : "For testing Case Access Group", + "version" : null, + "name" : "CaseAccessGroups_Casetype", + "security_classification" : null, + "events" : [ + { + "__ordering__": "unordered" + }, + { + "id" : "updateCase", + "name" : "Update Case", + "description" : null, + "pre_states" : [ "CaseCreated" ], + "acls" : [ { + "create" : true, + "read" : true, + "update" : true, + "delete" : true, + "role" : "caseworker-befta_jurisdiction_1" + } ] + }, { + "id" : "createCase", + "name" : "Create a new case", + "description" : null, + "pre_states" : [ ], + "acls" : [ { + "create" : true, + "read" : true, + "update" : true, + "delete" : true, + "role" : "caseworker-befta_jurisdiction_1" + } ] + } ], + "states" : [ + { + "__ordering__": "unordered" + }, + { + "id" : "CaseCreated", + "name" : "Create Case", + "description" : null + }, { + "id" : "CaseUpdated", + "name" : "Update Case", + "description" : null + } ] + } + ] + } + ] + } + } +} diff --git a/src/main/java/uk/gov/hmcts/ccd/data/casedetails/JurisdictionMapper.java b/src/main/java/uk/gov/hmcts/ccd/data/casedetails/JurisdictionMapper.java index 35785b0d29..c38cb694d4 100644 --- a/src/main/java/uk/gov/hmcts/ccd/data/casedetails/JurisdictionMapper.java +++ b/src/main/java/uk/gov/hmcts/ccd/data/casedetails/JurisdictionMapper.java @@ -2,9 +2,15 @@ import jakarta.inject.Named; import jakarta.inject.Singleton; +import uk.gov.hmcts.ccd.domain.model.aggregated.lite.CaseTypeLite; import uk.gov.hmcts.ccd.domain.model.aggregated.JurisdictionDisplayProperties; +import uk.gov.hmcts.ccd.domain.model.aggregated.lite.JurisdictionDisplayPropertiesLite; +import uk.gov.hmcts.ccd.domain.model.definition.CaseTypeDefinition; import uk.gov.hmcts.ccd.domain.model.definition.JurisdictionDefinition; +import java.util.ArrayList; +import java.util.List; + @Named @Singleton public class JurisdictionMapper { @@ -16,4 +22,23 @@ public JurisdictionDisplayProperties toResponse(JurisdictionDefinition jurisdict result.setCaseTypeDefinitions(jurisdictionDefinition.getCaseTypeDefinitions()); return result; } + + public JurisdictionDisplayPropertiesLite toLiteResponse(JurisdictionDefinition jurisdictionDefinition) { + JurisdictionDisplayPropertiesLite result = new JurisdictionDisplayPropertiesLite(); + result.setId(jurisdictionDefinition.getId()); + result.setName(jurisdictionDefinition.getName()); + result.setDescription(jurisdictionDefinition.getDescription()); + result.setCaseTypeLiteDefinitions(toCaseTypeResponse(jurisdictionDefinition.getCaseTypeDefinitions())); + return result; + } + + public List toCaseTypeResponse(List caseTypeDefinitions) { + List list = new ArrayList<>(); + if (caseTypeDefinitions != null) { + return caseTypeDefinitions.stream() + .map(CaseTypeLite::new) + .toList(); + } + return list; + } } diff --git a/src/main/java/uk/gov/hmcts/ccd/data/user/UserService.java b/src/main/java/uk/gov/hmcts/ccd/data/user/UserService.java index 5195c4d092..85afeb7af8 100644 --- a/src/main/java/uk/gov/hmcts/ccd/data/user/UserService.java +++ b/src/main/java/uk/gov/hmcts/ccd/data/user/UserService.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.ccd.data.user; +import jakarta.inject.Inject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; @@ -9,12 +10,12 @@ import uk.gov.hmcts.ccd.data.definition.CaseDefinitionRepository; import uk.gov.hmcts.ccd.domain.model.aggregated.IdamProperties; import uk.gov.hmcts.ccd.domain.model.aggregated.JurisdictionDisplayProperties; +import uk.gov.hmcts.ccd.domain.model.aggregated.lite.JurisdictionDisplayPropertiesLite; import uk.gov.hmcts.ccd.domain.model.aggregated.UserDefault; import uk.gov.hmcts.ccd.domain.model.aggregated.UserProfile; import uk.gov.hmcts.ccd.domain.model.aggregated.WorkbasketDefault; import uk.gov.hmcts.ccd.domain.model.definition.JurisdictionDefinition; -import jakarta.inject.Inject; import java.util.ArrayList; import java.util.List; @@ -64,9 +65,11 @@ private UserProfile createUserProfile(IdamProperties idamProperties, List jurisdictionsDefinition) { JurisdictionDisplayProperties[] resultJurisdictions = toResponse(jurisdictionsDefinition); + JurisdictionDisplayPropertiesLite[] liteJurisdictions = toLiteResponse(jurisdictionsDefinition); UserProfile userProfile = new UserProfile(); userProfile.setJurisdictions(resultJurisdictions); + userProfile.setLiteJurisdictions(liteJurisdictions); userProfile.getUser().setIdamProperties(idamProperties); UserDefault userDefault = userRepository.getUserDefaultSettings(userId); @@ -86,6 +89,11 @@ private JurisdictionDisplayProperties[] toResponse(List .toArray(JurisdictionDisplayProperties[]::new); } + private JurisdictionDisplayPropertiesLite[] toLiteResponse(List jurisdictionsDefinition) { + return jurisdictionsDefinition.stream().map(jurisdictionMapper::toLiteResponse) + .toArray(JurisdictionDisplayPropertiesLite[]::new); + } + public List getUserRolesJurisdictions() { return userRepository.getCaseworkerUserRolesJurisdictions(); } diff --git a/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/JurisdictionDisplayProperties.java b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/JurisdictionDisplayProperties.java index 526b244abd..c20b242cbf 100644 --- a/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/JurisdictionDisplayProperties.java +++ b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/JurisdictionDisplayProperties.java @@ -1,47 +1,19 @@ package uk.gov.hmcts.ccd.domain.model.aggregated; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; +import uk.gov.hmcts.ccd.domain.model.definition.CaseTypeDefinition; + import java.util.ArrayList; import java.util.List; -import uk.gov.hmcts.ccd.domain.model.definition.CaseTypeDefinition; +@Setter +@Getter public class JurisdictionDisplayProperties { private String id; private String name; private String description; - - private List caseTypeDefinitions = new ArrayList<>(); - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - @JsonProperty("caseTypes") - public List getCaseTypeDefinitions() { - return caseTypeDefinitions; - } - - public void setCaseTypeDefinitions(List caseTypeDefinitions) { - this.caseTypeDefinitions = caseTypeDefinitions; - } + private List caseTypeDefinitions = new ArrayList<>(); } diff --git a/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/UserProfile.java b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/UserProfile.java index ba49baafc2..13d86a46d8 100644 --- a/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/UserProfile.java +++ b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/UserProfile.java @@ -1,47 +1,22 @@ package uk.gov.hmcts.ccd.domain.model.aggregated; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; import lombok.ToString; +import uk.gov.hmcts.ccd.domain.model.aggregated.lite.JurisdictionDisplayPropertiesLite; +@Setter +@Getter @ToString public class UserProfile { private User user = new User(); private String[] channels; private JurisdictionDisplayProperties[] jurisdictions; + @JsonIgnore + private JurisdictionDisplayPropertiesLite[] liteJurisdictions; @JsonProperty("default") private DefaultSettings defaultSettings = new DefaultSettings(); - - public String[] getChannels() { - return channels; - } - - public void setChannels(String[] channels) { - this.channels = channels; - } - - public JurisdictionDisplayProperties[] getJurisdictions() { - return jurisdictions; - } - - public void setJurisdictions(JurisdictionDisplayProperties[] jurisdictions) { - this.jurisdictions = jurisdictions; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - public DefaultSettings getDefaultSettings() { - return defaultSettings; - } - - public void setDefaultSettings(DefaultSettings defaultSettings) { - this.defaultSettings = defaultSettings; - } - } diff --git a/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseEventLite.java b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseEventLite.java new file mode 100644 index 0000000000..7297b7c6e2 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseEventLite.java @@ -0,0 +1,39 @@ +package uk.gov.hmcts.ccd.domain.model.aggregated.lite; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import uk.gov.hmcts.ccd.domain.model.definition.AccessControlList; +import uk.gov.hmcts.ccd.domain.model.definition.Copyable; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@Setter +@Getter +@ToString +public class CaseEventLite implements Serializable, Copyable { + + private String id = null; + private String name = null; + private String description = null; + @JsonProperty("pre_states") + private List preStates = new ArrayList<>(); + @JsonProperty("acls") + private List accessControlLists; + + @JsonIgnore + @Override + public CaseEventLite createCopy() { + CaseEventLite copy = new CaseEventLite(); + copy.setId(this.getId()); + copy.setName(this.getName()); + copy.setDescription(this.getDescription()); + copy.setPreStates(this.getPreStates() != null ? new ArrayList<>(this.getPreStates()) : null); + copy.setAccessControlLists(createACLCopyList(this.getAccessControlLists())); + return copy; + } +} diff --git a/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseStateLite.java b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseStateLite.java new file mode 100644 index 0000000000..4c857dc752 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseStateLite.java @@ -0,0 +1,27 @@ +package uk.gov.hmcts.ccd.domain.model.aggregated.lite; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Getter; +import lombok.Setter; +import uk.gov.hmcts.ccd.domain.model.definition.Copyable; + +import java.io.Serializable; + +@Setter +@Getter +public class CaseStateLite implements Serializable, Copyable { + + private String id = null; + private String name = null; + private String description = null; + + @JsonIgnore + @Override + public CaseStateLite createCopy() { + CaseStateLite copy = new CaseStateLite(); + copy.setId(this.getId()); + copy.setName(this.getName()); + copy.setDescription(this.getDescription()); + return copy; + } +} diff --git a/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseTypeLite.java b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseTypeLite.java new file mode 100644 index 0000000000..41df62af56 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseTypeLite.java @@ -0,0 +1,87 @@ +package uk.gov.hmcts.ccd.domain.model.aggregated.lite; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.collect.Lists; +import lombok.Getter; +import lombok.ToString; +import uk.gov.hmcts.ccd.data.casedetails.SecurityClassification; +import uk.gov.hmcts.ccd.domain.model.definition.CaseEventDefinition; +import uk.gov.hmcts.ccd.domain.model.definition.CaseStateDefinition; +import uk.gov.hmcts.ccd.domain.model.definition.CaseTypeDefinition; +import uk.gov.hmcts.ccd.domain.model.definition.Version; + +import java.io.Serializable; +import java.util.List; + +@ToString +@Getter +public class CaseTypeLite implements Serializable { + + private final String id; + private final String description; + private final Version version; + private final String name; + @JsonProperty("security_classification") + private final SecurityClassification securityClassification; + private final List events; + private final List states; + + public CaseTypeLite(CaseTypeDefinition caseTypeDefinition) { + this.id = caseTypeDefinition.getId(); + this.description = caseTypeDefinition.getDescription(); + this.version = caseTypeDefinition.getVersion(); + this.name = caseTypeDefinition.getName(); + this.securityClassification = caseTypeDefinition.getSecurityClassification(); + this.events = createLiteEvents(caseTypeDefinition.getEvents()); + this.states = createLiteStates(caseTypeDefinition.getStates()); + } + + @JsonCreator + public CaseTypeLite( + @JsonProperty("id") String id, + @JsonProperty("description") String description, + @JsonProperty("version") Version version, + @JsonProperty("name") String name, + @JsonProperty("security_classification") SecurityClassification securityClassification, + @JsonProperty("events") List events, + @JsonProperty("states") List states) { + this.id = id; + this.description = description; + this.version = version; + this.name = name; + this.securityClassification = securityClassification; + this.events = createLiteEvents(events); + this.states = createLiteStates(states); + } + + private List createLiteEvents(List events) { + if (events != null) { + return events.stream() + .map(event -> { + CaseEventLite caseEventLite = new CaseEventLite(); + caseEventLite.setId(event.getId()); + caseEventLite.setName(event.getName()); + caseEventLite.setDescription(event.getDescription()); + caseEventLite.setPreStates(event.getPreStates()); + caseEventLite.setAccessControlLists(event.getAccessControlLists()); + return caseEventLite; + }).toList(); + } + return Lists.newArrayList(); + } + + private List createLiteStates(List states) { + if (states != null) { + return states.stream() + .map(state -> { + CaseStateLite caseStateLite = new CaseStateLite(); + caseStateLite.setId(state.getId()); + caseStateLite.setName(state.getName()); + caseStateLite.setDescription(state.getDescription()); + return caseStateLite; + }).toList(); + } + return Lists.newArrayList(); + } +} diff --git a/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/JurisdictionDisplayPropertiesLite.java b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/JurisdictionDisplayPropertiesLite.java new file mode 100644 index 0000000000..4e8806181c --- /dev/null +++ b/src/main/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/JurisdictionDisplayPropertiesLite.java @@ -0,0 +1,19 @@ +package uk.gov.hmcts.ccd.domain.model.aggregated.lite; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; + +@Setter +@Getter +public class JurisdictionDisplayPropertiesLite { + + private String id; + private String name; + private String description; + @JsonProperty("caseTypes") + private List caseTypeLiteDefinitions = new ArrayList<>(); +} diff --git a/src/main/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpoint.java b/src/main/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpoint.java index 4b966cc632..0ced9910a3 100644 --- a/src/main/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpoint.java +++ b/src/main/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpoint.java @@ -1,9 +1,9 @@ package uk.gov.hmcts.ccd.endpoint.ui; import com.google.common.collect.Maps; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import jakarta.inject.Inject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; @@ -18,10 +18,11 @@ import uk.gov.hmcts.ccd.auditlog.LogAudit; import uk.gov.hmcts.ccd.data.casedetails.search.FieldMapSanitizeOperation; import uk.gov.hmcts.ccd.data.casedetails.search.MetaData; -import uk.gov.hmcts.ccd.domain.model.aggregated.CaseUpdateViewEvent; import uk.gov.hmcts.ccd.domain.model.aggregated.CaseHistoryView; +import uk.gov.hmcts.ccd.domain.model.aggregated.CaseUpdateViewEvent; import uk.gov.hmcts.ccd.domain.model.aggregated.CaseView; import uk.gov.hmcts.ccd.domain.model.aggregated.JurisdictionDisplayProperties; +import uk.gov.hmcts.ccd.domain.model.aggregated.lite.JurisdictionDisplayPropertiesLite; import uk.gov.hmcts.ccd.domain.model.definition.AccessControlList; import uk.gov.hmcts.ccd.domain.model.definition.CaseTypeDefinition; import uk.gov.hmcts.ccd.domain.model.search.SearchInput; @@ -44,14 +45,13 @@ import uk.gov.hmcts.ccd.endpoint.exceptions.ResourceNotFoundException; import uk.gov.hmcts.ccd.v2.V2; -import jakarta.inject.Inject; import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; -import java.util.Arrays; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -153,6 +153,27 @@ public List getJurisdictions(@RequestParam(value } } + @SuppressWarnings("java:S6856") + @GetMapping(value = "/caseworkers/{uid}/jurisdictions-lite") + @Operation(summary = "Get jurisdictions available to the user") + @ApiResponse(responseCode = "200", description = "List of jurisdictions for the given access criteria") + @ApiResponse(responseCode = "404", description = "No jurisdictions found for given access criteria") + public List getJurisdictionsLite(@RequestParam(value = "access") String access) { + if (accessMap.get(access) == null) { + throw new BadRequestException("Access can only be 'create', 'read' or 'update'"); + } + JurisdictionDisplayPropertiesLite[] liteJurisdictions = getUserProfileOperation + .execute(accessMap.get(access)).getLiteJurisdictions(); + List jurisdictions = liteJurisdictions == null + ? new ArrayList<>() + : Arrays.asList(liteJurisdictions); + if (jurisdictions.isEmpty()) { + throw new ResourceNotFoundException("No jurisdictions found"); + } else { + return jurisdictions; + } + } + @RequestMapping(value = "/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases", method = RequestMethod.GET) @Operation(summary = "Get case data with UI layout") @@ -207,11 +228,11 @@ public SearchInput[] findSearchInputDetails(@PathVariable("uid") final String ui method = RequestMethod.GET) @Operation(summary = "Get Workbasket Input details") @ApiResponse( - responseCode = "200", + responseCode = "200", description = "Workbasket Input data found for the given case type and jurisdiction" ) @ApiResponse( - responseCode = "404", + responseCode = "404", description = "No Workbasket Input found for the given case type and jurisdiction" ) public WorkbasketInput[] findWorkbasketInputDetails(@PathVariable("uid") final String uid, diff --git a/src/test/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseEventLiteTest.java b/src/test/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseEventLiteTest.java new file mode 100644 index 0000000000..b468760d1a --- /dev/null +++ b/src/test/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseEventLiteTest.java @@ -0,0 +1,191 @@ +package uk.gov.hmcts.ccd.domain.model.aggregated.lite; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.ccd.domain.model.definition.AccessControlList; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@DisplayName("CaseEventLite Test") +class CaseEventLiteTest { + + private CaseEventLite caseEventLite; + + @BeforeEach + void setUp() { + caseEventLite = new CaseEventLite(); + } + + @Test + @DisplayName("Should create CaseEventLite with default values") + void shouldCreateCaseEventLiteWithDefaultValues() { + assertNotNull(caseEventLite); + assertNull(caseEventLite.getId()); + assertNull(caseEventLite.getName()); + assertNull(caseEventLite.getDescription()); + assertNotNull(caseEventLite.getPreStates()); + assertTrue(caseEventLite.getPreStates().isEmpty()); + assertNull(caseEventLite.getAccessControlLists()); + } + + @Test + @DisplayName("Should set and get id") + void shouldSetAndGetId() { + String id = "EVENT_1"; + caseEventLite.setId(id); + assertEquals(id, caseEventLite.getId()); + } + + @Test + @DisplayName("Should set and get name") + void shouldSetAndGetName() { + String name = "Test Event"; + caseEventLite.setName(name); + assertEquals(name, caseEventLite.getName()); + } + + @Test + @DisplayName("Should set and get description") + void shouldSetAndGetDescription() { + String description = "Test Event Description"; + caseEventLite.setDescription(description); + assertEquals(description, caseEventLite.getDescription()); + } + + @Test + @DisplayName("Should set and get preStates") + void shouldSetAndGetPreStates() { + List preStates = Arrays.asList("State1", "State2", "State3"); + caseEventLite.setPreStates(preStates); + assertEquals(preStates, caseEventLite.getPreStates()); + assertEquals(3, caseEventLite.getPreStates().size()); + } + + @Test + @DisplayName("Should handle null preStates") + void shouldHandleNullPreStates() { + caseEventLite.setPreStates(null); + assertNull(caseEventLite.getPreStates()); + } + + @Test + @DisplayName("Should set and get accessControlLists") + void shouldSetAndGetAccessControlLists() { + final List acls = new ArrayList<>(); + AccessControlList acl1 = new AccessControlList(); + acl1.setAccessProfile("profile1"); + acl1.setCreate(true); + acl1.setRead(true); + acls.add(acl1); + + AccessControlList acl2 = new AccessControlList(); + acl2.setAccessProfile("profile2"); + acl2.setUpdate(true); + acl2.setDelete(true); + acls.add(acl2); + + caseEventLite.setAccessControlLists(acls); + assertEquals(acls, caseEventLite.getAccessControlLists()); + assertEquals(2, caseEventLite.getAccessControlLists().size()); + } + + @Test + @DisplayName("Should handle null accessControlLists") + void shouldHandleNullAccessControlLists() { + caseEventLite.setAccessControlLists(null); + assertNull(caseEventLite.getAccessControlLists()); + } + + @Test + @DisplayName("Should create copy of CaseEventLite") + void shouldCreateCopyOfCaseEventLite() { + caseEventLite.setId("EVENT_1"); + caseEventLite.setName("Test Event"); + caseEventLite.setDescription("Test Description"); + caseEventLite.setPreStates(Arrays.asList("State1", "State2")); + + List acls = new ArrayList<>(); + AccessControlList acl = new AccessControlList(); + acl.setAccessProfile("profile1"); + acl.setCreate(true); + acls.add(acl); + caseEventLite.setAccessControlLists(acls); + + CaseEventLite copy = caseEventLite.createCopy(); + + assertNotNull(copy); + assertNotSame(caseEventLite, copy); + assertEquals(caseEventLite.getId(), copy.getId()); + assertEquals(caseEventLite.getName(), copy.getName()); + assertEquals(caseEventLite.getDescription(), copy.getDescription()); + assertEquals(caseEventLite.getPreStates(), copy.getPreStates()); + assertNotNull(copy.getAccessControlLists()); + assertEquals(caseEventLite.getAccessControlLists().size(), copy.getAccessControlLists().size()); + } + + @Test + @DisplayName("Should create copy with null preStates") + void shouldCreateCopyWithNullPreStates() { + caseEventLite.setId("EVENT_1"); + caseEventLite.setName("Test Event"); + caseEventLite.setPreStates(null); + + CaseEventLite copy = caseEventLite.createCopy(); + + assertNotNull(copy); + assertNull(copy.getPreStates()); + } + + @Test + @DisplayName("Should create copy with null accessControlLists") + void shouldCreateCopyWithNullAccessControlLists() { + caseEventLite.setId("EVENT_1"); + caseEventLite.setName("Test Event"); + caseEventLite.setAccessControlLists(null); + + CaseEventLite copy = caseEventLite.createCopy(); + + assertNotNull(copy); + assertNull(copy.getAccessControlLists()); + } + + @Test + @DisplayName("Should create copy with empty preStates") + void shouldCreateCopyWithEmptyPreStates() { + caseEventLite.setId("EVENT_1"); + caseEventLite.setPreStates(new ArrayList<>()); + + CaseEventLite copy = caseEventLite.createCopy(); + + assertNotNull(copy); + assertNotNull(copy.getPreStates()); + assertTrue(copy.getPreStates().isEmpty()); + } + + @Test + @DisplayName("Should create independent copy - modifying copy should not affect original") + void shouldCreateIndependentCopy() { + caseEventLite.setId("EVENT_1"); + caseEventLite.setName("Original Name"); + List preStates = new ArrayList<>(Arrays.asList("State1")); + caseEventLite.setPreStates(preStates); + + CaseEventLite copy = caseEventLite.createCopy(); + copy.setName("Modified Name"); + copy.getPreStates().add("State2"); + + assertEquals("Original Name", caseEventLite.getName()); + assertEquals(1, caseEventLite.getPreStates().size()); + assertEquals("Modified Name", copy.getName()); + assertEquals(2, copy.getPreStates().size()); + } +} diff --git a/src/test/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseStateLiteTest.java b/src/test/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseStateLiteTest.java new file mode 100644 index 0000000000..7d8899fb5a --- /dev/null +++ b/src/test/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseStateLiteTest.java @@ -0,0 +1,130 @@ +package uk.gov.hmcts.ccd.domain.model.aggregated.lite; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; + +@DisplayName("CaseStateLite Test") +class CaseStateLiteTest { + + private CaseStateLite caseStateLite; + + @BeforeEach + void setUp() { + caseStateLite = new CaseStateLite(); + } + + @Test + @DisplayName("Should create CaseStateLite with default values") + void shouldCreateCaseStateLiteWithDefaultValues() { + assertNotNull(caseStateLite); + assertNull(caseStateLite.getId()); + assertNull(caseStateLite.getName()); + assertNull(caseStateLite.getDescription()); + } + + @Test + @DisplayName("Should set and get id") + void shouldSetAndGetId() { + String id = "STATE_1"; + caseStateLite.setId(id); + assertEquals(id, caseStateLite.getId()); + } + + @Test + @DisplayName("Should set and get name") + void shouldSetAndGetName() { + String name = "Test State"; + caseStateLite.setName(name); + assertEquals(name, caseStateLite.getName()); + } + + @Test + @DisplayName("Should set and get description") + void shouldSetAndGetDescription() { + String description = "Test State Description"; + caseStateLite.setDescription(description); + assertEquals(description, caseStateLite.getDescription()); + } + + @Test + @DisplayName("Should set all properties") + void shouldSetAllProperties() { + String id = "STATE_1"; + String name = "Test State"; + String description = "Test Description"; + + caseStateLite.setId(id); + caseStateLite.setName(name); + caseStateLite.setDescription(description); + + assertEquals(id, caseStateLite.getId()); + assertEquals(name, caseStateLite.getName()); + assertEquals(description, caseStateLite.getDescription()); + } + + @Test + @DisplayName("Should create copy of CaseStateLite") + void shouldCreateCopyOfCaseStateLite() { + caseStateLite.setId("STATE_1"); + caseStateLite.setName("Test State"); + caseStateLite.setDescription("Test Description"); + + CaseStateLite copy = caseStateLite.createCopy(); + + assertNotNull(copy); + assertNotSame(caseStateLite, copy); + assertEquals(caseStateLite.getId(), copy.getId()); + assertEquals(caseStateLite.getName(), copy.getName()); + assertEquals(caseStateLite.getDescription(), copy.getDescription()); + } + + @Test + @DisplayName("Should create copy with null values") + void shouldCreateCopyWithNullValues() { + caseStateLite.setId(null); + caseStateLite.setName(null); + caseStateLite.setDescription(null); + + CaseStateLite copy = caseStateLite.createCopy(); + + assertNotNull(copy); + assertNull(copy.getId()); + assertNull(copy.getName()); + assertNull(copy.getDescription()); + } + + @Test + @DisplayName("Should create independent copy - modifying copy should not affect original") + void shouldCreateIndependentCopy() { + caseStateLite.setId("STATE_1"); + caseStateLite.setName("Original Name"); + caseStateLite.setDescription("Original Description"); + + CaseStateLite copy = caseStateLite.createCopy(); + copy.setName("Modified Name"); + copy.setDescription("Modified Description"); + + assertEquals("Original Name", caseStateLite.getName()); + assertEquals("Original Description", caseStateLite.getDescription()); + assertEquals("Modified Name", copy.getName()); + assertEquals("Modified Description", copy.getDescription()); + } + + @Test + @DisplayName("Should handle empty strings") + void shouldHandleEmptyStrings() { + caseStateLite.setId(""); + caseStateLite.setName(""); + caseStateLite.setDescription(""); + + assertEquals("", caseStateLite.getId()); + assertEquals("", caseStateLite.getName()); + assertEquals("", caseStateLite.getDescription()); + } +} diff --git a/src/test/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseTypeLiteTest.java b/src/test/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseTypeLiteTest.java new file mode 100644 index 0000000000..054a34e12e --- /dev/null +++ b/src/test/java/uk/gov/hmcts/ccd/domain/model/aggregated/lite/CaseTypeLiteTest.java @@ -0,0 +1,297 @@ +package uk.gov.hmcts.ccd.domain.model.aggregated.lite; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.ccd.data.casedetails.SecurityClassification; +import uk.gov.hmcts.ccd.domain.model.definition.AccessControlList; +import uk.gov.hmcts.ccd.domain.model.definition.CaseEventDefinition; +import uk.gov.hmcts.ccd.domain.model.definition.CaseStateDefinition; +import uk.gov.hmcts.ccd.domain.model.definition.CaseTypeDefinition; +import uk.gov.hmcts.ccd.domain.model.definition.JurisdictionDefinition; +import uk.gov.hmcts.ccd.domain.model.definition.Version; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +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 org.junit.jupiter.api.Assertions.assertTrue; + +@DisplayName("CaseTypeLite Test") +class CaseTypeLiteTest { + + private CaseTypeDefinition caseTypeDefinition; + private Version version; + + @BeforeEach + void setUp() { + version = new Version(); + version.setNumber(1); + + JurisdictionDefinition jurisdictionDefinition = new JurisdictionDefinition(); + jurisdictionDefinition.setId("TEST_JURISDICTION"); + jurisdictionDefinition.setName("Test Jurisdiction"); + + caseTypeDefinition = new CaseTypeDefinition(); + caseTypeDefinition.setId("TEST_CASE_TYPE"); + caseTypeDefinition.setName("Test Case Type"); + caseTypeDefinition.setDescription("Test Description"); + caseTypeDefinition.setVersion(version); + caseTypeDefinition.setJurisdictionDefinition(jurisdictionDefinition); + caseTypeDefinition.setSecurityClassification(SecurityClassification.PUBLIC); + } + + @Test + @DisplayName("Should create CaseTypeLite from CaseTypeDefinition") + void shouldCreateCaseTypeLiteFromCaseTypeDefinition() { + CaseTypeLite caseTypeLite = new CaseTypeLite(caseTypeDefinition); + + assertNotNull(caseTypeLite); + assertEquals(caseTypeDefinition.getId(), caseTypeLite.getId()); + assertEquals(caseTypeDefinition.getName(), caseTypeLite.getName()); + assertEquals(caseTypeDefinition.getDescription(), caseTypeLite.getDescription()); + assertEquals(caseTypeDefinition.getVersion(), caseTypeLite.getVersion()); + assertEquals(caseTypeDefinition.getSecurityClassification(), caseTypeLite.getSecurityClassification()); + assertNotNull(caseTypeLite.getEvents()); + assertNotNull(caseTypeLite.getStates()); + } + + @Test + @DisplayName("Should create CaseTypeLite with events and states from CaseTypeDefinition") + void shouldCreateCaseTypeLiteWithEventsAndStates() { + // Create states + CaseStateDefinition state1 = new CaseStateDefinition(); + state1.setId("STATE_1"); + state1.setName("State 1"); + state1.setDescription("State 1 Description"); + + CaseStateDefinition state2 = new CaseStateDefinition(); + state2.setId("STATE_2"); + state2.setName("State 2"); + state2.setDescription("State 2 Description"); + + caseTypeDefinition.getStates().add(state1); + caseTypeDefinition.getStates().add(state2); + + // Create events + CaseEventDefinition event1 = new CaseEventDefinition(); + event1.setId("EVENT_1"); + event1.setName("Event 1"); + event1.setDescription("Event 1 Description"); + event1.setPreStates(Arrays.asList("State1", "State2")); + + CaseEventDefinition event2 = new CaseEventDefinition(); + event2.setId("EVENT_2"); + event2.setName("Event 2"); + event2.setDescription("Event 2 Description"); + + List acls = new ArrayList<>(); + AccessControlList acl = new AccessControlList(); + acl.setAccessProfile("profile1"); + acl.setCreate(true); + acls.add(acl); + event1.setAccessControlLists(acls); + + caseTypeDefinition.getEvents().add(event1); + caseTypeDefinition.getEvents().add(event2); + + CaseTypeLite caseTypeLite = new CaseTypeLite(caseTypeDefinition); + + assertNotNull(caseTypeLite); + assertEquals(2, caseTypeLite.getEvents().size()); + assertEquals(2, caseTypeLite.getStates().size()); + + CaseEventLite eventLite1 = caseTypeLite.getEvents().get(0); + assertEquals("EVENT_1", eventLite1.getId()); + assertEquals("Event 1", eventLite1.getName()); + assertEquals("Event 1 Description", eventLite1.getDescription()); + assertEquals(Arrays.asList("State1", "State2"), eventLite1.getPreStates()); + assertNotNull(eventLite1.getAccessControlLists()); + assertEquals(1, eventLite1.getAccessControlLists().size()); + + CaseStateLite stateLite1 = caseTypeLite.getStates().get(0); + assertEquals("STATE_1", stateLite1.getId()); + assertEquals("State 1", stateLite1.getName()); + assertEquals("State 1 Description", stateLite1.getDescription()); + } + + @Test + @DisplayName("Should create CaseTypeLite with empty events and states when null") + void shouldCreateCaseTypeLiteWithEmptyListsWhenNull() { + caseTypeDefinition.setEvents(null); + caseTypeDefinition.setStates(null); + + CaseTypeLite caseTypeLite = new CaseTypeLite(caseTypeDefinition); + + assertNotNull(caseTypeLite); + assertNotNull(caseTypeLite.getEvents()); + assertTrue(caseTypeLite.getEvents().isEmpty()); + assertNotNull(caseTypeLite.getStates()); + assertTrue(caseTypeLite.getStates().isEmpty()); + } + + @Test + @DisplayName("Should create CaseTypeLite with empty events and states when empty lists") + void shouldCreateCaseTypeLiteWithEmptyLists() { + caseTypeDefinition.setEvents(new ArrayList<>()); + caseTypeDefinition.setStates(new ArrayList<>()); + + CaseTypeLite caseTypeLite = new CaseTypeLite(caseTypeDefinition); + + assertNotNull(caseTypeLite); + assertNotNull(caseTypeLite.getEvents()); + assertTrue(caseTypeLite.getEvents().isEmpty()); + assertNotNull(caseTypeLite.getStates()); + assertTrue(caseTypeLite.getStates().isEmpty()); + } + + @Test + @DisplayName("Should create CaseTypeLite using JsonCreator constructor") + void shouldCreateCaseTypeLiteUsingJsonCreator() { + List events = new ArrayList<>(); + CaseEventDefinition event = new CaseEventDefinition(); + event.setId("EVENT_1"); + event.setName("Event 1"); + events.add(event); + + List states = new ArrayList<>(); + CaseStateDefinition state = new CaseStateDefinition(); + state.setId("STATE_1"); + state.setName("State 1"); + states.add(state); + + CaseTypeLite caseTypeLite = new CaseTypeLite( + "TEST_ID", + "Test Description", + version, + "Test Name", + SecurityClassification.PUBLIC, + events, + states + ); + + assertNotNull(caseTypeLite); + assertEquals("TEST_ID", caseTypeLite.getId()); + assertEquals("Test Description", caseTypeLite.getDescription()); + assertEquals("Test Name", caseTypeLite.getName()); + assertEquals(version, caseTypeLite.getVersion()); + assertEquals(SecurityClassification.PUBLIC, caseTypeLite.getSecurityClassification()); + assertNotNull(caseTypeLite.getEvents()); + assertNotNull(caseTypeLite.getStates()); + } + + @Test + @DisplayName("Should create CaseTypeLite with null values using JsonCreator") + void shouldCreateCaseTypeLiteWithNullValuesUsingJsonCreator() { + CaseTypeLite caseTypeLite = new CaseTypeLite( + null, + null, + null, + null, + null, + null, + null + ); + + assertNotNull(caseTypeLite); + assertNull(caseTypeLite.getId()); + assertNull(caseTypeLite.getDescription()); + assertNull(caseTypeLite.getName()); + assertNull(caseTypeLite.getVersion()); + assertNull(caseTypeLite.getSecurityClassification()); + assertNotNull(caseTypeLite.getEvents()); + assertTrue(caseTypeLite.getEvents().isEmpty()); + assertNotNull(caseTypeLite.getStates()); + assertTrue(caseTypeLite.getStates().isEmpty()); + } + + @Test + @DisplayName("Should handle multiple events and states") + void shouldHandleMultipleEventsAndStates() { + // Add multiple states + for (int i = 1; i <= 3; i++) { + CaseStateDefinition state = new CaseStateDefinition(); + state.setId("STATE_" + i); + state.setName("State " + i); + caseTypeDefinition.getStates().add(state); + } + + // Add multiple events + for (int i = 1; i <= 5; i++) { + CaseEventDefinition event = new CaseEventDefinition(); + event.setId("EVENT_" + i); + event.setName("Event " + i); + caseTypeDefinition.getEvents().add(event); + } + + CaseTypeLite caseTypeLite = new CaseTypeLite(caseTypeDefinition); + + assertEquals(5, caseTypeLite.getEvents().size()); + assertEquals(3, caseTypeLite.getStates().size()); + } + + @Test + @DisplayName("Should preserve event preStates and accessControlLists using JsonCreator") + void shouldPreserveEventPreStatesAndAccessControlLists() { + // Test using JsonCreator constructor + CaseStateDefinition state = new CaseStateDefinition(); + state.setId("STATE_1"); + state.setName("State 1"); + + List states = new ArrayList<>(); + states.add(state); + + CaseEventDefinition event = new CaseEventDefinition(); + event.setId("EVENT_1"); + event.setName("Event 1"); + event.setPreStates(Arrays.asList("PreState1", "PreState2")); + + List acls = new ArrayList<>(); + AccessControlList acl1 = new AccessControlList(); + acl1.setAccessProfile("profile1"); + acl1.setCreate(true); + acls.add(acl1); + + AccessControlList acl2 = new AccessControlList(); + acl2.setAccessProfile("profile2"); + acl2.setRead(true); + acls.add(acl2); + + event.setAccessControlLists(acls); + + List events = new ArrayList<>(); + events.add(event); + + CaseTypeLite caseTypeLite = new CaseTypeLite( + "TEST_ID", + "Test Description", + version, + "Test Name", + SecurityClassification.PUBLIC, + events, + states + ); + + assertEquals(1, caseTypeLite.getEvents().size()); + CaseEventLite eventLite = caseTypeLite.getEvents().get(0); + assertEquals("EVENT_1", eventLite.getId()); + assertEquals("Event 1", eventLite.getName()); + assertEquals(Arrays.asList("PreState1", "PreState2"), eventLite.getPreStates()); + assertNotNull(eventLite.getAccessControlLists()); + assertEquals(2, eventLite.getAccessControlLists().size()); + assertEquals(1, caseTypeLite.getStates().size()); + } + + @Test + @DisplayName("Should handle all SecurityClassification values") + void shouldHandleAllSecurityClassificationValues() { + for (SecurityClassification classification : SecurityClassification.values()) { + caseTypeDefinition.setSecurityClassification(classification); + CaseTypeLite caseTypeLite = new CaseTypeLite(caseTypeDefinition); + assertEquals(classification, caseTypeLite.getSecurityClassification()); + } + } +} diff --git a/src/test/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpointIT.java b/src/test/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpointIT.java index a32c52e9a3..e99881c48b 100644 --- a/src/test/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpointIT.java +++ b/src/test/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpointIT.java @@ -31,6 +31,7 @@ import uk.gov.hmcts.ccd.domain.model.aggregated.CaseViewTab; import uk.gov.hmcts.ccd.domain.model.aggregated.CaseViewType; import uk.gov.hmcts.ccd.domain.model.aggregated.JurisdictionDisplayProperties; +import uk.gov.hmcts.ccd.domain.model.aggregated.lite.JurisdictionDisplayPropertiesLite; import uk.gov.hmcts.ccd.domain.model.aggregated.ProfileCaseState; import uk.gov.hmcts.ccd.domain.model.definition.CaseDetails; import uk.gov.hmcts.ccd.domain.model.definition.CaseFieldDefinition; @@ -52,6 +53,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; @@ -106,7 +108,11 @@ public class QueryEndpointIT extends WireMockBaseTest { private static final String GET_CASE_TYPES_READ_ACCESS = "/aggregated/caseworkers/0/jurisdictions/PROBATE/" + "case-types?access=read"; private static final String GET_JURISDICTIONS_READ_ACCESS = "/aggregated/caseworkers/0/jurisdictions?access=read"; - + public static final String JURISDICTIONS_LITE_ACCESS = "/aggregated/caseworkers/0/jurisdictions-lite?access="; + private static final String GET_JURISDICTIONS_LITE_READ_ACCESS = JURISDICTIONS_LITE_ACCESS + "read"; + private static final String GET_JURISDICTIONS_LITE_CREATE_ACCESS = JURISDICTIONS_LITE_ACCESS + "create"; + private static final String GET_JURISDICTIONS_LITE_UPDATE_ACCESS = JURISDICTIONS_LITE_ACCESS + "update"; + private static final String GET_JURISDICTIONS_LITE_INVALID_ACCESS = JURISDICTIONS_LITE_ACCESS + "invalid"; private static final String GET_CASE_TYPES_NO_ACCESS_PARAM = "/aggregated/caseworkers/0/jurisdictions/PROBATE/" + "case-types"; @@ -1582,6 +1588,83 @@ public void shouldGetJurisdictionsForReadAccess() throws Exception { ); } + @Test + @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_cases.sql"}) + public void shouldGetJurisdictionsLiteForReadAccess() throws Exception { + final MvcResult result = mockMvc.perform(get(GET_JURISDICTIONS_LITE_READ_ACCESS) + .contentType(JSON_CONTENT_TYPE) + .header(AUTHORIZATION, "Bearer user1")) + .andExpect(status().is(200)) + .andReturn(); + + final JurisdictionDisplayPropertiesLite[] jurisdictions = mapper.readValue( + result.getResponse().getContentAsString(), JurisdictionDisplayPropertiesLite[].class); + + // match against wiremock:`/src/test/resources/mappings/jurisdictions.json` + assertThat(jurisdictions.length, is(equalTo(4))); + + // find and verify 1 + JurisdictionDisplayPropertiesLite jurisdiction = Arrays.stream(jurisdictions) + .filter(item -> item.getId().equalsIgnoreCase("PROBATE")) + .findFirst().orElse(null); + assertNotNull(jurisdiction); + + assertAll( + () -> assertThat(jurisdiction.getCaseTypeLiteDefinitions().size(), is(equalTo(2))), + + () -> assertThat(jurisdiction.getCaseTypeLiteDefinitions().get(0), + hasProperty("id", equalTo("GrantOfRepresentation"))), + () -> assertThat(jurisdiction.getCaseTypeLiteDefinitions().get(0).getStates().size(), is(equalTo(2))), + () -> assertThat(jurisdiction.getCaseTypeLiteDefinitions().get(0).getEvents().size(), is(equalTo(2))), + + () -> assertThat(jurisdiction.getCaseTypeLiteDefinitions().get(1), + hasProperty("id", equalTo("TestAddressBookCaseCaseLinks"))), + () -> assertThat(jurisdiction.getCaseTypeLiteDefinitions().get(1).getStates().size(), is(equalTo(2))), + () -> assertThat(jurisdiction.getCaseTypeLiteDefinitions().get(1).getEvents().size(), is(equalTo(3))) + ); + } + + @Test + @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_cases.sql"}) + public void shouldGetJurisdictionsLiteForCreateAccess() throws Exception { + final MvcResult result = mockMvc.perform(get(GET_JURISDICTIONS_LITE_CREATE_ACCESS) + .contentType(JSON_CONTENT_TYPE) + .header(AUTHORIZATION, "Bearer user1")) + .andExpect(status().is(200)) + .andReturn(); + + final JurisdictionDisplayPropertiesLite[] jurisdictions = mapper.readValue( + result.getResponse().getContentAsString(), JurisdictionDisplayPropertiesLite[].class); + + assertNotNull("Jurisdictions should not be null", jurisdictions); + assertThat("Jurisdictions should not be empty", jurisdictions.length, is(greaterThan(0))); + } + + @Test + @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_cases.sql"}) + public void shouldGetJurisdictionsLiteForUpdateAccess() throws Exception { + final MvcResult result = mockMvc.perform(get(GET_JURISDICTIONS_LITE_UPDATE_ACCESS) + .contentType(JSON_CONTENT_TYPE) + .header(AUTHORIZATION, "Bearer user1")) + .andExpect(status().is(200)) + .andReturn(); + + final JurisdictionDisplayPropertiesLite[] jurisdictions = mapper.readValue( + result.getResponse().getContentAsString(), JurisdictionDisplayPropertiesLite[].class); + + assertNotNull("Jurisdictions should not be null", jurisdictions); + assertThat("Jurisdictions should not be empty", jurisdictions.length, is(greaterThan(0))); + } + + @Test + @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_cases.sql"}) + public void shouldReturnBadRequestForInvalidAccessInJurisdictionsLite() throws Exception { + mockMvc.perform(get(GET_JURISDICTIONS_LITE_INVALID_ACCESS) + .contentType(JSON_CONTENT_TYPE) + .header(AUTHORIZATION, "Bearer user1")) + .andExpect(status().is(400)); + } + @Test @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_case_event_history.sql"}) diff --git a/src/test/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpointTest.java b/src/test/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpointTest.java index 6b9a09f536..64d902c9b0 100644 --- a/src/test/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpointTest.java +++ b/src/test/java/uk/gov/hmcts/ccd/endpoint/ui/QueryEndpointTest.java @@ -1,40 +1,21 @@ package uk.gov.hmcts.ccd.endpoint.ui; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static uk.gov.hmcts.ccd.domain.model.callbacks.EventTokenProperties.JURISDICTION_ID; -import static uk.gov.hmcts.ccd.domain.model.search.CriteriaType.WORKBASKET; -import static uk.gov.hmcts.ccd.domain.service.common.AccessControlService.CAN_CREATE; -import static uk.gov.hmcts.ccd.domain.service.common.AccessControlService.CAN_READ; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import uk.gov.hmcts.ccd.data.casedetails.search.FieldMapSanitizeOperation; import uk.gov.hmcts.ccd.data.casedetails.search.MetaData; -import uk.gov.hmcts.ccd.domain.model.aggregated.CaseUpdateViewEvent; import uk.gov.hmcts.ccd.domain.model.aggregated.CaseHistoryView; +import uk.gov.hmcts.ccd.domain.model.aggregated.CaseUpdateViewEvent; import uk.gov.hmcts.ccd.domain.model.aggregated.CaseView; import uk.gov.hmcts.ccd.domain.model.aggregated.JurisdictionDisplayProperties; +import uk.gov.hmcts.ccd.domain.model.aggregated.lite.JurisdictionDisplayPropertiesLite; import uk.gov.hmcts.ccd.domain.model.aggregated.UserProfile; import uk.gov.hmcts.ccd.domain.model.search.SearchResultView; import uk.gov.hmcts.ccd.domain.model.search.WorkbasketInput; @@ -49,6 +30,31 @@ import uk.gov.hmcts.ccd.endpoint.exceptions.ResourceNotFoundException; import uk.gov.hmcts.ccd.v2.V2; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.ccd.domain.model.callbacks.EventTokenProperties.JURISDICTION_ID; +import static uk.gov.hmcts.ccd.domain.model.search.CriteriaType.WORKBASKET; +import static uk.gov.hmcts.ccd.domain.service.common.AccessControlService.CAN_CREATE; +import static uk.gov.hmcts.ccd.domain.service.common.AccessControlService.CAN_READ; +import static uk.gov.hmcts.ccd.domain.service.common.AccessControlService.CAN_UPDATE; + +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) class QueryEndpointTest { @Mock @@ -73,7 +79,6 @@ class QueryEndpointTest { @BeforeEach void setup() { - MockitoAnnotations.openMocks(this); queryEndpoint = new QueryEndpoint(getCaseViewOperation, getCaseHistoryViewOperation, getEventTriggerOperation, @@ -149,6 +154,89 @@ void shouldThrowBadRequest() { assertThrows(BadRequestException.class, () -> queryEndpoint.getJurisdictions("creat")); } + @Test + @DisplayName("Should call Get User Profile Operation for Lite Jurisdictions") + void shouldCallGetUserProfileOperationForLiteJurisdictions() { + JurisdictionDisplayPropertiesLite j1 = new JurisdictionDisplayPropertiesLite(); + j1.setId("J1"); + JurisdictionDisplayPropertiesLite j2 = new JurisdictionDisplayPropertiesLite(); + j2.setId("J2"); + JurisdictionDisplayPropertiesLite[] jurisdictions = {j1, j2}; + UserProfile userProfile = new UserProfile(); + userProfile.setLiteJurisdictions(jurisdictions); + doReturn(userProfile).when(getUserProfileOperation).execute(CAN_CREATE); + + List response = queryEndpoint.getJurisdictionsLite("create"); + + assertEquals(jurisdictions.length, response.size()); + assertThat(response.get(0), is(j1)); + assertThat(response.get(1), is(j2)); + verify(getUserProfileOperation, times(1)).execute(CAN_CREATE); + } + + @Test + @DisplayName("Should call Get User Profile Operation for Lite Jurisdictions with read access") + void shouldCallGetUserProfileOperationForLiteJurisdictionsWithReadAccess() { + JurisdictionDisplayPropertiesLite j1 = new JurisdictionDisplayPropertiesLite(); + j1.setId("J1"); + JurisdictionDisplayPropertiesLite[] jurisdictions = {j1}; + UserProfile userProfile = new UserProfile(); + userProfile.setLiteJurisdictions(jurisdictions); + doReturn(userProfile).when(getUserProfileOperation).execute(CAN_READ); + + List response = queryEndpoint.getJurisdictionsLite("read"); + + assertEquals(jurisdictions.length, response.size()); + assertThat(response.get(0), is(j1)); + verify(getUserProfileOperation, times(1)).execute(CAN_READ); + } + + @Test + @DisplayName("Should call Get User Profile Operation for Lite Jurisdictions with update access") + void shouldCallGetUserProfileOperationForLiteJurisdictionsWithUpdateAccess() { + JurisdictionDisplayPropertiesLite j1 = new JurisdictionDisplayPropertiesLite(); + j1.setId("J1"); + JurisdictionDisplayPropertiesLite[] jurisdictions = {j1}; + UserProfile userProfile = new UserProfile(); + userProfile.setLiteJurisdictions(jurisdictions); + doReturn(userProfile).when(getUserProfileOperation).execute(CAN_UPDATE); + + List response = queryEndpoint.getJurisdictionsLite("update"); + + assertEquals(jurisdictions.length, response.size()); + assertThat(response.get(0), is(j1)); + verify(getUserProfileOperation, times(1)).execute(CAN_UPDATE); + } + + @Test + @DisplayName("Should throw bad request Exception when access is not correct for Lite Jurisdictions") + void shouldThrowBadRequestForLiteJurisdictions() { + assertThrows(BadRequestException.class, () -> queryEndpoint.getJurisdictionsLite("creat")); + assertThrows(BadRequestException.class, () -> queryEndpoint.getJurisdictionsLite("invalid")); + assertThrows(BadRequestException.class, () -> queryEndpoint.getJurisdictionsLite("")); + } + + @Test + @DisplayName("Should throw ResourceNotFoundException when Lite Jurisdictions are empty") + void shouldThrowResourceNotFoundExceptionWhenLiteJurisdictionsAreEmpty() { + UserProfile userProfile = new UserProfile(); + userProfile.setLiteJurisdictions(new JurisdictionDisplayPropertiesLite[0]); + doReturn(userProfile).when(getUserProfileOperation).execute(CAN_READ); + + assertThrows(ResourceNotFoundException.class, () -> queryEndpoint.getJurisdictionsLite("read")); + } + + @Test + @DisplayName("Should throw ResourceNotFoundException when Lite Jurisdictions array is null") + void shouldThrowResourceNotFoundExceptionWhenLiteJurisdictionsAreNull() { + UserProfile userProfile = new UserProfile(); + userProfile.setLiteJurisdictions(null); + doReturn(userProfile).when(getUserProfileOperation).execute(CAN_READ); + + // null array is treated as empty, so should throw ResourceNotFoundException + assertThrows(ResourceNotFoundException.class, () -> queryEndpoint.getJurisdictionsLite("read")); + } + @Test @DisplayName("Should throw bad request Exception for invalid case type id") void shouldThrowBadRequestForInvalidCaseType() { @@ -188,7 +276,6 @@ void shouldCallSearchQueryOperation() { void shouldThrowBadRequestException() { String expectedErrorMessage = V2.Error.DATE_STRING_INVALID + "2021-06-28T::.000"; Map params = new HashMap<>(); - Map sanitised = new HashMap<>(); params.put("created_date", "2021-06-28T::.000"); params.put("last_modified_date", "2021-06-29T::.000"); @@ -202,7 +289,6 @@ void shouldThrowBadRequestException() { @DisplayName("Should should throw bad request exception for 3rd date") void shouldThrowBadRequestExceptionForLastDate() { Map params = new HashMap<>(); - Map sanitised = new HashMap<>(); params.put("created_date", "2021-06-28"); params.put("last_state_modified_date", "2021-06-29"); params.put("last_modified_date", "2021-06-30T::.000"); @@ -218,7 +304,6 @@ void shouldThrowBadRequestExceptionForLastDate() { @DisplayName("Should should throw bad request exception for 2nd and 3rd date") void shouldThrowBadRequestExceptionForTwoDates() { Map params = new HashMap<>(); - Map sanitised = new HashMap<>(); params.put("created_date", "2021-06-28"); params.put("last_state_modified_date", "2021-06-29T::.000"); params.put("last_modified_date", "2021-06-30T::.000");