Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

CIV-8905 Claimant Dashboard Status "Mediation E2E, Manual Determination (org), ITP failed" #3564

Merged
merged 12 commits into from
Nov 29, 2023
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -39,26 +35,21 @@ public void handleTask(ExternalTask externalTask) {
updateCaseByEvent(caseIdForNotifyRpaOnCaseHandedOffline, RETRIGGER_CASES);
}

private void updateCaseByEvent(List<String> caseIdList, CaseEvent caseEvent) {
public void updateCaseByEvent(List<String> 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<String, Object> 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);
});
Expand All @@ -68,17 +59,6 @@ private void updateCaseByEvent(List<String> caseIdList, CaseEvent caseEvent) {

}

private CaseDataContent caseDataContent(StartEventResponse startEventResponse, Map<String, Object> caseDataMap) {
Map<String, Object> 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<String> readCaseIds(String file) {

String data = readString(file);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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
Expand All @@ -293,5 +294,4 @@ public boolean isClaimantDefaultJudgement() {
&& caseData.getRespondent1ResponseDeadline().isBefore(LocalDate.now().atTime(FOUR_PM))
&& caseData.getPaymentTypeSelection() != null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

public enum DashboardClaimStatus {

MEDIATION_UNSUCCESSFUL(
Claim::isMediationUnsuccessful
),
MEDIATION_SUCCESSFUL(
Claim::isMediationSuccessful
),
CLAIMANT_REJECT_PARTIAL_ADMISSION(
Claim::isPartialAdmissionRejected
),
Expand All @@ -21,12 +27,6 @@ public enum DashboardClaimStatus {
MORE_DETAILS_REQUIRED(
Claim::isMoreDetailsRequired
),
MEDIATION_UNSUCCESSFUL(
Claim::isMediationUnsuccessful
),
MEDIATION_SUCCESSFUL(
Claim::isMediationSuccessful
),
IN_MEDIATION(
Claim::isMediationPending
),
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/caseIdForRetrigger.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1693404277952499
1694435036274857
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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<String> 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<String> emptyCaseIdList = Collections.emptyList();

retriggerCasesEventHandler.updateCaseByEvent(emptyCaseIdList, CaseEvent.RETRIGGER_CASES);

// Assertions
verify(coreCaseDataService, never()).triggerEvent(anyLong(), eq(CaseEvent.RETRIGGER_CASES));
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down
Loading