Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.sscs.callback.CallbackHandler;
import uk.gov.hmcts.reform.sscs.ccd.callback.Callback;
Expand All @@ -21,21 +22,31 @@
public class UpdateOtherPartyHandler implements CallbackHandler<SscsCaseData> {

private final ListingStateProcessingService listingStateProcessingService;
private final boolean cmOtherPartyConfidentialityEnabled;

@Autowired
public UpdateOtherPartyHandler(ListingStateProcessingService listingStateProcessingService) {
public UpdateOtherPartyHandler(ListingStateProcessingService listingStateProcessingService,
@Value("${feature.cm-other-party-confidentiality.enabled}") boolean cmOtherPartyConfidentialityEnabled) {
this.listingStateProcessingService = listingStateProcessingService;
this.cmOtherPartyConfidentialityEnabled = cmOtherPartyConfidentialityEnabled;
}

@Override
public boolean canHandle(CallbackType callbackType, Callback<SscsCaseData> callback) {

// TODO When this feature flag is enabled we can delete this handler because its only purpose is to update state for UPDATE_OTHER_PARTY_DATA
if (cmOtherPartyConfidentialityEnabled) {
return false;
}

requireNonNull(callback, "callback must not be null");

return callbackType.equals(CallbackType.SUBMITTED)
&& callback.getEvent() == EventType.UPDATE_OTHER_PARTY_DATA
&& callback.getCaseDetails().getCaseData().getAppeal() != null
&& callback.getCaseDetails().getCaseData().getAppeal().getBenefitType() != null
&& StringUtils.equalsIgnoreCase(callback.getCaseDetails().getCaseData().getAppeal().getBenefitType().getCode(), Benefit.CHILD_SUPPORT.getShortName());
&& StringUtils.equalsIgnoreCase(callback.getCaseDetails().getCaseData().getAppeal().getBenefitType().getCode(),
Benefit.CHILD_SUPPORT.getShortName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -19,7 +21,6 @@
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -33,14 +34,12 @@
import uk.gov.hmcts.reform.sscs.ccd.callback.Callback;
import uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType;
import uk.gov.hmcts.reform.sscs.ccd.domain.Appeal;
import uk.gov.hmcts.reform.sscs.ccd.domain.Appointee;
import uk.gov.hmcts.reform.sscs.ccd.domain.BenefitType;
import uk.gov.hmcts.reform.sscs.ccd.domain.CcdValue;
import uk.gov.hmcts.reform.sscs.ccd.domain.EventType;
import uk.gov.hmcts.reform.sscs.ccd.domain.ExcludeDate;
import uk.gov.hmcts.reform.sscs.ccd.domain.HearingOptions;
import uk.gov.hmcts.reform.sscs.ccd.domain.OtherParty;
import uk.gov.hmcts.reform.sscs.ccd.domain.Representative;
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData;
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseDetails;
import uk.gov.hmcts.reform.sscs.ccd.domain.State;
Expand All @@ -50,38 +49,37 @@
import uk.gov.hmcts.reform.sscs.idam.IdamService;

@ExtendWith(MockitoExtension.class)
public class UpdateOtherPartyHandlerTest {
class UpdateOtherPartyHandlerTest {

private UpdateOtherPartyHandler handler;
@Mock
private UpdateCcdCaseService updateCcdCaseService;
@Mock
private IdamService idamService;

UpdateOtherPartyHandler handler;

@Captor
private ArgumentCaptor<Consumer<SscsCaseDetails>> consumerArgumentCaptor;

@BeforeEach
public void setUp() {
handler = new UpdateOtherPartyHandler(new ListingStateProcessingService(updateCcdCaseService, idamService));
void setUp() {
handler = new UpdateOtherPartyHandler(new ListingStateProcessingService(updateCcdCaseService, idamService), false);
}

@Test
public void givenAValidSubmittedEvent_thenReturnTrue() {
Assertions.assertTrue(handler.canHandle(SUBMITTED, HandlerHelper.buildTestCallbackForGivenData(
SscsCaseData.builder()
.ccdCaseId("1")
.isFqpmRequired(YES)
.directionDueDate(LocalDate.now().toString())
.otherParties(List.of(buildOtherParty("2", HearingOptions.builder().build())))
.appeal(Appeal.builder().benefitType(BenefitType.builder().code("childSupport").build())
.build()).build(), INTERLOCUTORY_REVIEW_STATE, UPDATE_OTHER_PARTY_DATA)));
void givenAValidSubmittedEvent_thenReturnTrue() {
assertTrue(handler.canHandle(SUBMITTED, HandlerHelper.buildTestCallbackForGivenData(
buildAValidEvent(), INTERLOCUTORY_REVIEW_STATE, UPDATE_OTHER_PARTY_DATA)));
}

@Test
void givenTheOtherPartyConfidentialityFlagIsEnabled_thenReturnFalse() {
handler = new UpdateOtherPartyHandler(new ListingStateProcessingService(updateCcdCaseService, idamService), true);
assertFalse(handler.canHandle(SUBMITTED, HandlerHelper.buildTestCallbackForGivenData(
buildAValidEvent(), INTERLOCUTORY_REVIEW_STATE, UPDATE_OTHER_PARTY_DATA)));
}

@ParameterizedTest
@MethodSource(value = "generateAllPossibleOtherPartyWithHearingOptions")
public void givenFqpmSetAndDueDateSetAndAllOtherPartyHearingOptionsSet_thenCaseStateIsReadyToList(HearingOptions hearingOptions) {
void givenFqpmSetAndDueDateSetAndAllOtherPartyHearingOptionsSet_thenCaseStateIsReadyToList(HearingOptions hearingOptions) {

final Callback<SscsCaseData> callback = HandlerHelper.buildTestCallbackForGivenData(
SscsCaseData.builder()
Expand All @@ -104,7 +102,7 @@ public void givenFqpmSetAndDueDateSetAndAllOtherPartyHearingOptionsSet_thenCaseS

@ParameterizedTest
@MethodSource(value = "generateAllPossibleOtherPartyWithHearingOptions")
public void givenFqpmSetAndNoDueDateSetAndAllOtherPartyHearingOptionsSet_thenCaseStateIsReadyToList(HearingOptions hearingOptions) {
void givenFqpmSetAndNoDueDateSetAndAllOtherPartyHearingOptionsSet_thenCaseStateIsReadyToList(HearingOptions hearingOptions) {

final Callback<SscsCaseData> callback = HandlerHelper.buildTestCallbackForGivenData(
SscsCaseData.builder()
Expand All @@ -123,7 +121,7 @@ public void givenFqpmSetAndNoDueDateSetAndAllOtherPartyHearingOptionsSet_thenCas

@ParameterizedTest
@CsvSource({"YES", "NO"})
public void givenFqpmSetAndNoDueDateSetAndNotAllOtherPartyHearingOptionsSet_thenCaseStateIsReadyToList(String isFqpmRequired) {
void givenFqpmSetAndNoDueDateSetAndNotAllOtherPartyHearingOptionsSet_thenCaseStateIsReadyToList(String isFqpmRequired) {

final Callback<SscsCaseData> callback = HandlerHelper.buildTestCallbackForGivenData(
SscsCaseData.builder()
Expand All @@ -144,7 +142,7 @@ public void givenFqpmSetAndNoDueDateSetAndNotAllOtherPartyHearingOptionsSet_then

@ParameterizedTest
@CsvSource({"YES", "NO"})
public void givenFqpmSetAndDueDateSetAndNotAllOtherPartyHearingOptionsSet_thenCaseStateIsNotListable(String isFqpmRequired) {
void givenFqpmSetAndDueDateSetAndNotAllOtherPartyHearingOptionsSet_thenCaseStateIsNotListable(String isFqpmRequired) {

final Callback<SscsCaseData> callback = HandlerHelper.buildTestCallbackForGivenData(
SscsCaseData.builder()
Expand All @@ -163,7 +161,7 @@ public void givenFqpmSetAndDueDateSetAndNotAllOtherPartyHearingOptionsSet_thenCa
}

@Test
public void givenNoFqpmSetAndNoDueDateSetAndNotAllOtherPartyHearingOptionsSet_thenCaseStateIsNotListable() {
void givenNoFqpmSetAndNoDueDateSetAndNotAllOtherPartyHearingOptionsSet_thenCaseStateIsNotListable() {

final Callback<SscsCaseData> callback = HandlerHelper.buildTestCallbackForGivenData(
SscsCaseData.builder()
Expand All @@ -181,7 +179,7 @@ public void givenNoFqpmSetAndNoDueDateSetAndNotAllOtherPartyHearingOptionsSet_th
}

@Test
public void givenNoFqpmSetAndDueDateSetAndNotAllOtherPartyHearingOptionsSet_thenCaseStateIsNotListable() {
void givenNoFqpmSetAndDueDateSetAndNotAllOtherPartyHearingOptionsSet_thenCaseStateIsNotListable() {

final Callback<SscsCaseData> callback = HandlerHelper.buildTestCallbackForGivenData(
SscsCaseData.builder()
Expand All @@ -200,7 +198,8 @@ public void givenNoFqpmSetAndDueDateSetAndNotAllOtherPartyHearingOptionsSet_then

@ParameterizedTest
@MethodSource(value = "generateAllPossibleOtherPartyWithHearingOptions")
public void givenNoFqpmSetAndNoDueDateSetAndAllOtherPartyHearingOptionsSet_thenCaseStateIsNotListable(HearingOptions hearingOptions) {
void givenNoFqpmSetAndNoDueDateSetAndAllOtherPartyHearingOptionsSet_thenCaseStateIsNotListable(
HearingOptions hearingOptions) {

final Callback<SscsCaseData> callback = HandlerHelper.buildTestCallbackForGivenData(
SscsCaseData.builder()
Expand All @@ -222,7 +221,7 @@ public void givenNoFqpmSetAndNoDueDateSetAndAllOtherPartyHearingOptionsSet_thenC
"HEARING, 1", "INCOMPLETE_APPLICATION, 1", "INCOMPLETE_APPLICATION_INFORMATION_REQUESTED, 1",
"INTERLOCUTORY_REVIEW_STATE, 1", "POST_HEARING, 1", "READY_TO_LIST, 1", "RESPONSE_RECEIVED, 0",
"VALID_APPEAL, 1", "WITH_DWP, 0"})
public void givenAnInitialStateThenTriggerNonListableEventType(State currentState, int wantedNumberOfInvocations) {
void givenAnInitialStateThenTriggerNonListableEventType(State currentState, int wantedNumberOfInvocations) {
final Callback<SscsCaseData> callback = HandlerHelper.buildTestCallbackForGivenData(
SscsCaseData.builder()
.ccdCaseId("1")
Expand All @@ -234,7 +233,8 @@ public void givenAnInitialStateThenTriggerNonListableEventType(State currentStat

handler.handle(CallbackType.SUBMITTED, callback);

verify(updateCcdCaseService, times(wantedNumberOfInvocations)).triggerCaseEventV2(eq(Long.valueOf(callback.getCaseDetails().getCaseData().getCcdCaseId())),
verify(updateCcdCaseService, times(wantedNumberOfInvocations)).triggerCaseEventV2(
eq(Long.valueOf(callback.getCaseDetails().getCaseData().getCcdCaseId())),
eq(EventType.NOT_LISTABLE.getCcdType()), anyString(), anyString(), any());
}

Expand Down Expand Up @@ -273,6 +273,16 @@ private static Object[] generateAllPossibleOtherPartyWithHearingOptions() {
};
}

private SscsCaseData buildAValidEvent() {
return SscsCaseData.builder()
.ccdCaseId("1")
.isFqpmRequired(YES)
.directionDueDate(LocalDate.now().toString())
.otherParties(List.of(buildOtherParty("2", HearingOptions.builder().build())))
.appeal(Appeal.builder().benefitType(BenefitType.builder().code("childSupport").build())
.build()).build();
}

private CcdValue<OtherParty> buildOtherParty(String id, HearingOptions hearingOptions) {
return CcdValue.<OtherParty>builder()
.value(OtherParty.builder()
Expand All @@ -283,14 +293,4 @@ private CcdValue<OtherParty> buildOtherParty(String id, HearingOptions hearingOp
.build();
}

private CcdValue<OtherParty> buildOtherPartyWithAppointeeAndRep(String id, String appointeeId, String repId) {
return CcdValue.<OtherParty>builder()
.value(OtherParty.builder()
.id(id)
.isAppointee(YES.getValue())
.appointee(Appointee.builder().id(appointeeId).build())
.rep(Representative.builder().id(repId).hasRepresentative(YES.getValue()).build())
.build())
.build();
}
}
Loading