Skip to content
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

CCD-5224: CCD / Work Allocation Pact Provider Tests #2454

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5058b8e
Enable Pact Testing
Jul 15, 2024
4fdc1be
Add logging to State methods and uncomment existing code in State met…
Jul 16, 2024
3006874
Merge branch 'master' into CCD-5224-investigate-CCD-Pact-Testing-not-…
JamesCollettCGI Jul 16, 2024
ee9363c
Add missing imports
Jul 16, 2024
39809bb
Merge branch 'master' into CCD-5224-investigate-CCD-Pact-Testing-not-…
JamesCollettCGI Jul 18, 2024
4a435e8
Added 'HelloOneProviderTest.java'
Aug 2, 2024
626ba57
Fix checkstyleContractTest
Aug 2, 2024
fddbf03
Add PACT values to charts values.yaml
Aug 2, 2024
b0ebadc
Bumping chart version/ fixing aliases
hmcts-jenkins-a-to-c[bot] Aug 2, 2024
320abd3
Merge branch 'master' into CCD-5224-investigate-CCD-Pact-Testing-not-…
JamesCollettCGI Aug 2, 2024
77100e8
Added 'HelloTwoProviderTest.java'
Aug 2, 2024
c276c8c
Fix HelloOneProviderTest and HelloTwoProviderTest @Provider names
Aug 2, 2024
851f829
Add WorkAllocationProviderTest.java
Aug 5, 2024
6d7822b
Updated 'WorkAllocationProviderTest.java' -- Added SpringBootTest , A…
Aug 5, 2024
bab3f0a
Updated 'WorkAllocationProviderTest.java' -- Added remaining WA States
Aug 6, 2024
e53e2e7
Add GetCaseProviderTest , StartEventProviderTest , StartProviderTest …
Sep 6, 2024
fec0a2c
Bumping chart version/ fixing aliases
hmcts-jenkins-a-to-c[bot] Sep 6, 2024
e9e271c
Rename WorkAllocationPacts1ProviderTest.java to WorkAllocationProvide…
Sep 6, 2024
657b386
Fix all checkstyleContractTest warnings
Sep 9, 2024
6e56a3e
Revert temporary and 'v2' changes
Sep 9, 2024
878b597
Merge branch 'master' into CCD-5224-investigate-CCD-Pact-Testing-not-…
JamesCollettCGI Sep 9, 2024
a85406c
Remove @PactFolder annotations from Provider Tests
Sep 9, 2024
2173b16
Update to build.gradle
Sep 24, 2024
51a3fe8
Merge branch 'master' into CCD-5224-investigate-CCD-Pact-Testing-not-…
JamesCollettCGI Oct 16, 2024
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
6 changes: 6 additions & 0 deletions Jenkinsfile_CNP
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = "hmctspublic.azurecr.io/imported/"
withPipeline(type, product, component) {
onMaster {
enableSlackNotifications('#ccd-master-builds')
enablePactAs([
AppPipelineDsl.PactRoles.PROVIDER
])
}
if (env.BRANCH_NAME.equalsIgnoreCase(dataStoreApiDevelopPr)) {
enableSlackNotifications('#ccd-develop-builds')
Expand All @@ -128,6 +131,9 @@ withPipeline(type, product, component) {
}
onPR {
enableSlackNotifications('#ccd-pr-builds')
enablePactAs([
AppPipelineDsl.PactRoles.PROVIDER
])
}

// Check if the build should be wired to an environment higher than 'preview'.
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ plugins {
id 'org.jetbrains.gradle.plugin.idea-ext' version '0.7'
id 'info.solidsoft.pitest' version '1.15.0'
id 'uk.gov.hmcts.java' version '0.12.57'
id 'au.com.dius.pact' version '4.1.0'
id 'au.com.dius.pact' version '4.3.12'
id "org.jsonschema2pojo" version "1.2.1"
}

apply from: './gradle/suppress.gradle'

def versions = [
pact_version : '4.1.7',
pact_version : '4.3.4',
]

ext['spring-security.version'] = '5.7.11'
Expand Down Expand Up @@ -921,7 +921,7 @@ task runProviderPactVerification(type:Test) {
systemProperty 'pact.verifier.publishResults', project.property('pact.verifier.publishResults')
}
systemProperty 'pact.provider.version', project.pactVersion
include "uk/gov/hmcts/ccd/v2/external/controller/**"
include "uk/gov/hmcts/**"
}

runProviderPactVerification.finalizedBy pactVerify
Expand Down
2 changes: 1 addition & 1 deletion charts/ccd-data-store-api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ description: Helm chart for the HMCTS CCD Data Store
name: ccd-data-store-api
apiVersion: v2
home: https://github.com/hmcts/ccd-data-store-api
version: 2.0.30
version: 2.0.31
maintainers:
- name: HMCTS CCD Dev Team
email: [email protected]
Expand Down
5 changes: 5 additions & 0 deletions charts/ccd-data-store-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ java:
DATA_STORE_CROSS_JURISDICTIONAL_ROLES: caseworker-caa,caseworker-approver,next-hearing-date-admin
DATA_STORE_CITIZEN_ROLES: citizen,letter-holder
DATA_STORE_SECURITY_LOGGING_FILTER_PATH_REGEX: 'DISABLED'

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,69 @@
package uk.gov.hmcts.reform.ccd.pactprovider.wataskmanagement;

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.ccd.data.casedetails.SecurityClassification;
import uk.gov.hmcts.ccd.domain.model.definition.CaseDetails;
import uk.gov.hmcts.ccd.domain.service.getcase.GetCaseOperation;
import uk.gov.hmcts.reform.ccd.pactprovider.wataskmanagement.controller.GetCaseRestController;
import java.util.Optional;

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

// Get Case Provider Test version 1.

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

@Mock
private GetCaseOperation mockGetCaseOperation;

@BeforeEach
void beforeCreate(PactVerificationContext context) {
MockMvcTestTarget testTarget = new MockMvcTestTarget();
testTarget.setControllers(new GetCaseRestController(mockGetCaseOperation));
if (context != null) {
context.setTarget(testTarget);
}
}

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

// Mock the interaction.
@State("a case exists")
public void getCase() {
when(mockGetCaseOperation.execute(anyString())).thenReturn(Optional.of(mockCaseDetails()));
}

private CaseDetails mockCaseDetails() {
CaseDetails caseDetails = new CaseDetails();
caseDetails.setReference(1L);
caseDetails.setCaseTypeId("Asylum");
caseDetails.setJurisdiction("IA");
caseDetails.setSecurityClassification(SecurityClassification.PRIVATE);
return caseDetails;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package uk.gov.hmcts.reform.ccd.pactprovider.wataskmanagement;

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 com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.TextNode;
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.ccd.data.casedetails.SecurityClassification;
import uk.gov.hmcts.ccd.domain.model.callbacks.StartEventResult;
import uk.gov.hmcts.ccd.domain.model.definition.CaseDetails;
import uk.gov.hmcts.ccd.domain.service.startevent.StartEventOperation;
import uk.gov.hmcts.reform.ccd.pactprovider.wataskmanagement.controller.StartEventRestController;
import java.util.HashMap;

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

// Start Event Provider Test version 1.

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

@Mock
private StartEventOperation startEventOperation;

private final ObjectMapper objectMapper = new ObjectMapper();

@BeforeEach
void beforeCreate(PactVerificationContext context) {
MockMvcTestTarget testTarget = new MockMvcTestTarget();
testTarget.setControllers(new StartEventRestController(startEventOperation));
if (context != null) {
context.setTarget(testTarget);
}
}

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

// Mock the interaction.
@State("A Start Event for a Caseworker is requested")
public void startEventForCaseworker() throws JsonProcessingException {
when(startEventOperation.triggerStartForCase(anyString(), anyString(), anyBoolean()))
.thenReturn(mockStartEventResult());
}

private StartEventResult mockStartEventResult() throws JsonProcessingException {
StartEventResult startEventResult = new StartEventResult();
startEventResult.setToken("someToken");
startEventResult.setEventId("startAppeal");
startEventResult.setCaseDetails(mockCaseDetails());
return startEventResult;
}

private CaseDetails mockCaseDetails() throws JsonProcessingException {
CaseDetails caseDetails = new CaseDetails();
caseDetails.setReference(1L);
caseDetails.setCaseTypeId("Asylum");
caseDetails.setJurisdiction("IA");
caseDetails.setSecurityClassification(SecurityClassification.PUBLIC);
caseDetails.setState("appealStarted");
caseDetails.setData(new HashMap<String,JsonNode>() {{
put("appealReferenceNumber", new TextNode("DRAFT"));
put("appealType", new TextNode("protection"));
put("appellantDateOfBirth", new TextNode("1990-12-07"));
put("appellantFamilyName", new TextNode("Smith"));
put("appellantGivenNames", new TextNode("Bob"));
put("appellantNameForDisplay", new TextNode("Bob Smith"));
put("appellantTitle", new TextNode("Mr"));
put("applicationOutOfTimeExplanation", new TextNode("test case"));
put("caseManagementLocation", objectMapper.readTree("{\"baseLocation\":\"765324\",\"region\":"
+ "\"1\"}"));
put("currentCaseStateVisibleToLegalRepresentative", new TextNode("appealStarted"));
put("homeOfficeDecisionDate", new TextNode("2019-08-01"));
put("homeOfficeReferenceNumber", new TextNode("000123456"));
put("legalRepCompanyAddress", objectMapper.readTree("{\"AddressLine1\":\"\",\"AddressLine2\":"
+ "\"\",\"AddressLine3\":\"\",\"Country\":\"\",\"PostCode\":\"\",\"PostTown\":\"\"}"));
put("legalRepCompanyName", new TextNode(""));
put("staffLocation", new TextNode("Taylor House"));
put("submissionOutOfTime", new TextNode("Yes"));
put("subscriptions", objectMapper.readTree("[{\"id\":\"1\",\"value\":{\"email\":"
+ "\"[email protected]\",\"mobileNumber\":\"0111111111\",\"subscriber\":\"appellant\","
+ "\"wantsEmail\":\"Yes\",\"wantsSms\":\"Yes\"}}]"));
put("uploadAddendumEvidenceLegalRepActionAvailable", new TextNode("No"));
put("uploadAdditionalEvidenceActionAvailable", new TextNode("No"));
put("uploadTheNoticeOfDecisionDocs", objectMapper.readTree("[{\"id\":\"1\",\"value\":"
+ "{\"description\":\"some notice of decision description\",\"document\":{\"document_binary_url\":"
+ "\"http://dm-store-aat.service.core-compute-aat.internal/documents/"
+ "7f63ca9b-c361-49ab-aa8c-8fbdb6bc2936\",\"document_filename\":"
+ "\"some-notice-of-decision-letter.pdf\",\"document_url\":"
+ "\"http://dm-store-aat.service.core-compute-aat.internal/documents/"
+ "7f63ca9b-c361-49ab-aa8c-8fbdb6bc2936\"}}}]"));
}
});
return caseDetails;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package uk.gov.hmcts.reform.ccd.pactprovider.wataskmanagement;

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 com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.TextNode;
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.ccd.domain.model.callbacks.StartEventResult;
import uk.gov.hmcts.ccd.domain.model.definition.CaseDetails;
import uk.gov.hmcts.ccd.domain.service.startevent.StartEventOperation;
import uk.gov.hmcts.reform.ccd.pactprovider.wataskmanagement.controller.StartRestController;
import java.util.HashMap;

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

// Start Provider Test version 1.

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

@Mock
private StartEventOperation startEventOperation;

@BeforeEach
void beforeCreate(PactVerificationContext context) {
MockMvcTestTarget testTarget = new MockMvcTestTarget();
testTarget.setControllers(new StartRestController(startEventOperation));
if (context != null) {
context.setTarget(testTarget);
}
}

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

// Mock the interaction.
@State("A Start for a Caseworker is requested")
public void start() {
when(startEventOperation.triggerStartForCaseType(anyString(), anyString(), anyBoolean()))
.thenReturn(mockStartEventResult());
}

private StartEventResult mockStartEventResult() {
StartEventResult startEventResult = new StartEventResult();
startEventResult.setCaseDetails(mockCaseDetails());
startEventResult.setToken("someToken");
startEventResult.setEventId("startAppeal");
return startEventResult;
}

private CaseDetails mockCaseDetails() {
CaseDetails caseDetails = new CaseDetails();
caseDetails.setReference(1L);
caseDetails.setCaseTypeId("Asylum");
caseDetails.setJurisdiction("IA");
caseDetails.setData(new HashMap<String, JsonNode>() {{
put("appealOutOfCountry", new TextNode("No"));
put("isOutOfCountryEnabled", new TextNode("No"));
}
});
return caseDetails;
}
}
Loading