Skip to content

Commit

Permalink
DTSAM-574 add optional roleLabel in RAS query APIs response (#2355)
Browse files Browse the repository at this point in the history
* DTSAM-574 add optional roleLabel in RAS query APIs response

* DTSAM-574 add sonar issue + tidy up

* DTSAM-574 fetch `RoleConfig` outside forEach & null check `RoleConfigRole`

* DTSAM-574 revert JacksonUtils.java changes

* DTSAM-574 update IT

* DTSAM-574 update `RoleAssignmentIntegrationTest.java` imports

* DTSAM-574 review feedback (move duplicate code to method)

* DTSAM-574 FTA added scenario for v1 & 2 query req with includeLabels (#2359)

* DTSAM-574 FTA added scenario for v1 query req with includeLabels

* DTSAM-574 FTA added scenario for v2 query req with includeLabels

* DTSAM-574 update S-185 FTA

* DTSAM-574 update S-185 FTA

* DTSAM-574 update S-185 FTA

* DTSAM-574 add `__ordering__` & `__elementId__` S-185 FTA

* DTSAM-574 update S-185

* DTSAM-574 delete RoleAssignments for s-185

* DTSAM-574 review feedback (generate UUID for reference)

* DTSAM-583 Fix non-running integration tests (#2361)

[DTSAM-583](https://tools.hmcts.net/jira/browse/DTSAM-583)

Fix non-running integration tests.

---------

Co-authored-by: Matt Nayler <57350764+mattnayler@users.noreply.github.com>
  • Loading branch information
abul-syed and mattnayler authored Oct 22, 2024
1 parent a3c5919 commit 9baaef1
Show file tree
Hide file tree
Showing 15 changed files with 677 additions and 152 deletions.
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ sourceSets {
}
}

idea {
module {
// config to allow Intelij to mark test source and resource files correctly to help linting tools
testSources.from(java.sourceSets.functionalTest.java.srcDirs)
testSources.from(java.sourceSets.integrationTest.java.srcDirs)
testSources.from(java.sourceSets.smokeTest.java.srcDirs)
testSources.from(java.sourceSets.contractTest.java.srcDirs)
testResources.from(java.sourceSets.functionalTest.resources.srcDirs)
testResources.from(java.sourceSets.integrationTest.resources.srcDirs)
testResources.from(java.sourceSets.smokeTest.resources.srcDirs)
testResources.from(java.sourceSets.contractTest.resources.srcDirs)
}
}

tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Werror"
}
Expand Down
12 changes: 12 additions & 0 deletions src/functionalTest/resources/features/F-006/F-006.feature
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,15 @@ Feature: F-006 : Post Role Assignments Query Request
Then a positive response is received,
And the response has all other details as expected,
And a successful call [to delete role assignments just created above] as in [S-087_DeleteDataForMultipleRoleAssignments].

@S-088
Scenario: must successfully receive Role Assignments including role label with one query param
Given a user with [an active IDAM profile with full permissions],
And a successful call [to create a role assignment for an actor] as in [CreationDataForRoleAssignment],
When a request is prepared with appropriate values,
And the request [contains one search query param]
And the request [has includeLabels request param set to true]
And it is submitted to call the [Post Role Assignments Query Request] operation of [Role Assignment Service],
Then a positive response is received,
And the response has all other details as expected,
And a successful call [to delete role assignments just created above] as in [F-006_DeleteDataForMultipleRoleAssignments].
30 changes: 30 additions & 0 deletions src/functionalTest/resources/features/F-006/S-088.td.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"title": "must successfully receive Role Assignments including role label with one query param",
"_guid_": "S-088",
"_extends_": "F-006_Test_Data_Base",
"specs": [
"contains one search query param",
"has includeLabels request param set to true"
],

"request": {
"queryParams": {
"includeLabels": "true"
},
"body": {
"actorId": ["${[scenarioContext][childContexts][CreationDataForRoleAssignment][testData][request][body][roleRequest][reference]}"]
}
},
"expectedResponse": {
"_extends_": "Common_200_Response",
"body": {
"roleAssignmentResponse" : [
{
"_extends_": "ResponseRoleAssignment",
"actorId": "${}${[scenarioContext][testData][request][body][actorId][0]}",
"roleLabel": "Judge"
}
]
}
}
}
12 changes: 12 additions & 0 deletions src/functionalTest/resources/features/F-009/F-009.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ Feature: F-009 : Post Role Assignments Advance Query Request
And the response has all other details as expected,
And a successful call [to delete role assignments just created above] as in [S-183_DeleteDataForMultipleRoleAssignments].

@S-185
Scenario: must successfully receive Role Assignments with page size including role label
Given a user with [an active IDAM profile with full permissions],
And a successful call [to create a role assignment for an actor] as in [S-185_CreationDataForRoleAssignment],
When a request is prepared with appropriate values,
And the request [contains multiple Role Assignments with a page size]
And the request [has includeLabels request param set to true]
And it is submitted to call the [Post Role Assignments Query Request] operation of [Role Assignment Service],
Then a positive response is received,
And the response has all other details as expected,
And a successful call [to delete role assignments just created above] as in [S-185_DeleteDataForMultipleRoleAssignments].

@S-186
Scenario: must successfully receive Role Assignments without optional headers
Given a user with [an active IDAM profile with full permissions],
Expand Down
54 changes: 54 additions & 0 deletions src/functionalTest/resources/features/F-009/S-185.td.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"title": "must successfully receive Role Assignments with page size including role label",
"_guid_": "S-185",
"_extends_": "F-009_Test_Data_Base",
"specs": [
"contains multiple Role Assignments with a page size",
"has includeLabels request param set to true"
],

"request": {
"headers": {
"size": 3,
"sort": "roleName"
},
"queryParams": {
"includeLabels": "true"
},
"body": {
"queryRequests":[
{
"actorId": ["${[scenarioContext][childContexts][S-185_CreationDataForRoleAssignment][testData][request][body][roleRequest][reference]}"]
}
]
}
},
"expectedResponse": {
"_extends_": "Common_200_Response",
"body": {
"roleAssignmentResponse" : [
{
"_extends_": "ResponseRoleAssignment",
"actorId": "${}${[scenarioContext][testData][request][body][queryRequests][0][actorId][0]}",
"roleName": "case-allocator",
"roleLabel": "Case Allocator",
"attributes" : {
"substantive": "N"
}
},
{
"_extends_": "ResponseRoleAssignment",
"actorId": "${}${[scenarioContext][testData][request][body][queryRequests][0][actorId][0]}",
"roleName": "judge",
"roleLabel": "Judge"
},
{
"_extends_": "ResponseRoleAssignment",
"actorId": "${}${[scenarioContext][testData][request][body][queryRequests][0][actorId][0]}",
"roleName": "senior-judge",
"roleLabel": "Senior Judge"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"_guid_": "S-185_CreationDataForRoleAssignment",
"_extends_": "CreationDataBaseForRoleAssignment",
"request": {
"body": {
"roleRequest": {
"reference": "${[scenarioContext][customValues][generateUUID]}",
"replaceExisting": true
},
"requestedRoles": [
{
"_extends_": "RequestedRole",
"actorId": "${[scenarioContext][testData][request][body][roleRequest][reference]}",
"roleName": "case-allocator"
},
{
"_extends_": "RequestedRole",
"actorId": "${[scenarioContext][testData][request][body][roleRequest][reference]}",
"roleName": "judge"
},
{
"_extends_": "RequestedRole",
"actorId": "${[scenarioContext][testData][request][body][roleRequest][reference]}",
"roleName": "senior-judge"
}
]
}
},
"expectedResponse": {
"body": {
"roleAssignmentResponse": {
"roleRequest": {
"reference": "${}${[scenarioContext][testData][request][body][roleRequest][reference]}",
"replaceExisting": true
},
"requestedRoles": [
{
"__ordering__": "UNORDERED",
"__elementId__": "roleName"
},
{
"_extends_": "ResponseRequestedRole",
"actorId": "${}${[scenarioContext][testData][request][body][roleRequest][reference]}",
"reference": "${}${[scenarioContext][testData][request][body][roleRequest][reference]}",
"roleName": "case-allocator",
"attributes" : {
"substantive": "N"
}
},
{
"_extends_": "ResponseRequestedRole",
"actorId": "${}${[scenarioContext][testData][request][body][roleRequest][reference]}",
"reference": "${}${[scenarioContext][testData][request][body][roleRequest][reference]}",
"roleName": "judge"
},
{
"_extends_": "ResponseRequestedRole",
"actorId": "${}${[scenarioContext][testData][request][body][roleRequest][reference]}",
"reference": "${}${[scenarioContext][testData][request][body][roleRequest][reference]}",
"roleName": "senior-judge"
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"_guid_": "S-185_DeleteDataForMultipleRoleAssignments",
"productName": "Role Assignment Service",
"operationName": "Delete Role Assignments by Process",
"method": "DELETE",
"uri": "/am/role-assignments?process={process}&reference={reference}",
"specs": [
"to delete role assignments just created above"
],
"users": {
"invokingUser": {
"_extends_": "AmBeftaUser2"
}
},
"request": {
"headers": {
"Authorization": "[[DEFAULT_AUTO_VALUE]]",
"ServiceAuthorization": "[[DEFAULT_AUTO_VALUE]]",
"X-Correlation-ID": "003352d0-e699-48bc-b6f5-5810411e60af"
},
"pathVariables": {
"process": "businessProcess1",
"reference": "${[scenarioContext][parentContext][childContexts][S-185_CreationDataForRoleAssignment][testData][request][body][roleRequest][reference]}"
}
},
"expectedResponse": {
"headers": {
"Content-Length": "[[ANYTHING_PRESENT]]",
"Content-Type": "application/json"
},
"_extends_": "Common_204_Response"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static org.mockito.Mockito.doReturn;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand All @@ -57,8 +58,10 @@ public class QueryAssignmentIntegrationTest extends BaseTest {
private static final Logger logger = LoggerFactory.getLogger(RoleAssignmentIntegrationTest.class);

private static final String URL = "/am/role-assignments/query";
private static final String INCLUDE_LABELS_PARAM = "includeLabels";

private static final String ACTOR_ID = "123e4567-e89b-42d3-a456-556642445613";
private static final String ACTOR_ID_2 = "8bc0a13d-3bb7-3b7c-ab5b-1a9b0a141bab";

private MockMvc mockMvc;

Expand Down Expand Up @@ -159,6 +162,30 @@ public void retrieveRoleAssignmentsByQueryRequest_queryRequestWithoutHeaders() t
.andReturn();
}

@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_role_assignment.sql"})
public void retrieveRoleAssignmentsByQueryRequest_verifyRoleLabel() throws Exception {
retrieveRoleAssignmentsByQueryRequest_conditionallyAddRoleLabel(true);
retrieveRoleAssignmentsByQueryRequest_conditionallyAddRoleLabel(false);
}

void retrieveRoleAssignmentsByQueryRequest_conditionallyAddRoleLabel(Boolean includeLabels) throws Exception {

logger.info("Retrieve Role Assignments when includeLabels {}", includeLabels);

final MvcResult result = mockMvc.perform(post(URL)
.contentType(JSON_CONTENT_TYPE)
.headers(getHttpHeaders("3", "roleName"))
.param(INCLUDE_LABELS_PARAM, includeLabels.toString())
.content(mapper.writeValueAsBytes(
QueryRequest.builder()
.actorId(ACTOR_ID_2).build())))
.andExpect(status().isOk())
.andReturn();

assertRoleAssignmentResponse(result, includeLabels);
}

@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_role_assignment.sql"})
public void retrieveRoleAssignmentsByQueryRequest_unmatchedQueryRequest() throws Exception {
Expand Down Expand Up @@ -248,6 +275,33 @@ public void retrieveRoleAssignmentsByQueryRequestV2_PageSize() throws Exception
.get("roleType").asText());
}

@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_role_assignment.sql"})
public void retrieveRoleAssignmentsByQueryRequestV2_verifyRoleLabel() throws Exception {
retrieveRoleAssignmentsByQueryRequestV2_conditionallyAddRoleLabel(true);
retrieveRoleAssignmentsByQueryRequestV2_conditionallyAddRoleLabel(false);
}

void retrieveRoleAssignmentsByQueryRequestV2_conditionallyAddRoleLabel(Boolean includeLabels) throws Exception {

logger.info("Retrieve Role Assignments V2 query request when includeLabels {}", includeLabels);

QueryRequest queryRequest = QueryRequest.builder().actorId(ACTOR_ID_2).build();
MultipleQueryRequest queryRequests = MultipleQueryRequest.builder().queryRequests(List.of(queryRequest))
.build();

final MvcResult result = mockMvc.perform(post("/am/role-assignments/query")
.contentType(V2.MediaType.POST_ASSIGNMENTS)
.headers(getHttpHeaders("3", "roleName"))
.param(INCLUDE_LABELS_PARAM, includeLabels.toString())
.content(mapper.writeValueAsString(queryRequests))
.accept(V2.MediaType.POST_ASSIGNMENTS))
.andExpect(status().isOk())
.andReturn();

assertRoleAssignmentResponse(result, includeLabels);
}

@Test
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = {"classpath:sql/insert_role_assignment.sql"})
public void retrieveRoleAssignmentsByQueryRequestV2_EmptyAttributeMappingDoesNotQueryEntireDb() throws Exception {
Expand Down Expand Up @@ -375,4 +429,26 @@ private HttpHeaders getHttpHeaders(String size, String sort) {

return headers;
}

private void assertRoleAssignmentResponse(MvcResult result, Boolean includeLabels) throws Exception {
JsonNode responseJsonNode = new ObjectMapper().readValue(result.getResponse().getContentAsString(),
JsonNode.class);
JsonNode roleAssignmentResponse = responseJsonNode.get("roleAssignmentResponse");

String[] expectedRoleTypes = {"CASE", "ORGANISATION", "CASE"};
String[] expectedRoleLabels = {"Case Allocator", "Judge", "Post Hearing Judge"};

assertFalse(roleAssignmentResponse.isEmpty());
assertEquals(3, roleAssignmentResponse.size());

for (int i = 0; i < roleAssignmentResponse.size(); i++) {
assertEquals(expectedRoleTypes[i], roleAssignmentResponse.get(i).get("roleType").asText());
if (includeLabels) {
assertEquals(expectedRoleLabels[i], roleAssignmentResponse.get(i).get("roleLabel").asText());
} else {
assertNull(roleAssignmentResponse.get(i).get("roleLabel"));
}
}
}

}
Loading

0 comments on commit 9baaef1

Please sign in to comment.