diff --git a/build.gradle b/build.gradle index ca6ca6fb433..03857cea73b 100644 --- a/build.gradle +++ b/build.gradle @@ -314,7 +314,7 @@ sonarqube { property "sonar.projectName", "CIVIL :: service" property "sonar.projectKey", "civil-service" property "sonar.coverage.jacoco.xmlReportPaths", "${jacocoTestReport.reports.xml.destination.path}" - property "sonar.coverage.exclusions", "**/model/**, **/config/**/*Configuration.java, **/testingsupport/**, **/*ExternalTaskListener.java, **/*BaseExternalTaskHandler.java, **/stereotypes/**, **/*Exception.java, **/EventHistoryMapper*.java, **/model/hearingvalues/**, **/enums/hearing/**, **/fees/client/**, **/enums/sdo/**, **/service/PaymentsService.java, **/RetriggerCases*.java" + property "sonar.coverage.exclusions", "**/model/**, **/config/**/*Configuration.java, **/testingsupport/**, **/*ExternalTaskListener.java, **/*BaseExternalTaskHandler.java, **/stereotypes/**, **/*Exception.java, **/EventHistoryMapper*.java, **/model/hearingvalues/**, **/enums/hearing/**, **/fees/client/**, **/enums/sdo/**, **/service/PaymentsService.java" property "sonar.cpd.exclusions", "**/*DocumentManagementService.java, **/*Spec*.java, **/*CcdDashboardClaimantClaimMatcher.java" property "sonar.exclusions", "**/hmc/model/**, **/model/hearingvalues/**" property "sonar.host.url", "https://sonar.reform.hmcts.net/" diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/RetriggerCasesEventHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/RetriggerCasesEventHandler.java index 08e6562df3a..ecb14390ff5 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/RetriggerCasesEventHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/RetriggerCasesEventHandler.java @@ -6,9 +6,6 @@ import org.apache.commons.io.IOUtils; import org.camunda.bpm.client.task.ExternalTask; import org.springframework.stereotype.Component; -import uk.gov.hmcts.reform.ccd.client.model.CaseDataContent; -import uk.gov.hmcts.reform.ccd.client.model.Event; -import uk.gov.hmcts.reform.ccd.client.model.StartEventResponse; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.handler.tasks.BaseExternalTaskHandler; import uk.gov.hmcts.reform.civil.service.CoreCaseDataService; @@ -18,7 +15,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -39,26 +35,21 @@ public void handleTask(ExternalTask externalTask) { updateCaseByEvent(caseIdForNotifyRpaOnCaseHandedOffline, RETRIGGER_CASES); } - private void updateCaseByEvent(List caseIdList, CaseEvent caseEvent) { + public void updateCaseByEvent(List caseIdList, CaseEvent caseEvent) { if (caseIdList != null && !caseIdList.isEmpty()) { log.info("Retrigger cases started for event: {}", caseEvent); caseIdList.forEach(caseId -> { try { log.info("Retrigger CaseId: {} started", caseId); - var startEventResponse = coreCaseDataService.startUpdate(caseId, caseEvent); - - Map caseDataMap = coreCaseDataService.getCase(Long.valueOf(caseId)).getData(); - - coreCaseDataService.submitUpdate(caseId, caseDataContent(startEventResponse, caseDataMap)); + coreCaseDataService.triggerEvent(Long.parseLong(caseId), caseEvent); log.info("Retrigger CaseId: {} finished", caseId); } catch (FeignException e) { log.error("ERROR Retrigger CaseId: {}", caseId); - log.error(String.format("Updating case data failed: %s", e.contentUTF8())); + log.error(String.format("Retrigger case failed: %s", e.contentUTF8())); throw e; } catch (Exception e) { - log.error("ERROR Retrigger CaseId: {}", caseId); - log.error(String.format("Updating case data failed: %s", e.getMessage())); + throw e; } log.info("Retrigger cases Finished for event: {}", caseEvent); }); @@ -68,17 +59,6 @@ private void updateCaseByEvent(List caseIdList, CaseEvent caseEvent) { } - private CaseDataContent caseDataContent(StartEventResponse startEventResponse, Map caseDataMap) { - Map data = startEventResponse.getCaseDetails().getData(); - data.putAll(caseDataMap); - - return CaseDataContent.builder() - .eventToken(startEventResponse.getToken()) - .event(Event.builder().id(startEventResponse.getEventId()).build()) - .data(data) - .build(); - } - public List readCaseIds(String file) { String data = readString(file); @@ -93,7 +73,7 @@ private String readString(String resourcePath) { return new String(readBytes(resourcePath), StandardCharsets.UTF_8); } - private byte[] readBytes(String resourcePath) { + byte[] readBytes(String resourcePath) { try (InputStream inputStream = RetriggerCasesEventHandler.class.getResourceAsStream(resourcePath)) { return IOUtils.toByteArray(inputStream); } catch (IOException e) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/CcdDashboardClaimantClaimMatcher.java b/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/CcdDashboardClaimantClaimMatcher.java index 0b6bb762b99..9855f6be349 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/CcdDashboardClaimantClaimMatcher.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/CcdDashboardClaimantClaimMatcher.java @@ -247,8 +247,9 @@ public boolean isMediationPending() { @Override public boolean isCourtReviewing() { return (!hasSdoBeenDrawn() - && caseData.isRespondentResponseFullDefence() - && caseData.getCcdState().equals(CaseState.JUDICIAL_REFERRAL)) + && (caseData.isRespondentResponseFullDefence() + || caseData.isPartAdmitClaimSpec()) + && CaseState.JUDICIAL_REFERRAL.equals(caseData.getCcdState())) || (caseData.hasApplicantRejectedRepaymentPlan()); } @@ -278,7 +279,7 @@ public boolean hasClaimantRejectOffer() { @Override public boolean isPartialAdmissionRejected() { return CaseState.JUDICIAL_REFERRAL.equals(caseData.getCcdState()) - && caseData.isPartAdmitClaimSpec(); + && caseData.isPartAdmitClaimSpec() && YesOrNo.NO.equals(caseData.getApplicant1PartAdmitConfirmAmountPaidSpec()); } @Override @@ -293,5 +294,4 @@ public boolean isClaimantDefaultJudgement() { && caseData.getRespondent1ResponseDeadline().isBefore(LocalDate.now().atTime(FOUR_PM)) && caseData.getPaymentTypeSelection() != null; } - } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/DashboardClaimStatus.java b/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/DashboardClaimStatus.java index 83716bcd9a8..c297110458b 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/DashboardClaimStatus.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/DashboardClaimStatus.java @@ -6,6 +6,12 @@ public enum DashboardClaimStatus { + MEDIATION_UNSUCCESSFUL( + Claim::isMediationUnsuccessful + ), + MEDIATION_SUCCESSFUL( + Claim::isMediationSuccessful + ), CLAIMANT_REJECT_PARTIAL_ADMISSION( Claim::isPartialAdmissionRejected ), @@ -21,12 +27,6 @@ public enum DashboardClaimStatus { MORE_DETAILS_REQUIRED( Claim::isMoreDetailsRequired ), - MEDIATION_UNSUCCESSFUL( - Claim::isMediationUnsuccessful - ), - MEDIATION_SUCCESSFUL( - Claim::isMediationSuccessful - ), IN_MEDIATION( Claim::isMediationPending ), diff --git a/src/main/resources/caseIdForRetrigger.txt b/src/main/resources/caseIdForRetrigger.txt index 301cfca6940..75a619adbf3 100644 --- a/src/main/resources/caseIdForRetrigger.txt +++ b/src/main/resources/caseIdForRetrigger.txt @@ -1 +1 @@ -1693404277952499 +1694435036274857 diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/RetriggerCasesEventHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/RetriggerCasesEventHandlerTest.java new file mode 100644 index 00000000000..ac0c133583e --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/RetriggerCasesEventHandlerTest.java @@ -0,0 +1,86 @@ +package uk.gov.hmcts.reform.civil.handler; + +import feign.FeignException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.service.CoreCaseDataService; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +class RetriggerCasesEventHandlerTest { + + @Mock + private CoreCaseDataService coreCaseDataService; + + @InjectMocks + private RetriggerCasesEventHandler retriggerCasesEventHandler; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + void testUpdateCaseByEvent() { + List caseIdList = Arrays.asList("1", "2", "3"); + + retriggerCasesEventHandler.updateCaseByEvent(caseIdList, CaseEvent.RETRIGGER_CASES); + + // Assertions + verify(coreCaseDataService, times(caseIdList.size())).triggerEvent(anyLong(), eq(CaseEvent.RETRIGGER_CASES)); + } + + @Test + void testUpdateCaseByEventWithFeignException() { + List caseIdList = Arrays.asList("1", "2", "3"); + + // Simulate FeignException + doThrow(FeignException.class).when(coreCaseDataService).triggerEvent(anyLong(), eq(CaseEvent.RETRIGGER_CASES)); + + // Assertions + FeignException exception = assertThrows(FeignException.class, () -> + retriggerCasesEventHandler.updateCaseByEvent(caseIdList, CaseEvent.RETRIGGER_CASES) + ); + } + + @Test + void testUpdateCaseByEventWithGenericException() { + List caseIdList = Arrays.asList("1", "2", "3"); + + doThrow(new RuntimeException("Simulated RuntimeException")).when(coreCaseDataService) + .triggerEvent(anyLong(), eq(CaseEvent.RETRIGGER_CASES)); + + RuntimeException exception = assertThrows(RuntimeException.class, () -> + retriggerCasesEventHandler.updateCaseByEvent(caseIdList, CaseEvent.RETRIGGER_CASES) + ); + + assertEquals("Simulated RuntimeException", exception.getMessage()); + } + + @Test + void testUpdateCaseByEventWithEmptyList() { + List emptyCaseIdList = Collections.emptyList(); + + retriggerCasesEventHandler.updateCaseByEvent(emptyCaseIdList, CaseEvent.RETRIGGER_CASES); + + // Assertions + verify(coreCaseDataService, never()).triggerEvent(anyLong(), eq(CaseEvent.RETRIGGER_CASES)); + } +} + + diff --git a/src/test/java/uk/gov/hmcts/reform/civil/model/citizenui/CcdClaimStatusDashboardFactoryTest.java b/src/test/java/uk/gov/hmcts/reform/civil/model/citizenui/CcdClaimStatusDashboardFactoryTest.java index 3b77acb3d44..c37552f429f 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/model/citizenui/CcdClaimStatusDashboardFactoryTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/model/citizenui/CcdClaimStatusDashboardFactoryTest.java @@ -279,6 +279,7 @@ void given_mediation_whenGetSatus_mediationSuccessful() { .mediationAgreement(MediationAgreementDocument.builder().build()) .build()) .build()) + .respondent1ClaimResponseTypeForSpec(PART_ADMISSION) .build(); DashboardClaimStatus status = ccdClaimStatusDashboardFactory.getDashboardClaimStatus(new CcdDashboardDefendantClaimMatcher( claim, featureToggleService)); @@ -288,10 +289,12 @@ void given_mediation_whenGetSatus_mediationSuccessful() { @Test void given_mediation_whenGetStatus_mediationUnsuccessful() { CaseData claim = CaseData.builder() + .ccdState(CaseState.JUDICIAL_REFERRAL) .respondent1ResponseDate(LocalDateTime.now()) .mediation(Mediation.builder() .unsuccessfulMediationReason("this is a reason") .build()) + .respondent1ClaimResponseTypeForSpec(PART_ADMISSION) .build(); DashboardClaimStatus status = ccdClaimStatusDashboardFactory.getDashboardClaimStatus(new CcdDashboardDefendantClaimMatcher( claim, featureToggleService)); @@ -345,6 +348,7 @@ void given_applicantRejectPartialAdmit_whenGetStatus_rejectOffer() { .respondent1ResponseDate(LocalDateTime.now()) .respondent1ClaimResponseTypeForSpec(PART_ADMISSION) .applicant1AcceptPartAdmitPaymentPlanSpec(YesOrNo.NO) + .applicant1AcceptAdmitAmountPaidSpec(YesOrNo.NO) .ccdState(CaseState.JUDICIAL_REFERRAL) .build(); DashboardClaimStatus status = ccdClaimStatusDashboardFactory.getDashboardClaimStatus(new CcdDashboardDefendantClaimMatcher( @@ -413,7 +417,6 @@ void givenClaimStatusInProcessHeritageSystem_WhenGetStatus_thenReturnResponseByP CaseData claim = CaseData.builder() .respondent1ResponseDate(LocalDateTime.now()) .respondent1ClaimResponseTypeForSpec(PART_ADMISSION) - .applicant1AcceptPartAdmitPaymentPlanSpec(YesOrNo.NO) .takenOfflineDate(LocalDateTime.now()) .ccdState(CaseState.PROCEEDS_IN_HERITAGE_SYSTEM) .build();