From 8d8b92cf82781b6523adb3121ef25e97534b83f8 Mon Sep 17 00:00:00 2001 From: Sammi Chong Date: Tue, 8 Jul 2025 16:34:03 +0100 Subject: [PATCH 1/2] Add new provider test --- ...afcassApiProviderCcdSearchCaseApiTest.java | 111 ++++++++++++++++++ .../cases/FlatMockController.java | 74 ++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/CafcassApiProviderCcdSearchCaseApiTest.java create mode 100644 src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/FlatMockController.java diff --git a/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/CafcassApiProviderCcdSearchCaseApiTest.java b/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/CafcassApiProviderCcdSearchCaseApiTest.java new file mode 100644 index 0000000000..d07ca6c5fe --- /dev/null +++ b/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/CafcassApiProviderCcdSearchCaseApiTest.java @@ -0,0 +1,111 @@ +package uk.gov.hmcts.reform.ccd.pactprovider.cases; + +import au.com.dius.pact.provider.junit5.PactVerificationContext; +import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider; +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 lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +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.mockito.Mockito; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +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.model.definition.FieldTypeDefinition; +import uk.gov.hmcts.ccd.domain.model.search.CaseSearchResult; +import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.CaseSearchResultView; +import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.ElasticsearchRequest; +import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.HeaderGroupMetadata; +import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.SearchResultViewHeader; +import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.SearchResultViewHeaderGroup; +import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.SearchResultViewItem; +import uk.gov.hmcts.ccd.domain.service.createcase.CreateCaseOperation; +import uk.gov.hmcts.ccd.domain.service.createevent.CreateEventOperation; +import uk.gov.hmcts.ccd.domain.service.getcase.GetCaseOperation; +import uk.gov.hmcts.ccd.domain.service.search.CaseSearchResultViewGenerator; +import uk.gov.hmcts.ccd.domain.service.search.elasticsearch.CaseSearchOperation; +import uk.gov.hmcts.ccd.domain.service.search.elasticsearch.CrossCaseTypeSearchRequest; +import uk.gov.hmcts.ccd.domain.service.search.elasticsearch.ElasticsearchQueryHelper; +import uk.gov.hmcts.ccd.domain.service.search.elasticsearch.ElasticsearchSortService; +import uk.gov.hmcts.ccd.domain.service.startevent.StartEventOperation; +import uk.gov.hmcts.ccd.v2.internal.controller.UICaseSearchController; +import uk.gov.hmcts.ccd.v2.internal.resource.CaseSearchResultViewResource; +import uk.gov.hmcts.reform.ccd.pactprovider.cases.controller.CasesRestController; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.powermock.api.mockito.PowerMockito.doReturn; + +@Slf4j +@ExtendWith(SpringExtension.class) +@Provider("ccd_data") +@PactBroker(url = "${PACT_BROKER_FULL_URL:http://localhost:9292}", + consumerVersionSelectors = {@VersionSelector(tag = "Dev")}) +@TestPropertySource(locations = "/application.properties") +@ActiveProfiles("SECURITY_MOCK") +public class CafcassApiProviderCcdSearchCaseApiTest { + + @Mock + private CaseSearchOperation caseSearchOperation; + + @Mock + private CaseSearchResultViewGenerator caseSearchResultViewGenerator; + + @Mock + private ElasticsearchSortService elasticsearchSortService; + + @Mock + private GetCaseOperation getCaseOperation; + + @Mock + private StartEventOperation startEventOperation; + + @Mock + private CreateEventOperation createEventOperation; + + @Mock + private CreateCaseOperation mockCreateCaseOperation; + + @Mock + private ElasticsearchQueryHelper elasticsearchQueryHelper; + + @BeforeEach + void before(PactVerificationContext context) { + MockMvcTestTarget target = new MockMvcTestTarget(); + target.setControllers(new uk.gov.hmcts.reform.ccd.pactprovider.cases.FlatMockController()); + context.setTarget(target); + } + + @TestTemplate + @ExtendWith(PactVerificationInvocationContextProvider.class) + void pactVerificationTestTemplate(PactVerificationContext context) { + context.verifyInteraction(); + } + + @State("Search Cases exist in the datetime range for CafCass in CCD Store") + public void searchCasesExist() throws JsonProcessingException { + System.out.println("State setup: Search Cases exist in the datetime range for CafCass in CCD Store"); + } +} \ No newline at end of file diff --git a/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/FlatMockController.java b/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/FlatMockController.java new file mode 100644 index 0000000000..5e1b3abec0 --- /dev/null +++ b/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/FlatMockController.java @@ -0,0 +1,74 @@ +package uk.gov.hmcts.reform.ccd.pactprovider.cases; + +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.*; + +@RestController +@RequestMapping("/internal/searchCases") +public class FlatMockController { + + @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity> searchCases(@RequestParam("ctid") String caseTypeId, + @RequestBody Map query) { + + Map caseData = new HashMap<>(); + caseData.put("applicantSolicitorEmailAddress", "prl-e2etestsolicitor@mailinator.com"); + caseData.put("caseTypeOfApplication", "C100"); + caseData.put("confidentialDetails", Map.of("isConfidentialDetailsAvailable", "No")); + caseData.put("childrenKnownToLocalAuthority", "no"); + caseData.put("children", List.of()); + caseData.put("respondents", List.of()); + caseData.put("applicants", List.of()); + caseData.put("applicantsConfidentialDetails", List.of(Map.of())); + caseData.put("courtName", "West London Family Court"); + caseData.put("dateSubmitted", "2022-08-22"); + + caseData.put("miamExemptionsTable", Map.of( + "reasonsForMiamExemption", "Urgency", + "domesticViolenceEvidence", "", + "urgencyEvidence", "Any delay caused by MIAM would cause unreasonable hardship to the prospective applicant", + "childProtectionEvidence", "", + "previousAttendenceEvidence", "", + "otherGroundsEvidence", "" + )); + + caseData.put("otherPeopleInTheCaseTable", List.of(Map.of( + "id", "a5d86587-ba06-4db0-8620-10ef472af3e5", + "value", Map.of( + "address", Map.of(), + "relationshipToChild", List.of(Map.of()) + ) + ))); + + caseData.put("solicitorName", "E2E Test Solicitor"); + + caseData.put("submitAndPayDownloadApplicationLink", Map.of( + "document_filename", "Draft_C100_application.pdf", + "document_id", "e7226e49-fc92-4c12-bac5-e3e50ee4ff15" + )); + + caseData.put("summaryTabForOrderAppliedFor", Map.of( + "ordersApplyingFor", "Child Arrangements Order", + "typeOfChildArrangementsOrder", "Live with order" + )); + + Map caseMap = new HashMap<>(); + caseMap.put("id", 16611647); + caseMap.put("jurisdiction", "PRIVATELAW"); + caseMap.put("state", "SUBMITTED_PAID"); + caseMap.put("caseTypeOfApplication", "C100"); + caseMap.put("case_type_id", "PRLAPPS"); + caseMap.put("created_date", "2022-08-22T10:39:43.49"); + caseMap.put("last_modified", "2022-08-22T10:44:54.055"); + caseMap.put("case_data", caseData); + + Map response = new HashMap<>(); + response.put("total", 1); + response.put("cases", List.of(caseMap)); + + return ResponseEntity.ok(response); + } +} From 0bf357084f972249a0c12bc77e238baec931b766 Mon Sep 17 00:00:00 2001 From: Sammi Chong Date: Thu, 10 Jul 2025 08:38:46 +0100 Subject: [PATCH 2/2] Remove mock controller --- ...afcassApiProviderCcdSearchCaseApiTest.java | 112 +++++++++++------- .../cases/FlatMockController.java | 74 ------------ 2 files changed, 69 insertions(+), 117 deletions(-) delete mode 100644 src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/FlatMockController.java diff --git a/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/CafcassApiProviderCcdSearchCaseApiTest.java b/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/CafcassApiProviderCcdSearchCaseApiTest.java index d07ca6c5fe..d912b2009e 100644 --- a/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/CafcassApiProviderCcdSearchCaseApiTest.java +++ b/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/CafcassApiProviderCcdSearchCaseApiTest.java @@ -1,56 +1,35 @@ package uk.gov.hmcts.reform.ccd.pactprovider.cases; import au.com.dius.pact.provider.junit5.PactVerificationContext; -import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider; 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 lombok.extern.slf4j.Slf4j; -import org.jetbrains.annotations.NotNull; 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.mockito.Mockito; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; 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.model.definition.FieldTypeDefinition; import uk.gov.hmcts.ccd.domain.model.search.CaseSearchResult; import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.CaseSearchResultView; -import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.ElasticsearchRequest; -import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.HeaderGroupMetadata; -import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.SearchResultViewHeader; -import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.SearchResultViewHeaderGroup; import uk.gov.hmcts.ccd.domain.model.search.elasticsearch.SearchResultViewItem; -import uk.gov.hmcts.ccd.domain.service.createcase.CreateCaseOperation; -import uk.gov.hmcts.ccd.domain.service.createevent.CreateEventOperation; -import uk.gov.hmcts.ccd.domain.service.getcase.GetCaseOperation; import uk.gov.hmcts.ccd.domain.service.search.CaseSearchResultViewGenerator; import uk.gov.hmcts.ccd.domain.service.search.elasticsearch.CaseSearchOperation; import uk.gov.hmcts.ccd.domain.service.search.elasticsearch.CrossCaseTypeSearchRequest; import uk.gov.hmcts.ccd.domain.service.search.elasticsearch.ElasticsearchQueryHelper; import uk.gov.hmcts.ccd.domain.service.search.elasticsearch.ElasticsearchSortService; -import uk.gov.hmcts.ccd.domain.service.startevent.StartEventOperation; import uk.gov.hmcts.ccd.v2.internal.controller.UICaseSearchController; -import uk.gov.hmcts.ccd.v2.internal.resource.CaseSearchResultViewResource; -import uk.gov.hmcts.reform.ccd.pactprovider.cases.controller.CasesRestController; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -76,36 +55,83 @@ public class CafcassApiProviderCcdSearchCaseApiTest { @Mock private ElasticsearchSortService elasticsearchSortService; - @Mock - private GetCaseOperation getCaseOperation; - - @Mock - private StartEventOperation startEventOperation; - - @Mock - private CreateEventOperation createEventOperation; - - @Mock - private CreateCaseOperation mockCreateCaseOperation; - @Mock private ElasticsearchQueryHelper elasticsearchQueryHelper; @BeforeEach void before(PactVerificationContext context) { - MockMvcTestTarget target = new MockMvcTestTarget(); - target.setControllers(new uk.gov.hmcts.reform.ccd.pactprovider.cases.FlatMockController()); - context.setTarget(target); - } + UICaseSearchController controller = new UICaseSearchController( + caseSearchOperation, + elasticsearchQueryHelper, + caseSearchResultViewGenerator, + elasticsearchSortService + ); - @TestTemplate - @ExtendWith(PactVerificationInvocationContextProvider.class) - void pactVerificationTestTemplate(PactVerificationContext context) { - context.verifyInteraction(); + MockMvcTestTarget target = new MockMvcTestTarget(); + target.setControllers(controller); + if (context != null) { + context.setTarget(target); + } } @State("Search Cases exist in the datetime range for CafCass in CCD Store") - public void searchCasesExist() throws JsonProcessingException { - System.out.println("State setup: Search Cases exist in the datetime range for CafCass in CCD Store"); + public void setupCafcassStoreState() { + ObjectMapper mapper = new ObjectMapper(); + + Map caseData = new HashMap<>(); + caseData.put("applicantSolicitorEmailAddress", mapper.valueToTree("prl-e2etestsolicitor@mailinator.com")); + caseData.put("confidentialDetails", mapper.valueToTree(Map.of("isConfidentialDetailsAvailable", "No"))); + caseData.put("childrenKnownToLocalAuthority", mapper.valueToTree("no")); + caseData.put("children", mapper.valueToTree(List.of())); + caseData.put("miamExemptionsTable", mapper.valueToTree(Map.of( + "reasonsForMiamExemption", "Urgency", + "domesticViolenceEvidence", "", + "urgencyEvidence", "Any delay caused by MIAM would cause unreasonable hardship to the prospective applicant", + "childProtectionEvidence", "", + "previousAttendenceEvidence", "", + "otherGroundsEvidence", "" + ))); + caseData.put("summaryTabForOrderAppliedFor", mapper.valueToTree(Map.of( + "ordersApplyingFor", "Child Arrangements Order", + "typeOfChildArrangementsOrder", "Live with order" + ))); + caseData.put("applicants", mapper.valueToTree(List.of())); + caseData.put("respondents", mapper.valueToTree(List.of())); + caseData.put("applicantsConfidentialDetails", mapper.valueToTree(List.of())); + caseData.put("courtName", mapper.valueToTree("West London Family Court")); + caseData.put("dateSubmitted", mapper.valueToTree("2022-08-22")); + caseData.put("solicitorName", mapper.valueToTree("E2E Test Solicitor")); + caseData.put("submitAndPayDownloadApplicationLink", mapper.valueToTree(Map.of( + "document_filename", "Draft_C100_application.pdf", + "document_id", "e7226e49-fc92-4c12-bac5-e3e50ee4ff15" + ))); + caseData.put("otherPeopleInTheCaseTable", mapper.valueToTree(List.of())); + + SearchResultViewItem viewItem = new SearchResultViewItem(); + + CaseSearchResultView resultView = new CaseSearchResultView( + List.of(), + List.of(viewItem), + 1L + ); + + CaseDetails caseDetails = new CaseDetails(); + caseDetails.setCaseTypeId("PRLAPPS"); + caseDetails.setState("SUBMITTED_PAID"); + caseDetails.setJurisdiction("PRIVATELAW"); + caseDetails.setId("16611647"); + caseDetails.setCreatedDate(LocalDateTime.of(2022, 8, 22, 10, 39, 43)); + caseDetails.setLastModified(LocalDateTime.of(2022, 8, 22, 10, 44, 54)); + caseDetails.setData(caseData); + + CaseSearchResult caseSearchResult = new CaseSearchResult(1L, List.of(caseDetails)); + + doReturn(caseSearchResult) + .when(caseSearchOperation) + .execute(any(CrossCaseTypeSearchRequest.class), anyBoolean()); + + doReturn(resultView) + .when(caseSearchResultViewGenerator) + .execute(anyString(), eq(caseSearchResult), any(), any()); } } \ No newline at end of file diff --git a/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/FlatMockController.java b/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/FlatMockController.java deleted file mode 100644 index 5e1b3abec0..0000000000 --- a/src/contractTest/java/uk/gov/hmcts/reform/ccd/pactprovider/cases/FlatMockController.java +++ /dev/null @@ -1,74 +0,0 @@ -package uk.gov.hmcts.reform.ccd.pactprovider.cases; - -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.*; - -@RestController -@RequestMapping("/internal/searchCases") -public class FlatMockController { - - @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> searchCases(@RequestParam("ctid") String caseTypeId, - @RequestBody Map query) { - - Map caseData = new HashMap<>(); - caseData.put("applicantSolicitorEmailAddress", "prl-e2etestsolicitor@mailinator.com"); - caseData.put("caseTypeOfApplication", "C100"); - caseData.put("confidentialDetails", Map.of("isConfidentialDetailsAvailable", "No")); - caseData.put("childrenKnownToLocalAuthority", "no"); - caseData.put("children", List.of()); - caseData.put("respondents", List.of()); - caseData.put("applicants", List.of()); - caseData.put("applicantsConfidentialDetails", List.of(Map.of())); - caseData.put("courtName", "West London Family Court"); - caseData.put("dateSubmitted", "2022-08-22"); - - caseData.put("miamExemptionsTable", Map.of( - "reasonsForMiamExemption", "Urgency", - "domesticViolenceEvidence", "", - "urgencyEvidence", "Any delay caused by MIAM would cause unreasonable hardship to the prospective applicant", - "childProtectionEvidence", "", - "previousAttendenceEvidence", "", - "otherGroundsEvidence", "" - )); - - caseData.put("otherPeopleInTheCaseTable", List.of(Map.of( - "id", "a5d86587-ba06-4db0-8620-10ef472af3e5", - "value", Map.of( - "address", Map.of(), - "relationshipToChild", List.of(Map.of()) - ) - ))); - - caseData.put("solicitorName", "E2E Test Solicitor"); - - caseData.put("submitAndPayDownloadApplicationLink", Map.of( - "document_filename", "Draft_C100_application.pdf", - "document_id", "e7226e49-fc92-4c12-bac5-e3e50ee4ff15" - )); - - caseData.put("summaryTabForOrderAppliedFor", Map.of( - "ordersApplyingFor", "Child Arrangements Order", - "typeOfChildArrangementsOrder", "Live with order" - )); - - Map caseMap = new HashMap<>(); - caseMap.put("id", 16611647); - caseMap.put("jurisdiction", "PRIVATELAW"); - caseMap.put("state", "SUBMITTED_PAID"); - caseMap.put("caseTypeOfApplication", "C100"); - caseMap.put("case_type_id", "PRLAPPS"); - caseMap.put("created_date", "2022-08-22T10:39:43.49"); - caseMap.put("last_modified", "2022-08-22T10:44:54.055"); - caseMap.put("case_data", caseData); - - Map response = new HashMap<>(); - response.put("total", 1); - response.put("cases", List.of(caseMap)); - - return ResponseEntity.ok(response); - } -}