From 61943ed6c6fa035e59b349c4f99c6d67f39e8ec1 Mon Sep 17 00:00:00 2001 From: MMNycz <94067802+MMNycz@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:11:37 +0000 Subject: [PATCH 1/3] CIV-10986 case not proceeding to judicial referral (#3411) * CIV-10986 fix one_v_two_two_rep validation * Update suppressions.xml * Remove updated supressions * CIV-10986 update spec shouldMoveToJudicialReferral * refactor shouldMoveToJudicialReferral method --------- Co-authored-by: mfallonhmcts <114912573+mfallonhmcts@users.noreply.github.com> --- .../user/RespondToDefenceCallbackHandler.java | 51 +--------------- .../RespondToDefenceSpecCallbackHandler.java | 3 +- .../service/flowstate/StateFlowEngine.java | 20 +++---- .../civil/utils/JudicialReferralUtils.java | 58 +++++++++++++++++++ ...spondToDefenceSpecCallbackHandlerTest.java | 2 + .../utils/JudicialReferralUtilsTest.java | 53 +++++++++++++++++ 6 files changed, 127 insertions(+), 60 deletions(-) create mode 100644 src/main/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtils.java create mode 100644 src/test/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtilsTest.java diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceCallbackHandler.java index add98412f45..7b1599b7eb8 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceCallbackHandler.java @@ -14,12 +14,10 @@ import uk.gov.hmcts.reform.civil.config.ToggleConfiguration; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; -import uk.gov.hmcts.reform.civil.enums.AllocatedTrack; import uk.gov.hmcts.reform.civil.enums.CaseCategory; import uk.gov.hmcts.reform.civil.enums.CaseState; import uk.gov.hmcts.reform.civil.enums.DocCategory; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; -import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.helpers.LocationHelper; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; @@ -36,6 +34,7 @@ import uk.gov.hmcts.reform.civil.service.Time; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; +import uk.gov.hmcts.reform.civil.utils.JudicialReferralUtils; import uk.gov.hmcts.reform.civil.utils.LocationRefDataUtil; import uk.gov.hmcts.reform.civil.utils.UnavailabilityDatesUtils; import uk.gov.hmcts.reform.civil.validation.UnavailableDateValidator; @@ -56,7 +55,6 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CLAIMANT_RESPONSE; -import static uk.gov.hmcts.reform.civil.enums.AllocatedTrack.getAllocatedTrack; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_ONE_LEGAL_REP; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_TWO_LEGAL_REP; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.TWO_V_ONE; @@ -288,57 +286,12 @@ private CallbackResponse aboutToSubmit(CallbackParams callbackParams) { return AboutToStartOrSubmitCallbackResponse.builder() .data(builder.build().toMap(objectMapper)) - .state((shouldMoveToJudicialReferral(caseData) + .state((JudicialReferralUtils.shouldMoveToJudicialReferral(caseData) ? CaseState.JUDICIAL_REFERRAL : CaseState.PROCEEDS_IN_HERITAGE_SYSTEM).name()) .build(); } - /** - * Computes whether the case data should move to judicial referral or not. - * - * @param caseData a case data such that defendants rejected the claim, and claimant(s) wants to proceed - * vs all the defendants - * @return true if and only if the case should move to judicial referral - */ - public static boolean shouldMoveToJudicialReferral(CaseData caseData) { - CaseCategory caseCategory = caseData.getCaseAccessCategory(); - - if (CaseCategory.SPEC_CLAIM.equals(caseCategory)) { - MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); - boolean addRespondent2 = YES.equals(caseData.getAddRespondent2()); - - return switch (multiPartyScenario) { - case ONE_V_ONE -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES; - case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimSpec2v1() == YesOrNo.YES; - case ONE_V_TWO_ONE_LEGAL_REP -> addRespondent2 - && YES.equals(caseData.getRespondentResponseIsSame()); - case ONE_V_TWO_TWO_LEGAL_REP -> addRespondent2 - && caseData.getRespondentResponseIsSame() == null; - }; - } else { - AllocatedTrack allocatedTrack = - getAllocatedTrack( - CaseCategory.UNSPEC_CLAIM.equals(caseCategory) - ? caseData.getClaimValue().toPounds() - : caseData.getTotalClaimAmount(), - caseData.getClaimType() - ); - if (AllocatedTrack.MULTI_CLAIM.equals(allocatedTrack)) { - return false; - } - MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); - return switch (multiPartyScenario) { - case ONE_V_ONE -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES; - case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimMultiParty2v1() == YES - && caseData.getApplicant2ProceedWithClaimMultiParty2v1() == YES; - case ONE_V_TWO_ONE_LEGAL_REP, ONE_V_TWO_TWO_LEGAL_REP -> - caseData.getApplicant1ProceedWithClaimAgainstRespondent1MultiParty1v2() == YES - && caseData.getApplicant1ProceedWithClaimAgainstRespondent2MultiParty1v2() == YES; - }; - } - } - private void updateApplicants(CaseData caseData, CaseData.CaseDataBuilder builder, StatementOfTruth statementOfTruth) { if (caseData.getApplicant1DQ() != null && caseData.getApplicant1DQ().getApplicant1DQFileDirectionsQuestionnaire() != null) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java index 9a9bad9f366..bc39dbf86fe 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java @@ -43,6 +43,7 @@ import uk.gov.hmcts.reform.civil.service.citizenui.ResponseOneVOneShowTagService; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils; +import uk.gov.hmcts.reform.civil.utils.JudicialReferralUtils; import uk.gov.hmcts.reform.civil.utils.MonetaryConversions; import uk.gov.hmcts.reform.civil.utils.UnavailabilityDatesUtils; import uk.gov.hmcts.reform.civil.validation.UnavailableDateValidator; @@ -384,7 +385,7 @@ private void updateDQCourtLocations(CallbackParams callbackParams, CaseData case private void putCaseStateInJudicialReferral(CaseData caseData, AboutToStartOrSubmitCallbackResponse.AboutToStartOrSubmitCallbackResponseBuilder response) { if (caseData.isRespondentResponseFullDefence() - && RespondToDefenceCallbackHandler.shouldMoveToJudicialReferral(caseData)) { + && JudicialReferralUtils.shouldMoveToJudicialReferral(caseData)) { response.state(CaseState.JUDICIAL_REFERRAL.name()); } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/StateFlowEngine.java b/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/StateFlowEngine.java index 03ad14f2cee..39f82bb7088 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/StateFlowEngine.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/StateFlowEngine.java @@ -3,13 +3,13 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; -import uk.gov.hmcts.reform.civil.handler.callback.user.RespondToDefenceCallbackHandler; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.stateflow.StateFlow; import uk.gov.hmcts.reform.civil.stateflow.StateFlowBuilder; import uk.gov.hmcts.reform.civil.stateflow.model.State; +import uk.gov.hmcts.reform.civil.utils.JudicialReferralUtils; import java.util.Map; @@ -18,8 +18,8 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowFlag.BULK_CLAIM_ENABLED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowFlag.GENERAL_APPLICATION_ENABLED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.agreedToMediation; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.declinedMediation; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.ccjRequestJudgmentByAdmission; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.declinedMediation; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.isLipCase; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.isTranslatedDocumentUploaded; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.partAdmitPayImmediately; @@ -40,9 +40,9 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.caseDismissedAfterDetailNotifiedExtension; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.caseDismissedPastHearingFeeDue; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.casemanMarksMediationUnsuccessful; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimDismissalOutOfTime; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.certificateOfServiceEnabled; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimDetailsNotified; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimDismissalOutOfTime; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimDismissedByCamunda; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimIssued; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimNotified; @@ -72,8 +72,8 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.fullDefenceSpec; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isClaimantNotSettlePartAdmitClaim; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isInHearingReadiness; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isRespondentResponseLangIsBilingual; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isPayImmediately; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isRespondentResponseLangIsBilingual; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.multipartyCase; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.noticeOfChangeEnabled; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.notificationAcknowledged; @@ -137,11 +137,11 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FLOW_NAME; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMISSION; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_AGREE_REPAYMENT; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_JUDGMENT_ADMISSION; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_NOT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_PAY_IMMEDIATELY; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_REJECT_REPAYMENT; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_JUDGMENT_ADMISSION; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_DEFENCE; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_DEFENCE_NOT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_DEFENCE_PROCEED; @@ -153,9 +153,9 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMISSION; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_AGREE_REPAYMENT; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_AGREE_SETTLE; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_PAY_IMMEDIATELY; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_NOT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_NOT_SETTLED_NO_MEDIATION; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_PAY_IMMEDIATELY; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_REJECT_REPAYMENT; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PAST_APPLICANT_RESPONSE_DEADLINE_AWAITING_CAMUNDA; @@ -507,20 +507,20 @@ public StateFlow build(FlowState.Main initialState) { .onlyIf(fullDefenceProceed.and(allAgreedToLrMediationSpec).and(agreedToMediation.negate()).and(declinedMediation.negate())) .set((c, flags) -> { flags.put(FlowFlag.AGREED_TO_MEDIATION.name(), true); - flags.put(FlowFlag.SDO_ENABLED.name(), RespondToDefenceCallbackHandler.shouldMoveToJudicialReferral(c)); + flags.put(FlowFlag.SDO_ENABLED.name(), JudicialReferralUtils.shouldMoveToJudicialReferral(c)); }) .transitionTo(FULL_DEFENCE_PROCEED) .onlyIf(fullDefenceProceed.and(allAgreedToLrMediationSpec.negate().and(agreedToMediation.negate())) .or(declinedMediation).and(applicantOutOfTime.negate()).and(demageMultiClaim)) .set((c, flags) -> { flags.put(FlowFlag.IS_MULTI_TRACK.name(), true); - flags.put(FlowFlag.SDO_ENABLED.name(), RespondToDefenceCallbackHandler.shouldMoveToJudicialReferral(c)); + flags.put(FlowFlag.SDO_ENABLED.name(), JudicialReferralUtils.shouldMoveToJudicialReferral(c)); }) .transitionTo(FULL_DEFENCE_PROCEED) .onlyIf(fullDefenceProceed.and(allAgreedToLrMediationSpec.negate().and(agreedToMediation.negate())) .or(declinedMediation).and(applicantOutOfTime.negate()).and(demageMultiClaim.negate())) .setDynamic(Map.of(FlowFlag.SDO_ENABLED.name(), - RespondToDefenceCallbackHandler::shouldMoveToJudicialReferral)) + JudicialReferralUtils::shouldMoveToJudicialReferral)) .transitionTo(FULL_DEFENCE_NOT_PROCEED).onlyIf(fullDefenceNotProceed) .transitionTo(TAKEN_OFFLINE_BY_STAFF).onlyIf(takenOfflineByStaffAfterDefendantResponse) .transitionTo(PAST_APPLICANT_RESPONSE_DEADLINE_AWAITING_CAMUNDA) @@ -554,7 +554,7 @@ public StateFlow build(FlowState.Main initialState) { .transitionTo(PART_ADMIT_NOT_SETTLED_NO_MEDIATION) .onlyIf(isClaimantNotSettlePartAdmitClaim.and(not(agreedToMediation))) .setDynamic(Map.of(FlowFlag.SDO_ENABLED.name(), - RespondToDefenceCallbackHandler::shouldMoveToJudicialReferral)) + JudicialReferralUtils::shouldMoveToJudicialReferral)) .transitionTo(PART_ADMIT_PROCEED).onlyIf(fullDefenceProceed) .transitionTo(PART_ADMIT_NOT_PROCEED).onlyIf(fullDefenceNotProceed) .transitionTo(PART_ADMIT_PAY_IMMEDIATELY).onlyIf(partAdmitPayImmediately) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtils.java new file mode 100644 index 00000000000..2df4c2c08f1 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtils.java @@ -0,0 +1,58 @@ +package uk.gov.hmcts.reform.civil.utils; + +import uk.gov.hmcts.reform.civil.enums.AllocatedTrack; +import uk.gov.hmcts.reform.civil.enums.CaseCategory; +import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.model.CaseData; + +import static uk.gov.hmcts.reform.civil.enums.AllocatedTrack.getAllocatedTrack; +import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; + +public class JudicialReferralUtils { + + private JudicialReferralUtils() { + //NO-OP + } + + /** + * Computes whether the case data should move to judicial referral or not. + * + * @param caseData a case data such that defendants rejected the claim, and claimant(s) wants to proceed + * vs all the defendants + * @return true if and only if the case should move to judicial referral + */ + public static boolean shouldMoveToJudicialReferral(CaseData caseData) { + CaseCategory caseCategory = caseData.getCaseAccessCategory(); + + if (CaseCategory.SPEC_CLAIM.equals(caseCategory)) { + MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); + + return switch (multiPartyScenario) { + case ONE_V_ONE, ONE_V_TWO_ONE_LEGAL_REP, ONE_V_TWO_TWO_LEGAL_REP -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES; + case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimSpec2v1() == YesOrNo.YES; + }; + } else { + AllocatedTrack allocatedTrack = + getAllocatedTrack( + CaseCategory.UNSPEC_CLAIM.equals(caseCategory) + ? caseData.getClaimValue().toPounds() + : caseData.getTotalClaimAmount(), + caseData.getClaimType() + ); + if (AllocatedTrack.MULTI_CLAIM.equals(allocatedTrack)) { + return false; + } + MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); + return switch (multiPartyScenario) { + case ONE_V_ONE -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES; + case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimMultiParty2v1() == YES + && caseData.getApplicant2ProceedWithClaimMultiParty2v1() == YES; + case ONE_V_TWO_ONE_LEGAL_REP, ONE_V_TWO_TWO_LEGAL_REP -> + caseData.getApplicant1ProceedWithClaimAgainstRespondent1MultiParty1v2() == YES + && caseData.getApplicant1ProceedWithClaimAgainstRespondent2MultiParty1v2() == YES; + }; + } + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java index 19edb10eacf..15c778c9771 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java @@ -1084,6 +1084,7 @@ void shouldChangeCaseStateToJudicialReferral_ONE_V_TWO_ONE_REP() { .addRespondent2(YES) .respondentResponseIsSame(YES) .responseClaimTrack(FAST_CLAIM.name()) + .applicant1ProceedWithClaim(YES) .applicant1DQ(Applicant1DQ.builder().applicant1RespondToClaimExperts( ExpertDetails.builder().build()).build()) .respondent1(Party.builder().type(Party.Type.INDIVIDUAL).build()).build(); @@ -1104,6 +1105,7 @@ void shouldChangeCaseStateToJudicialReferral_ONE_V_TWO_TWO_REP() { .respondent2SameLegalRepresentative(NO) .addRespondent2(YES) .responseClaimTrack(FAST_CLAIM.name()) + .applicant1ProceedWithClaim(YES) .applicant1DQ(Applicant1DQ.builder().applicant1RespondToClaimExperts( ExpertDetails.builder().build()).build()) .respondent1(Party.builder().type(Party.Type.INDIVIDUAL).build()).build(); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtilsTest.java new file mode 100644 index 00000000000..72601e30b71 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtilsTest.java @@ -0,0 +1,53 @@ +package uk.gov.hmcts.reform.civil.utils; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.civil.enums.CaseCategory; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.ClaimValue; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class JudicialReferralUtilsTest { + + @Test + public void testShouldMoveToJudicialReferralForSpecClaim() { + CaseData caseData = CaseData.builder() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .applicant1ProceedWithClaim(YesOrNo.YES) + .build(); + + boolean judicialReferralUtils = JudicialReferralUtils.shouldMoveToJudicialReferral(caseData); + assertTrue(judicialReferralUtils); + } + + @Test + public void testShouldNotMoveToJudicialReferralForSpecClaim() { + CaseData caseData = CaseData.builder() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .applicant1ProceedWithClaim(YesOrNo.NO) + .build(); + + boolean judicialReferralUtils = JudicialReferralUtils.shouldMoveToJudicialReferral(caseData); + + assertFalse(judicialReferralUtils); + } + + @Test + public void testShouldMoveToJudicialReferralForUnspecClaim() { + CaseData caseData = CaseData.builder() + .caseAccessCategory(CaseCategory.UNSPEC_CLAIM) + .claimValue(ClaimValue.builder() + .statementOfValueInPennies(BigDecimal.valueOf(10000_00)) + .build()) + .applicant1ProceedWithClaim(YesOrNo.YES) + .build(); + + boolean judicialReferralUtils = JudicialReferralUtils.shouldMoveToJudicialReferral(caseData); + assertTrue(judicialReferralUtils); + } + +} From 29cd440a9280f5b534d1239645ed5c036716ce2e Mon Sep 17 00:00:00 2001 From: LTurkingtonHMCTS <95024266+LTurkingtonHMCTS@users.noreply.github.com> Date: Tue, 7 Nov 2023 08:16:04 +0000 Subject: [PATCH 2/3] CIV-10337 eaCourtLocation WA (#3380) * Added location whitelisting mechanism * Updated unit tests * Updated commons * Added whitelisted location check to create sdo handler * --amend * Update build.gradle * Set location whitelist toggle default value to false * Update build.gradle * Update build.gradle * Update build.gradle * Update FeatureToggleService.java Set default value back to true * Update FeatureToggleService.java * default to true * fix test * change value back to false * adding eaCourtLocation to CaseDataParent * suppress cve * suppressions * update commons version * fix commons version * suppressions * populating epims id * supressions * checkstyle * updating tests * sonar exclusions * DJ eaCourtLocation, DJ tests, checkstyle * sonar exclusions * fix null pointer getEpimmsId DJ * Added early adopters toggle and updated unit tests * Removed supressions and sonar exclusions * Refactored unit tests * updated getEpimmsId to use alternate flags * adding logs * adding logs * getting track from sdoHelper * Fixed unit tests * Removed create sdo logging --------- Co-authored-by: GarethLancaster <31533575+Gareth40342@users.noreply.github.com> Co-authored-by: Gareth Lancaster <90632240+Gareth40343@users.noreply.github.com> Co-authored-by: sankaviv1 <95748224+sankaviv1@users.noreply.github.com> Co-authored-by: sankaviv1 Co-authored-by: AhsanZX97 Co-authored-by: Hemanth Potipati --- .../user/CreateSDOCallbackHandler.java | 47 ++- .../user/StandardDirectionOrderDJ.java | 47 ++- .../reform/civil/model/CaseDataParent.java | 2 + .../civil/model/common/DynamicList.java | 25 +- .../user/CreateSDOCallbackHandlerTest.java | 288 +++++++++++++++++- .../user/StandardDirectionOrderDJTest.java | 143 ++++++++- .../civil/model/common/DynamicListTest.java | 57 ++++ 7 files changed, 586 insertions(+), 23 deletions(-) create mode 100644 src/test/java/uk/gov/hmcts/reform/civil/model/common/DynamicListTest.java diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandler.java index 6aae628746a..32770c5f47a 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandler.java @@ -98,6 +98,9 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CallbackVersion.V_1; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SDO; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; +import static uk.gov.hmcts.reform.civil.enums.sdo.OrderDetailsPagesSectionsToggle.SHOW; +import static uk.gov.hmcts.reform.civil.enums.sdo.OrderType.DISPOSAL; import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; import static uk.gov.hmcts.reform.civil.utils.HearingUtils.getHearingNotes; @@ -219,7 +222,7 @@ private CallbackResponse prePopulateOrderDetailsPages(CallbackParams callbackPar updatedData.fastTrackMethodInPerson(locationsList); updatedData.smallClaimsMethodInPerson(locationsList); - List checkList = List.of(OrderDetailsPagesSectionsToggle.SHOW); + List checkList = List.of(SHOW); setCheckList(updatedData, checkList); DisposalHearingJudgesRecital tempDisposalHearingJudgesRecital = DisposalHearingJudgesRecital.builder() @@ -711,17 +714,21 @@ private DynamicList getLocationList(CallbackParams callbackParams, )); DynamicList locationsList; if (matchingLocation.isPresent()) { - locationsList = DynamicList.fromList(locations, LocationRefDataService::getDisplayEntry, + locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry, matchingLocation.get(), true ); } else { - locationsList = DynamicList.fromList(locations, LocationRefDataService::getDisplayEntry, + locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry, null, true ); } return locationsList; } + private String getLocationEpimms(LocationRefData location) { + return location.getEpimmsId(); + } + private CallbackResponse setOrderDetailsFlags(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); CaseData.CaseDataBuilder updatedData = caseData.toBuilder(); @@ -732,9 +739,9 @@ private CallbackResponse setOrderDetailsFlags(CallbackParams callbackParams) { updatedData.setFastTrackFlag(YesOrNo.NO).build(); if (SdoHelper.isSmallClaimsTrack(caseData)) { - updatedData.setSmallClaimsFlag(YesOrNo.YES).build(); + updatedData.setSmallClaimsFlag(YES).build(); } else if (SdoHelper.isFastTrack(caseData)) { - updatedData.setFastTrackFlag(YesOrNo.YES).build(); + updatedData.setFastTrackFlag(YES).build(); } return AboutToStartOrSubmitCallbackResponse.builder() @@ -836,18 +843,38 @@ private CallbackResponse submitSDO(CallbackParams callbackParams) { dataBuilder.hearingNotes(getHearingNotes(caseData)); - if (featureToggleService.isLocationWhiteListedForCaseProgression( - caseData.getCaseManagementLocation().getBaseLocation())) { - log.info("Case {} is whitelisted for case progression.", caseData.getCcdCaseReference()); - } else { - log.info("Case {} is NOT whitelisted for case progression.", caseData.getCcdCaseReference()); + if (featureToggleService.isEarlyAdoptersEnabled()) { + if (featureToggleService.isLocationWhiteListedForCaseProgression( + getEpimmsId(caseData))) { + log.info("Case {} is whitelisted for case progression.", caseData.getCcdCaseReference()); + dataBuilder.eaCourtLocation(YES); + } else { + log.info("Case {} is NOT whitelisted for case progression.", caseData.getCcdCaseReference()); + dataBuilder.eaCourtLocation(YesOrNo.NO); + } } + System.out.println("before about to submit"); + return AboutToStartOrSubmitCallbackResponse.builder() .data(dataBuilder.build().toMap(objectMapper)) .build(); } + private String getEpimmsId(CaseData caseData) { + + if (caseData.getOrderType() != null && caseData.getOrderType().equals(DISPOSAL)) { + return caseData.getDisposalHearingMethodInPerson().getValue().getCode(); + } + if (SdoHelper.isFastTrack(caseData)) { + return caseData.getFastTrackMethodInPerson().getValue().getCode(); + } + if (SdoHelper.isSmallClaimsTrack(caseData)) { + return caseData.getSmallClaimsMethodInPerson().getValue().getCode(); + } + throw new IllegalArgumentException("Could not determine claim track"); + } + private boolean nonNull(Object object) { if (object != null) { return true; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJ.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJ.java index e5202ab4def..70020cfb326 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJ.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJ.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; @@ -17,6 +18,7 @@ import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.enums.CaseCategory; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.enums.dj.DisposalAndTrialHearingDJToggle; import uk.gov.hmcts.reform.civil.enums.dj.DisposalHearingMethodDJ; import uk.gov.hmcts.reform.civil.enums.sdo.DateToShowToggle; @@ -57,6 +59,7 @@ import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; import uk.gov.hmcts.reform.civil.service.CategoryService; import uk.gov.hmcts.reform.civil.service.DeadlinesCalculator; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.docmosis.dj.DefaultJudgmentOrderFormGenerator; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.HearingMethodUtils; @@ -88,6 +91,7 @@ import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; import static uk.gov.hmcts.reform.civil.utils.HearingUtils.getHearingNotes; +@Slf4j @Service @RequiredArgsConstructor public class StandardDirectionOrderDJ extends CallbackHandler { @@ -99,6 +103,7 @@ public class StandardDirectionOrderDJ extends CallbackHandler { private final ObjectMapper objectMapper; private final DefaultJudgmentOrderFormGenerator defaultJudgmentOrderFormGenerator; private final LocationRefDataService locationRefDataService; + private final FeatureToggleService featureToggleService; String participantString; public static final String DISPOSAL_HEARING = "DISPOSAL_HEARING"; public static final String ORDER_1_CLAI = "The directions order has been sent to: " @@ -628,9 +633,22 @@ private DynamicList getLocationList(CallbackParams callbackParams, ); Optional matchingLocation = Optional.ofNullable(preferredCourt) .flatMap(requestedCourt -> locationHelper.getMatching(locations, preferredCourt)); - return DynamicList.fromList(locations, LocationRefDataService::getDisplayEntry, - matchingLocation.orElse(null), true - ); + + DynamicList locationsList; + if (matchingLocation.isPresent()) { + locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry, + matchingLocation.get(), true + ); + } else { + locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry, + null, true + ); + } + return locationsList; + } + + private String getLocationEpimms(LocationRefData location) { + return location.getEpimmsId(); } private CallbackResponse generateSDONotifications(CallbackParams callbackParams) { @@ -643,7 +661,6 @@ private CallbackResponse generateSDONotifications(CallbackParams callbackParams) caseDataBuilder.orderSDODocumentDJ(null); assignCategoryId.assignCategoryIdToCollection(caseData.getOrderSDODocumentDJCollection(), document -> document.getValue().getDocumentLink(), "sdo"); caseDataBuilder.businessProcess(BusinessProcess.ready(STANDARD_DIRECTION_ORDER_DJ)); - var state = "CASE_PROGRESSION"; String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); List locations = (locationRefDataService .getCourtLocationsForDefaultJudgments(authToken)); @@ -655,15 +672,35 @@ private CallbackResponse generateSDONotifications(CallbackParams callbackParams) .ifPresent(caseDataBuilder::locationName); } - + var state = "CASE_PROGRESSION"; caseDataBuilder.hearingNotes(getHearingNotes(caseData)); + if (featureToggleService.isEarlyAdoptersEnabled()) { + if (featureToggleService.isLocationWhiteListedForCaseProgression( + getEpimmsId(caseData))) { + log.info("Case {} is whitelisted for case progression.", caseData.getCcdCaseReference()); + caseDataBuilder.eaCourtLocation(YesOrNo.YES); + } else { + log.info("Case {} is NOT whitelisted for case progression.", caseData.getCcdCaseReference()); + caseDataBuilder.eaCourtLocation(YesOrNo.NO); + } + } + return AboutToStartOrSubmitCallbackResponse.builder() .data(caseDataBuilder.build().toMap(objectMapper)) .state(state) .build(); } + private String getEpimmsId(CaseData caseData) { + if (caseData.getTrialHearingMethodInPersonDJ() != null) { + return caseData.getTrialHearingMethodInPersonDJ().getValue().getCode(); + } else if (caseData.getDisposalHearingMethodInPersonDJ() != null) { + return caseData.getDisposalHearingMethodInPersonDJ().getValue().getCode(); + } + throw new IllegalArgumentException("Epimms Id is not provided"); + } + private SubmittedCallbackResponse buildConfirmation(CallbackParams callbackParams) { var caseData = callbackParams.getCaseData(); return SubmittedCallbackResponse.builder() diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java index 4c06a057441..9e490085485 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java @@ -311,6 +311,8 @@ public class CaseDataParent implements MappableObject { private CaseDocument sdoOrderDocument; + private final YesOrNo eaCourtLocation; + // sdo ui flags private final YesOrNo setSmallClaimsFlag; private final YesOrNo setFastTrackFlag; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/common/DynamicList.java b/src/main/java/uk/gov/hmcts/reform/civil/model/common/DynamicList.java index 1fe3e01a3f6..075db0e94a5 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/common/DynamicList.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/common/DynamicList.java @@ -16,7 +16,7 @@ */ @Data @Jacksonized -@Builder +@Builder(toBuilder = true) public class DynamicList { /** @@ -39,18 +39,20 @@ public static DynamicList fromList(List list) { } /** - * Sometimes a dynamic list can be prepopulated with a value. + * A dynamic list can be pre-populated with a code and value. * * @param list the original list of items + * @param toCode (optional) how to populate the DynamicListElement code, defaults to random UUID * @param toLabel how to create the label * @param value (optional) value to be selected * @param type of element * @return dynamic list, possibly with value set */ - public static DynamicList fromList(List list, Function toLabel, T value, boolean sort) { + public static DynamicList fromList(List list, Function toCode, Function toLabel, T value, boolean sort) { List items = list.stream() - .map(toLabel) - .map(DynamicListElement::dynamicElement) + .map(item -> toCode != null + ? DynamicListElement.dynamicElementFromCode(toCode.apply(item), toLabel.apply(item)) + : DynamicListElement.dynamicElement(toLabel.apply(item))) .collect(toList()); int index = value != null ? list.indexOf(value) : -1; @@ -68,6 +70,19 @@ public static DynamicList fromList(List list, Function toLabel return DynamicList.builder().listItems(items).value(chosen).build(); } + /** + * Sometimes a dynamic list can be pre-populated with a value. + * + * @param list the original list of items + * @param toLabel how to create the label + * @param value (optional) value to be selected + * @param type of element + * @return dynamic list, possibly with value set + */ + public static DynamicList fromList(List list, Function toLabel, T value, boolean sort) { + return fromList(list, null, toLabel, value, sort); + } + public static DynamicList fromDynamicListElementList(List list) { return DynamicList.builder().listItems(list).value(DynamicListElement.EMPTY).build(); } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandlerTest.java index 208f29cbf58..505d72475f1 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandlerTest.java @@ -1,9 +1,12 @@ package uk.gov.hmcts.reform.civil.handler.callback.user; import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -65,9 +68,11 @@ import java.util.stream.Collectors; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; @@ -76,6 +81,8 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SDO; import static uk.gov.hmcts.reform.civil.enums.CaseCategory.SPEC_CLAIM; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.handler.callback.user.CreateSDOCallbackHandler.CONFIRMATION_HEADER; import static uk.gov.hmcts.reform.civil.handler.callback.user.CreateSDOCallbackHandler.CONFIRMATION_SUMMARY_1v1; import static uk.gov.hmcts.reform.civil.handler.callback.user.CreateSDOCallbackHandler.CONFIRMATION_SUMMARY_1v2; @@ -142,6 +149,49 @@ void setup() { .thenReturn(LocalDate.now().plusDays(7)); } + @Test + void shouldPopulateLocationListsWithPreselectedCourt() { + Category category = Category.builder().categoryKey("HearingChannel").key("INTER").valueEn("In Person").activeFlag("Y").build(); + CategorySearchResult categorySearchResult = CategorySearchResult.builder().categories(List.of(category)).build(); + String preSelectedCourt = "214320"; + List locations = List.of( + LocationRefData.builder().epimmsId("00001").courtLocationCode("00001") + .siteName("court 1").courtAddress("1 address").postcode("Y01 7RB").build(), + LocationRefData.builder().epimmsId(preSelectedCourt).courtLocationCode(preSelectedCourt) + .siteName("court 2").courtAddress("2 address").postcode("Y02 7RB").build(), + LocationRefData.builder().epimmsId("00003").courtLocationCode("00003") + .siteName("court 3").courtAddress("3 address").postcode("Y03 7RB").build() + ); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(anyString())).thenReturn(locations); + when(categoryService.findCategoryByCategoryIdAndServiceId(any(), any(), any())).thenReturn(Optional.of(categorySearchResult)); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft() + .atStateClaimIssuedDisposalHearingSDOInPersonHearing().build(); + + CallbackParams params = callbackParamsOf(CallbackVersion.V_1, caseData, ABOUT_TO_START); + CaseDocument order = CaseDocument.builder().documentLink( + Document.builder().documentUrl("url").build()) + .build(); + when(sdoGeneratorService.generate(any(), any())).thenReturn(order); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + DynamicList expected = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code(preSelectedCourt).label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code(preSelectedCourt).label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + assertThat(responseCaseData.getDisposalHearingMethodInPerson()).isEqualTo(expected); + assertThat(responseCaseData.getFastTrackMethodInPerson()).isEqualTo(expected); + assertThat(responseCaseData.getSmallClaimsMethodInPerson()).isEqualTo(expected); + } + @Test void shouldGenerateDynamicListsCorrectly() { Category category = Category.builder().categoryKey("HearingChannel").key("INTER").valueEn("In Person").activeFlag("Y").build(); @@ -194,8 +244,15 @@ class AboutToSubmitCallback { @BeforeEach void setup() { + List items = List.of("label 1", "label 2", "label 3"); + DynamicList options = DynamicList.fromList(items, Object::toString, items.get(0), false); caseData = CaseDataBuilder.builder().atStateClaimDraft() .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .build().toBuilder() + .disposalHearingMethodInPerson(options) + .fastTrackMethodInPerson(options) + .smallClaimsMethodInPerson(options) + .setFastTrackFlag(YES) .build(); params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); userId = UUID.randomUUID().toString(); @@ -206,11 +263,20 @@ void setup() { given(time.now()).willReturn(submittedDate); given(featureToggleService.isLocationWhiteListedForCaseProgression(anyString())).willReturn(true); + + given(featureToggleService.isEarlyAdoptersEnabled()).willReturn(true); } @Test void shouldUpdateBusinessProcess_whenInvoked() { - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle( + params.toBuilder() + .caseData(params.getCaseData().toBuilder() + .claimsTrack(ClaimsTrack.smallClaimsTrack) + .drawDirectionsOrderRequired(NO) + .build()) + .build() + ); assertThat(response.getData()) .extracting("businessProcess") @@ -249,6 +315,8 @@ void shouldNotUpdateCaseLocation_whenDisposal() { .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) .disposalHearingMethod(DisposalHearingMethod.disposalHearingMethodInPerson) .disposalHearingMethodInPerson(options) + .fastTrackMethodInPerson(options) + .smallClaimsMethodInPerson(options) .disposalHearingMethodToggle(Collections.singletonList(OrderDetailsPagesSectionsToggle.SHOW)) .caseManagementLocation(previousManagementLocation) .build(); @@ -314,6 +382,8 @@ void shouldNotUpdateCaseLocation_whenSmallClaims() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) .smallClaimsMethod(SmallClaimsMethod.smallClaimsMethodInPerson) + .disposalHearingMethodInPerson(options) + .fastTrackMethodInPerson(options) .smallClaimsMethodInPerson(options) .claimsTrack(ClaimsTrack.smallClaimsTrack) .caseManagementLocation(previousManagementLocation) @@ -372,7 +442,7 @@ void shouldNotUpdateCaseLocation_whenFastTrackAndOrderRequired() { @Test void shouldNotUpdateCaseLocation_whenSmallClaimsAndOrderRequired() { List items = List.of("label 1", "label 2", "label 3"); - DynamicList options = DynamicList.fromList(items, Object::toString, items.get(0), false); + DynamicList options = DynamicList.fromList(items, Object::toString, Object::toString, items.get(0), false); CaseLocationCivil previousManagementLocation = CaseLocationCivil.builder() .region("previous region") .baseLocation("previous base location") @@ -380,6 +450,8 @@ void shouldNotUpdateCaseLocation_whenSmallClaimsAndOrderRequired() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) .smallClaimsMethod(SmallClaimsMethod.smallClaimsMethodInPerson) + .fastTrackMethodInPerson(options) + .disposalHearingMethodInPerson(options) .smallClaimsMethodInPerson(options) .drawDirectionsOrderRequired(YesOrNo.YES) .drawDirectionsOrderSmallClaims(YesOrNo.YES) @@ -404,8 +476,14 @@ void shouldNotUpdateCaseLocation_whenSmallClaimsAndOrderRequired() { @Test void shouldReturnNullDocument_whenInvokedAboutToSubmit() { + List items = List.of("label 1", "label 2", "label 3"); + DynamicList options = DynamicList.fromList(items, Object::toString, Object::toString, items.get(0), false); CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .build().toBuilder() + .fastTrackMethodInPerson(options) + .disposalHearingMethodInPerson(options) + .smallClaimsMethodInPerson(options) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -415,6 +493,212 @@ void shouldReturnNullDocument_whenInvokedAboutToSubmit() { } } + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldSetEarlyAdoptersFlag_whenDisposal(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + DynamicListElement selectedCourt = DynamicListElement.builder() + .code("00002").label("court 2 - 2 address - Y02 7RB").build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .disposalHearingMethod(DisposalHearingMethod.disposalHearingMethodInPerson) + .disposalHearingMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .fastTrackMethodInPerson(options) + .smallClaimsMethodInPerson(options) + .disposalHearingMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .disposalHearingMethodToggle(Collections.singletonList(OrderDetailsPagesSectionsToggle.SHOW)) + .orderType(OrderType.DISPOSAL) + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(selectedCourt.getCode()))).thenReturn( + isLocationWhiteListed); + when(locationRefDataService.getLocationMatchingLabel(selectedCourt.getCode(), params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())) + .thenReturn(Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("site name") + .build())); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); + } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldSetEarlyAdoptersFlag_whenSmallClaims(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + DynamicListElement selectedCourt = DynamicListElement.builder() + .code("00002").label("court 2 - 2 address - Y02 7RB").build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .smallClaimsMethod(SmallClaimsMethod.smallClaimsMethodInPerson) + .disposalHearingMethodInPerson(options) + .fastTrackMethodInPerson(options) + .smallClaimsMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .claimsTrack(ClaimsTrack.smallClaimsTrack) + .setSmallClaimsFlag(YES) + .drawDirectionsOrderRequired(NO) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(selectedCourt.getCode()))).thenReturn( + isLocationWhiteListed); + when(locationRefDataService.getLocationMatchingLabel("label 1", params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())).thenReturn( + Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("location name") + .build())); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); + } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldSetEarlyAdoptersFlag_whenFastTrack(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + DynamicListElement selectedCourt = DynamicListElement.builder() + .code("00002").label("court 2 - 2 address - Y02 7RB").build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .fastTrackMethod(FastTrackMethod.fastTrackMethodInPerson) + .smallClaimsMethodInPerson(options) + .fastTrackMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .disposalHearingMethodInPerson(options) + .claimsTrack(ClaimsTrack.fastTrack) + .setFastTrackFlag(YES) + .drawDirectionsOrderRequired(NO) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(selectedCourt.getCode()))).thenReturn( + isLocationWhiteListed); + when(locationRefDataService.getLocationMatchingLabel("label 1", params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())).thenReturn( + Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("location name") + .build())); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); + } + + @Test + @SneakyThrows + void shouldThrowIllegalArgumentException_whenClaimTrackCannotDefined() { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .fastTrackMethod(FastTrackMethod.fastTrackMethodInPerson) + .smallClaimsMethodInPerson(options) + .fastTrackMethodInPerson(options) + .disposalHearingMethodInPerson(options) + .claimsTrack(ClaimsTrack.fastTrack) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(locationRefDataService.getLocationMatchingLabel("label 1", params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())).thenReturn( + Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("location name") + .build())); + + assertThrows(IllegalArgumentException.class, () -> handler.handle(params), + "Epimms Id is not provided" + ); + } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldNotSetEarlyAdoptersFlag_whenEarlyAdoptersToggleIsOff(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + DynamicListElement selectedCourt = DynamicListElement.builder() + .code("00002").label("court 2 - 2 address - Y02 7RB").build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .fastTrackMethod(FastTrackMethod.fastTrackMethodInPerson) + .fastTrackMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .smallClaimsMethodInPerson(options) + .disposalHearingMethodInPerson(options) + .claimsTrack(ClaimsTrack.fastTrack) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(false); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(selectedCourt.getCode()))).thenReturn( + isLocationWhiteListed); + when(locationRefDataService.getLocationMatchingLabel("label 1", params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())).thenReturn( + Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("location name") + .build())); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isNull(); + } + @Nested class MidEventDisposalHearingLocationRefDataCallback extends LocationRefSampleDataBuilder { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJTest.java index 4f94e09294f..3fea6f64824 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @@ -49,6 +51,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; @@ -57,6 +61,7 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.ACKNOWLEDGEMENT_OF_CLAIM; import static uk.gov.hmcts.reform.civil.enums.CaseCategory.UNSPEC_CLAIM; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; @@ -544,6 +549,44 @@ void shouldPrePopulateDJTrialHearingToggle() { var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getData()).extracting("trialHearingVariationsDirectionsDJToggle").isNotNull(); + assertThat(response.getData()).extracting("trialHearingVariationsDirectionsDJToggle").isNotNull(); + } + + @Test + void shouldPopulateLocationListsWithPreselectedCourt() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimDraft() + .atStateClaimIssuedTrialHearing() + .build(); + + String preSelectedCourt = "214320"; + + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + List locations = List.of( + LocationRefData.builder().epimmsId("00001").courtLocationCode("00001") + .siteName("court 1").courtAddress("1 address").postcode("Y01 7RB").build(), + LocationRefData.builder().epimmsId(preSelectedCourt).courtLocationCode(preSelectedCourt) + .siteName("court 2").courtAddress("2 address").postcode("Y02 7RB").build(), + LocationRefData.builder().epimmsId("00003").courtLocationCode("00003") + .siteName("court 3").courtAddress("3 address").postcode("Y03 7RB").build() + ); + + when(locationRefDataService.getCourtLocationsForDefaultJudgments(anyString())).thenReturn(locations); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = mapper.convertValue(response.getData(), CaseData.class); + DynamicList expected = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code(preSelectedCourt).label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code(preSelectedCourt).label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + assertThat(responseCaseData.getTrialHearingMethodInPersonDJ()).isEqualTo(expected); + assertThat(responseCaseData.getDisposalHearingMethodInPersonDJ()).isEqualTo(expected); } @Test @@ -693,9 +736,21 @@ void shouldCreateAndSaveSDOOrder_whenStateClaimIssuedDisposalSDOVideoCall() { @Nested class AboutToSubmitCallback { + + @BeforeEach + void setup() { + given(featureToggleService.isEarlyAdoptersEnabled()).willReturn(true); + } + @Test void shouldFinishBusinessProcess() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build(); + List items = List.of("label 1", "label 2", "label 3"); + DynamicList options = DynamicList.fromList(items, Object::toString, Object::toString, items.get(0), false); + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build() + .toBuilder() + .disposalHearingMethodInPersonDJ(options) + .trialHearingMethodInPersonDJ(options) + .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getData()).extracting("businessProcess").isNotNull(); @@ -717,9 +772,13 @@ void shouldAssignCategoryId_whenInvoked() { .build(); List> documentList = new ArrayList<>(); documentList.add(element(testDocument)); + List items = List.of("label 1", "label 2", "label 3"); + DynamicList options = DynamicList.fromList(items, Object::toString, items.get(0), false); //Given when(featureToggleService.isCaseFileViewEnabled()).thenReturn(true); CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .trialHearingMethodInPersonDJ(options) + .disposalHearingMethodInPersonDJ(options) .orderSDODocumentDJCollection(documentList) .build(); @@ -730,6 +789,88 @@ void shouldAssignCategoryId_whenInvoked() { //Then assertThat(updatedData.getOrderSDODocumentDJCollection().get(0).getValue().getDocumentLink().getCategoryID()).isEqualTo("sdo"); } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldPopulateEarlyAdoptersFlag_whenDisposalHearingMethodInPersonDJIsSet(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build() + .toBuilder() + .disposalHearingMethodInPersonDJ(options) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(options.getValue().getCode()))).thenReturn( + isLocationWhiteListed); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = mapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); + } + + @Test + void shouldNotPopulateEarlyAdoptersFlag_whenEarlyAdoptersToggleIsOff() { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build() + .toBuilder() + .disposalHearingMethodInPersonDJ(options) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(false); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(options.getValue().getCode()))) + .thenReturn(true); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = mapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isNull(); + } + } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldPopulateEarlyAdoptersFlag_whenTrialHearingMethodInPersonDJIsSet(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build() + .toBuilder() + .trialHearingMethodInPersonDJ(options) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(options.getValue().getCode()))).thenReturn( + isLocationWhiteListed); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = mapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); } @Nested diff --git a/src/test/java/uk/gov/hmcts/reform/civil/model/common/DynamicListTest.java b/src/test/java/uk/gov/hmcts/reform/civil/model/common/DynamicListTest.java new file mode 100644 index 00000000000..1aef0b2539b --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/model/common/DynamicListTest.java @@ -0,0 +1,57 @@ +package uk.gov.hmcts.reform.civil.model.common; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.List; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class DynamicListTest { + + private List listItems; + + @BeforeEach + public void setUp() { + listItems = Arrays.asList("Item1", "Item2", "Item3"); + } + + @Test + public void shouldPopulateDynamicListFromList_whenCodeFunctionIsProvided() { + Function toCode = item -> item + "_code"; + Function toLabel = item -> item + "_label"; + String value = "Item2"; + + DynamicList actual = DynamicList.fromList(listItems, toCode, toLabel, value, true); + + DynamicList expected = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("Item1_code").label("Item1_label").build(), + DynamicListElement.builder().code("Item2_code").label("Item2_label").build(), + DynamicListElement.builder().code("Item3_code").label("Item3_label").build() + )) + .value(DynamicListElement.builder().code("Item2_code").label("Item2_label").build()) + .build(); + + assertEquals(expected, actual); + } + + @Test + public void shouldPopulateDynamicListFromList_whenCodeFunctionIsNotProvided() { + Function toLabel = item -> item + "_label"; + String value = "Item2"; + + DynamicList actual = DynamicList.fromList(listItems, null, toLabel, value, true); + + assertNotNull(actual.getListItems().get(0).getCode()); + assertEquals("Item1_label", actual.getListItems().get(0).getLabel()); + assertNotNull(actual.getListItems().get(1).getCode()); + assertEquals("Item2_label", actual.getListItems().get(1).getLabel()); + assertNotNull(actual.getListItems().get(2).getCode()); + assertEquals("Item3_label", actual.getListItems().get(2).getLabel()); + assertNotNull(actual.getValue().getCode()); + assertEquals("Item2_label", actual.getValue().getLabel()); + } +} From 3e31b4940a7871b5d55823a80ab855d6e2cdd117 Mon Sep 17 00:00:00 2001 From: m-meulendijks-v1 <107135537+m-meulendijks-v1@users.noreply.github.com> Date: Tue, 7 Nov 2023 09:18:42 +0000 Subject: [PATCH 3/3] CIV-11414 - Updated trial ready WA search services (#3528) * CIV-11414 - Updated trial ready WA search services * CIV-11414 - updated tests --------- Co-authored-by: vasudevganesanhmcts <100689363+vasudevganesanhmcts@users.noreply.github.com> --- .../service/search/TrialReadyCheckSearchService.java | 6 +++++- .../search/TrialReadyNotificationSearchService.java | 8 ++++++-- .../service/search/TrialReadyCheckSearchServiceTest.java | 5 ++++- .../search/TrialReadyNotificationSearchServiceTest.java | 7 +++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchService.java index d23f38cf85b..b418a6a16fd 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchService.java @@ -13,6 +13,7 @@ import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.index.query.QueryBuilders.rangeQuery; +import static uk.gov.hmcts.reform.civil.enums.CaseState.HEARING_READINESS; import static uk.gov.hmcts.reform.civil.enums.CaseState.PREPARE_FOR_HEARING_CONDUCT_HEARING; @Service @@ -30,7 +31,10 @@ public Query query(int startIndex) { .must(rangeQuery("data.hearingDate").lt(LocalDate.now() .atTime(LocalTime.MIN).plusWeeks(3) .toString())) - .must(beState(PREPARE_FOR_HEARING_CONDUCT_HEARING)) + .must(boolQuery() + .minimumShouldMatch(1) + .should(beState(PREPARE_FOR_HEARING_CONDUCT_HEARING)) + .should(beState(HEARING_READINESS))) .mustNot(matchQuery("data.allocatedTrack", "SMALL_CLAIM")) .mustNot(matchQuery("data.trialReadyChecked", "Yes"))), List.of("reference"), diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchService.java index 878b2f73638..53a26cd55e1 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchService.java @@ -15,6 +15,7 @@ import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.index.query.QueryBuilders.rangeQuery; +import static uk.gov.hmcts.reform.civil.enums.CaseState.HEARING_READINESS; import static uk.gov.hmcts.reform.civil.enums.CaseState.PREPARE_FOR_HEARING_CONDUCT_HEARING; @Service @@ -32,10 +33,13 @@ public Query query(int startIndex) { .must(rangeQuery("data.hearingDate").lt(LocalDate.now() .atTime(LocalTime.MIN) .plusWeeks(6).toString())) - .must(beState(PREPARE_FOR_HEARING_CONDUCT_HEARING))) + .must(boolQuery() + .minimumShouldMatch(1) + .should(beState(PREPARE_FOR_HEARING_CONDUCT_HEARING)) + .should(beState(HEARING_READINESS))) .mustNot(matchQuery("data.allocatedTrack", "SMALL_CLAIM")) .mustNot(matchQuery("data.listingOrRelisting", ListingOrRelisting.RELISTING)) - .mustNot(matchQuery("data.trialReadyNotified", YesOrNo.YES)), + .mustNot(matchQuery("data.trialReadyNotified", YesOrNo.YES))), List.of("reference"), startIndex ); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchServiceTest.java index 0aefcb6a5c2..24a6e6b3716 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchServiceTest.java @@ -26,7 +26,10 @@ protected Query buildQuery(int fromValue) { .should(boolQuery() .must(rangeQuery("data.hearingDate").lt(LocalDate.now().atTime(LocalTime.MIN).plusWeeks(3) .toString())) - .must(boolQuery().must(matchQuery("state", "PREPARE_FOR_HEARING_CONDUCT_HEARING"))) + .must(boolQuery() + .minimumShouldMatch(1) + .should(boolQuery().must(matchQuery("state", "PREPARE_FOR_HEARING_CONDUCT_HEARING"))) + .should(boolQuery().must(matchQuery("state", "HEARING_READINESS")))) .mustNot(matchQuery("data.allocatedTrack", "SMALL_CLAIM")) .mustNot(matchQuery("data.trialReadyChecked", "Yes"))); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchServiceTest.java index 961b2c67253..f94d49c3430 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchServiceTest.java @@ -28,10 +28,13 @@ protected Query buildQuery(int fromValue) { .should(boolQuery() .must(rangeQuery("data.hearingDate").lt(LocalDate.now().atTime(LocalTime.MIN).plusWeeks(6) .toString())) - .must(boolQuery().must(matchQuery("state", "PREPARE_FOR_HEARING_CONDUCT_HEARING")))) + .must(boolQuery() + .minimumShouldMatch(1) + .should(boolQuery().must(matchQuery("state", "PREPARE_FOR_HEARING_CONDUCT_HEARING"))) + .should(boolQuery().must(matchQuery("state", "HEARING_READINESS")))) .mustNot(matchQuery("data.allocatedTrack", "SMALL_CLAIM")) .mustNot(matchQuery("data.listingOrRelisting", ListingOrRelisting.RELISTING)) - .mustNot(matchQuery("data.trialReadyNotified", YesOrNo.YES)); + .mustNot(matchQuery("data.trialReadyNotified", YesOrNo.YES))); return new Query(query, List.of("reference"), fromValue); }