Skip to content

CCD-5225: Enable AAC / ExUI Pact Tests #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id 'com.github.ben-manes.versions' version '0.51.0'
id 'com.github.spacialcircumstances.gradle-cucumber-reporting' version '0.1.25'
id 'org.sonarqube' version '5.0.0.4638'
id 'au.com.dius.pact' version '4.1.7'
id 'au.com.dius.pact' version '4.3.12'
}

ext {
Expand Down Expand Up @@ -179,7 +179,7 @@ tasks.register('contract', Test) {
useJUnitPlatform()
testClassesDirs = sourceSets.contractTest.output.classesDirs
classpath = sourceSets.contractTest.runtimeClasspath
include "uk/gov/hmcts/reform/managecase/api/controller/provider/**"
include "uk/gov/hmcts/reform/managecase/pactprovider"
}

tasks.register('runProviderPactVerification', Test) {
Expand Down Expand Up @@ -280,8 +280,9 @@ def versions = [
springBoot : springBoot.class.package.implementationVersion,
springfoxSwagger: '3.0.0',
restAssured : '4.3.1',
lombok : '1.18.28',
lombok : '1.18.30',
pact_version : '4.1.7',
pact_version : '4.3.4',
serviceAuthVersion : '4.0.3',
idamJavaClient : '2.0.1',
]
Expand Down
2 changes: 1 addition & 1 deletion charts/aac-manage-case-assignment/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ appVersion: "1.0"
description: A Helm chart for manage-case-assignment App
name: aac-manage-case-assignment
home: https://github.com/hmcts/aac-manage-case-assignment
version: 0.2.16
version: 0.2.17
maintainers:
- name: HMCTS CDM team
dependencies:
Expand Down
5 changes: 5 additions & 0 deletions charts/aac-manage-case-assignment/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ java:
CCD_DEFINITION_STORE_API_BASE_URL: http://ccd-definition-store-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal
PRD_HOST: http://rd-professional-api-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal
ROLE_ASSIGNMENT_URL: http://am-role-assignment-service-{{ .Values.global.environment }}.service.core-compute-{{ .Values.global.environment }}.internal

PACT_BROKER_FULL_URL: https://pact-broker.platform.hmcts.net
PACT_BROKER_URL: pact-broker.platform.hmcts.net
PACT_BROKER_PORT: 443
PACT_BROKER_SCHEME: https
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package uk.gov.hmcts.reform.managecase.pactprovider.caseassignments;

import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.State;
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;
import au.com.dius.pact.provider.junitsupport.loader.VersionSelector;
import au.com.dius.pact.provider.spring.junit5.MockMvcTestTarget;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.modelmapper.ModelMapper;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.managecase.domain.CaseAssignment;
import uk.gov.hmcts.reform.managecase.domain.UserDetails;
import uk.gov.hmcts.reform.managecase.pactprovider.caseassignments.controller.CasesRestController;
import uk.gov.hmcts.reform.managecase.domain.CaseAssignedUsers;
import uk.gov.hmcts.reform.managecase.service.CaseAssignmentService;
import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

@Provider("acc_manageCaseAssignment")
@PactBroker(
url = "${PACT_BROKER_FULL_URL:http://localhost:9292}",
consumerVersionSelectors = {@VersionSelector(tag = "master")})
@IgnoreNoPactsToVerify
@ExtendWith(SpringExtension.class)
public class CasesProviderTest {

@Mock
private CaseAssignmentService caseAssignmentService;

@Mock
private ModelMapper mapper;

@BeforeEach
void beforeCreate(PactVerificationContext context) {
MockMvcTestTarget testTarget = new MockMvcTestTarget();
testTarget.setControllers(new CasesRestController(caseAssignmentService, mapper));
if (context != null) {
context.setTarget(testTarget);
}
}

@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactVerificationTestTemplate(PactVerificationContext context) {
if (context != null) {
context.verifyInteraction();
}
}

@State("Case assignments exist for case Ids")
public void getCaseAssignments() {
when(caseAssignmentService.getCaseAssignments(anyList())).thenReturn(mockCaseAssignmentsList());
}

@State("Assign a user to a case")
public void assignAccessWithinOrganisation() {
when(mapper.map(any(Object.class), eq(CaseAssignment.class))).thenReturn(new CaseAssignment());
when(caseAssignmentService.assignCaseAccess(any(CaseAssignment.class), anyBoolean()))
.thenReturn(List.of("Role1","Role2"));
}

public List<CaseAssignedUsers> mockCaseAssignmentsList() {
UserDetails userDetails = new UserDetails("221a2877-e1ab-4dc4-a9ff-f9424ad58738", "Bill",
"Roberts", "[email protected]",
List.of("[Claimant]", "[Defendant]"));
CaseAssignedUsers caseAssignedUser = new CaseAssignedUsers("1588234985453946", List.of(userDetails));
return List.of(caseAssignedUser);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package uk.gov.hmcts.reform.managecase.pactprovider.caseassignments.controller;

import com.microsoft.applicationinsights.boot.dependencies.apachecommons.lang3.StringUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.modelmapper.ModelMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import uk.gov.hmcts.reform.managecase.api.payload.CaseAssignmentRequest;
import uk.gov.hmcts.reform.managecase.api.payload.CaseAssignmentResponse;
import uk.gov.hmcts.reform.managecase.api.payload.GetCaseAssignmentsResponse;
import uk.gov.hmcts.reform.managecase.domain.CaseAssignedUsers;
import uk.gov.hmcts.reform.managecase.domain.CaseAssignment;
import uk.gov.hmcts.reform.managecase.service.CaseAssignmentService;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Optional;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@RestController
public class CasesRestController {

public static final String ASSIGN_ACCESS_MESSAGE =
"Roles %s from the organisation policies successfully assigned to the assignee.";
public static final String GET_ASSIGNMENTS_MESSAGE = "Case-User-Role assignments returned successfully";

private final CaseAssignmentService caseAssignmentService;

private final ModelMapper mapper;

public CasesRestController(final CaseAssignmentService caseAssignmentService, final ModelMapper mapper) {
this.caseAssignmentService = caseAssignmentService;
this.mapper = mapper;
}

/*
* Handle Pact State "Case assignments exist for case Ids".
*/
@Operation(description = "Case assignments exist for case Ids",
security = {@SecurityRequirement(name = "ServiceAuthorization"), @SecurityRequirement(name = "Authorization")})
@ApiResponses({
@ApiResponse(
responseCode = "200", description = "OK",
content = {
@Content(mediaType = "application/json")
})
})
@GetMapping(path = "/case-assignments", produces = APPLICATION_JSON_VALUE)
public GetCaseAssignmentsResponse getCaseAssignments(@RequestParam("case_ids") @Valid
@NotEmpty(message = "case_ids must be a non-empty list of proper case ids.") List<String> caseIds) {

List<CaseAssignedUsers> caseAssignedUsers = caseAssignmentService.getCaseAssignments(caseIds);
return new GetCaseAssignmentsResponse(GET_ASSIGNMENTS_MESSAGE, caseAssignedUsers);
}


/*
* Handle Pact State "Assign a user to a case".
*/
@Operation(description = "Assign a user to a case",
security = {@SecurityRequirement(name = "ServiceAuthorization"), @SecurityRequirement(name = "Authorization")})
@ApiResponses({
@ApiResponse(
responseCode = "201", description = "Created",
content = {
@Content(mediaType = "application/json")
})
})
@PostMapping(path = "/case-assignments", produces = APPLICATION_JSON_VALUE)
public ResponseEntity<CaseAssignmentResponse> assignAccessWithinOrganisation(
@Valid @RequestBody CaseAssignmentRequest requestPayload,
@RequestParam(name = "use_user_token", required = false) Optional<Boolean> useUserToken) {

CaseAssignment caseAssignment = mapper.map(requestPayload, CaseAssignment.class);
List<String> roles = caseAssignmentService.assignCaseAccess(caseAssignment, useUserToken.orElse(false));
CaseAssignmentResponse caseAssignmentResponse = new CaseAssignmentResponse(String.format(ASSIGN_ACCESS_MESSAGE,
StringUtils.join(roles, ',')));

return ResponseEntity.status(HttpStatus.CREATED).body(caseAssignmentResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package uk.gov.hmcts.reform.managecase.pactprovider.noc;

import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.State;
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;
import au.com.dius.pact.provider.junitsupport.loader.VersionSelector;
import au.com.dius.pact.provider.spring.junit5.MockMvcTestTarget;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.managecase.api.payload.RequestNoticeOfChangeResponse;
import uk.gov.hmcts.reform.managecase.api.payload.VerifyNoCAnswersRequest;
import uk.gov.hmcts.reform.managecase.api.payload.VerifyNoCAnswersResponse;
import uk.gov.hmcts.reform.managecase.client.definitionstore.model.ChallengeQuestion;
import uk.gov.hmcts.reform.managecase.client.definitionstore.model.ChallengeQuestionsResult;
import uk.gov.hmcts.reform.managecase.client.definitionstore.model.FieldType;
import uk.gov.hmcts.reform.managecase.domain.ApprovalStatus;
import uk.gov.hmcts.reform.managecase.domain.NoCRequestDetails;
import uk.gov.hmcts.reform.managecase.domain.Organisation;
import uk.gov.hmcts.reform.managecase.pactprovider.noc.controller.NocRestController;
import uk.gov.hmcts.reform.managecase.service.noc.NoticeOfChangeQuestions;
import uk.gov.hmcts.reform.managecase.service.noc.RequestNoticeOfChangeService;
import uk.gov.hmcts.reform.managecase.service.noc.VerifyNoCAnswersService;
import java.util.ArrayList;
import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

@Provider("acc_manageCaseAssignment_Noc")
@PactBroker(
url = "${PACT_BROKER_FULL_URL:http://localhost:9292}",
consumerVersionSelectors = {@VersionSelector(tag = "master")})
@IgnoreNoPactsToVerify
@ExtendWith(SpringExtension.class)
public class NocProviderTest {

@Mock
private NoticeOfChangeQuestions mockNoticeOfChangeQuestions;

@Mock
private VerifyNoCAnswersService mockVerifyNoCAnswersService;

@Mock
private RequestNoticeOfChangeService mockRequestNoticeOfChangeService;

@Mock
private NoCRequestDetails mockNoCRequestDetails;

@BeforeEach
void beforeCreate(PactVerificationContext context) {
MockMvcTestTarget testTarget = new MockMvcTestTarget();
testTarget.setControllers(new NocRestController(mockNoticeOfChangeQuestions, mockVerifyNoCAnswersService,
mockRequestNoticeOfChangeService));
if (context != null) {
context.setTarget(testTarget);
}
}

@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactVerificationTestTemplate(PactVerificationContext context) {
if (context != null) {
context.verifyInteraction();
}
}

@State("a case with id 1234567890123456 exists")
public void getNoticeOfChangeQuestions1() {
when(mockNoticeOfChangeQuestions.getChallengeQuestions(anyString())).thenReturn(mockChallengeQuestionsResult());
}

@State("a case with an error exists")
public void getNoticeOfChangeQuestions2() {
}

@State("A valid submit NoC event is requested")
public void requestNoticeOfChange1() {
when(mockVerifyNoCAnswersService.verifyNoCAnswers(any(VerifyNoCAnswersRequest.class)))
.thenReturn(mockNoCRequestDetails);
when(mockRequestNoticeOfChangeService.requestNoticeOfChange(any(NoCRequestDetails.class)))
.thenReturn(mockRequestNoticeOfChangeResponse());
}

@State("A NoC answer request with invalid case ID")
public void requestNoticeOfChange2() {
when(mockVerifyNoCAnswersService.verifyNoCAnswers(any(VerifyNoCAnswersRequest.class)))
.thenReturn(mockNoCRequestDetails);
}

@State("A valid NoC answers verification request")
public void verifyNoticeOfChangeAnswers1() {
when(mockVerifyNoCAnswersService.verifyNoCAnswers(any(VerifyNoCAnswersRequest.class)))
.thenReturn(mockNoCRequestDetails);
when(mockNoCRequestDetails.toVerifyNoCAnswersResponse(anyString())).thenReturn(mockVerifyNoCAnswersResponse());
}

@State("An invalid NoC answer request")
public void verifyNoticeOfChangeAnswers2() {
when(mockVerifyNoCAnswersService.verifyNoCAnswers(any(VerifyNoCAnswersRequest.class)))
.thenReturn(mockNoCRequestDetails);
}


private ChallengeQuestionsResult mockChallengeQuestionsResult() {
FieldType answerFieldType = FieldType.builder()
.id("Email")
.type("Email")
.min("0")
.max("10")
.regularExpression("asdsa")
.collectionFieldType(FieldType.builder().build())
.build();
ChallengeQuestion challengeQuestion = ChallengeQuestion.builder()
.caseTypeId("Probate")
.order(1)
.questionText("What is their Email?")
.answerFieldType(answerFieldType)
.displayContextParameter("1")
.challengeQuestionId("NoC")
.questionId("QuestionId67745")
.answerField("")
.build();

List<ChallengeQuestion> challengeQuestionsResponse = new ArrayList<>();
challengeQuestionsResponse.add(challengeQuestion);

return ChallengeQuestionsResult.builder().questions(challengeQuestionsResponse).build();
}

private RequestNoticeOfChangeResponse mockRequestNoticeOfChangeResponse() {
return RequestNoticeOfChangeResponse.builder()
.approvalStatus(ApprovalStatus.APPROVED)
.caseRole("[Claimant]")
.status("Notice of request has been successfully submitted.")
.build();
}

private VerifyNoCAnswersResponse mockVerifyNoCAnswersResponse() {
return new VerifyNoCAnswersResponse("Notice of Change answers verified successfully",
new Organisation("QUK822NA", "Some Org"));
}
}
Loading