From 4d646afde7286386a6339c13ba14c56a1dd8de17 Mon Sep 17 00:00:00 2001 From: AbuSalamHMCTS <138011124+AbuSalamHMCTS@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:03:55 +0100 Subject: [PATCH] DTSCCI-459 Remove Spring context (#5096) * DTSCCI-459 Remove Spring context from uk/gov/hmcts/reform/civil/handler/callback/camunda/notification, payment * DTSCCI-459 Remove public modifier --------- Co-authored-by: AbuSalam22 <136581242+AbuSalam22@users.noreply.github.com> --- .../MakeBulkClaimPaymentCallbackHandler.java | 2 +- .../payment/PaymentsCallbackHandler.java | 2 +- ...mentDefendantLrCoverLetterHandlerTest.java | 116 ++- ...anualDeterminationCallBackHandlerTest.java | 96 ++- ...rderDJClaimantNotificationHandlerTest.java | 36 +- ...derDJDefendantNotificationHandlerTest.java | 36 +- ...loadedClaimantNotificationHandlerTest.java | 44 +- ...oadedDefendantNotificationHandlerTest.java | 24 +- ...ReadyApplicantNotificationHandlerTest.java | 42 +- .../TrialReadyNotifyOthersHandlerTest.java | 57 +- ...eadyRespondentNotificationHandlerTest.java | 65 +- ...aimIssueFeePaymentCallbackHandlerTest.java | 29 +- ...nHearingFeePaymentCallbackHandlerTest.java | 19 +- ...keBulkClaimPaymentCallbackHandlerTest.java | 41 +- .../payment/PaymentsCallbackHandlerTest.java | 32 +- .../payment/PaymentsForSpecHandlerTest.java | 34 +- .../payment/ServiceRequestAPIHandlerTest.java | 80 +-- .../ServiceRequestCUICallbackHandlerTest.java | 84 ++- ...rviceRequestUpdateCallbackHandlerTest.java | 24 +- ...mendClaimDocumentsCallbackHandlerTest.java | 121 ++-- ...HelpWithHearingFeeCallbackHandlerTest.java | 28 +- ...ceOfChangeDecisionCallbackHandlerTest.java | 662 +++++------------- ...eProceedsInCasemanCallbackHandlerTest.java | 40 +- 23 files changed, 708 insertions(+), 1006 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/MakeBulkClaimPaymentCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/MakeBulkClaimPaymentCallbackHandler.java index fdd96f41d59..dc5c58afc33 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/MakeBulkClaimPaymentCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/MakeBulkClaimPaymentCallbackHandler.java @@ -41,7 +41,7 @@ public class MakeBulkClaimPaymentCallbackHandler extends CallbackHandler { private static final List EVENTS = Collections.singletonList(MAKE_BULK_CLAIM_PAYMENT); private static final String ERROR_MESSAGE = "Technical error occurred"; private static final String TASK_ID = "makeBulkClaimPayment"; - public static final String DUPLICATE_BULK_PAYMENT_MESSAGE = "You attempted to retry the payment to soon. Try again later."; + public static final String DUPLICATE_BULK_PAYMENT_MESSAGE = "You attempted to retry the payment too soon. Try again later."; private final PaymentsService paymentsService; private final ObjectMapper objectMapper; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsCallbackHandler.java index ab5d0ccd64d..0e5aa48f7c2 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsCallbackHandler.java @@ -41,7 +41,7 @@ public class PaymentsCallbackHandler extends CallbackHandler { private static final String ERROR_MESSAGE = "Technical error occurred"; private static final String TASK_ID = "CreateClaimMakePayment"; public static final String DUPLICATE_PAYMENT_MESSAGE - = "You attempted to retry the payment to soon. Try again later."; + = "You attempted to retry the payment too soon. Try again later."; private final PaymentsService paymentsService; private final ObjectMapper objectMapper; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/DefaultJudgmentDefendantLrCoverLetterHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/DefaultJudgmentDefendantLrCoverLetterHandlerTest.java index 749ee7bf540..5e8671a9314 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/DefaultJudgmentDefendantLrCoverLetterHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/DefaultJudgmentDefendantLrCoverLetterHandlerTest.java @@ -1,13 +1,13 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; 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.EnumSource; import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.ccd.model.Organisation; @@ -20,15 +20,11 @@ import uk.gov.hmcts.reform.civil.model.Party; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; -import uk.gov.hmcts.reform.civil.service.OrganisationService; import uk.gov.hmcts.reform.civil.service.docmosis.judgmentonline.DefaultJudgmentCoverLetterGenerator; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT1; @@ -36,98 +32,76 @@ import static uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis.DefaultJudgmentDefendantLrCoverLetterHandler.TASK_ID_DEFENDANT_1; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis.DefaultJudgmentDefendantLrCoverLetterHandler.TASK_ID_DEFENDANT_2; -@SpringBootTest(classes = { - DefaultJudgmentDefendantLrCoverLetterHandler.class, - JacksonAutoConfiguration.class -}) -public class DefaultJudgmentDefendantLrCoverLetterHandlerTest extends BaseCallbackHandlerTest { +@ExtendWith(MockitoExtension.class) +class DefaultJudgmentDefendantLrCoverLetterHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private DefaultJudgmentDefendantLrCoverLetterHandler handler; - @MockBean - private DefaultJudgmentCoverLetterGenerator coverLetterGenerator; - @MockBean - private OrganisationService organisationService; - public static final String TASK_ID = "SendCoverLetterToDefendantLR"; + @Mock + private DefaultJudgmentCoverLetterGenerator coverLetterGenerator; @Test void handleEventsReturnsTheExpectedCallbackEvent() { - assertThat(handler.handledEvents()).contains(POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT1); - assertThat(handler.handledEvents()).contains(POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT2); + assertThat(handler.handledEvents()) + .containsExactlyInAnyOrder(POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT1, POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT2); } @ParameterizedTest - @EnumSource( - value = CaseEvent.class, - names = {"POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT1", "POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT2"}) + @EnumSource(value = CaseEvent.class, names = { + "POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT1", + "POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT2"}) void shouldReturnCorrectCamundaActivityId_whenInvoked(CaseEvent caseEvent) { - assertThat(handler.camundaActivityId(CallbackParamsBuilder.builder().request(CallbackRequest.builder().eventId( - caseEvent.name()).build()).build())).isEqualTo( - caseEvent.name() - .equals("POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT1") ? TASK_ID_DEFENDANT_1 : TASK_ID_DEFENDANT_2); + String expectedTaskId = caseEvent == POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT1 ? TASK_ID_DEFENDANT_1 : TASK_ID_DEFENDANT_2; + + CallbackParams params = CallbackParamsBuilder.builder() + .request(CallbackRequest.builder().eventId(caseEvent.name()).build()) + .build(); + + assertThat(handler.camundaActivityId(params)).isEqualTo(expectedTaskId); } @Test void shouldDownloadDocumentAndPrintLetterSuccessfullyForDefendant1() { - // given - OrganisationPolicy organisation1Policy = OrganisationPolicy.builder() - .organisation(Organisation.builder().organisationID("1234").build()).build(); + testDownloadDocumentAndPrintLetter(POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT1, true); + } - CaseData caseData = CaseDataBuilder.builder() - .atStateClaimIssued1v2AndBothDefendantsDefaultJudgment() - .respondent2(Party.builder().partyName("Respondent2 name").type(Party.Type.INDIVIDUAL).build()) - .addRespondent2(YesOrNo.YES) - .respondent1Represented(YesOrNo.YES) - .respondent1OrganisationPolicy(organisation1Policy) - .build(); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void shouldDownloadDocumentAndPrintLetterSuccessfullyForDefendant2(boolean sameLegalOrgs) { + testDownloadDocumentAndPrintLetter(POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT2, sameLegalOrgs); + } - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - params.getRequest().setEventId(POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT1.name()); + private void testDownloadDocumentAndPrintLetter(CaseEvent caseEvent, boolean sameLegalOrgs) { + OrganisationPolicy organisation1Policy = createOrganisationPolicy("1234"); + OrganisationPolicy organisation2Policy = createOrganisationPolicy("3456"); - when(coverLetterGenerator.generateAndPrintDjCoverLettersPlusDocument(eq(caseData), any(), eq(false))) - .thenReturn(new byte[]{50}); + CaseData caseData = createCaseData(organisation1Policy, organisation2Policy, sameLegalOrgs); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + params.getRequest().setEventId(caseEvent.name()); - // when var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - // then assertThat(response.getErrors()).isNull(); - verify(coverLetterGenerator, times(1)).generateAndPrintDjCoverLettersPlusDocument( - caseData, params.getParams().get(BEARER_TOKEN).toString(), false); + verify(coverLetterGenerator, times(sameLegalOrgs && caseEvent == POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT2 ? 0 : 1)) + .generateAndPrintDjCoverLettersPlusDocument(caseData, params.getParams().get(BEARER_TOKEN).toString(), caseEvent == POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT2); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - void shouldDownloadDocumentAndPrintLetterSuccessfullyForDefendant2(boolean sameLegalOrgs) { - // given - OrganisationPolicy organisation1Policy = OrganisationPolicy.builder() - .organisation(Organisation.builder().organisationID("1234").build()).build(); - - OrganisationPolicy organisation2Policy = OrganisationPolicy.builder() - .organisation(Organisation.builder().organisationID("3456").build()).build(); + private OrganisationPolicy createOrganisationPolicy(String organisationID) { + return OrganisationPolicy.builder() + .organisation(Organisation.builder().organisationID(organisationID).build()) + .build(); + } - CaseData caseData = CaseDataBuilder.builder() + private CaseData createCaseData(OrganisationPolicy organisation1Policy, OrganisationPolicy organisation2Policy, boolean sameLegalOrgs) { + return CaseDataBuilder.builder() .atStateClaimIssued1v2AndBothDefendantsDefaultJudgment() .respondent2(Party.builder().partyName("Respondent2 name").type(Party.Type.INDIVIDUAL).build()) .addRespondent2(YesOrNo.YES) .respondent1Represented(YesOrNo.YES) .respondent1OrganisationPolicy(organisation1Policy) .respondent2OrganisationPolicy(sameLegalOrgs ? organisation1Policy : organisation2Policy) - .build(); - - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - params.getRequest().setEventId(POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT2.name()); - - when(coverLetterGenerator.generateAndPrintDjCoverLettersPlusDocument(eq(caseData), any(), eq(true))) - .thenReturn(new byte[]{20}); - - // when - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - // then - assertThat(response.getErrors()).isNull(); - verify(coverLetterGenerator, times(sameLegalOrgs ? 0 : 1)).generateAndPrintDjCoverLettersPlusDocument( - caseData, params.getParams().get(BEARER_TOKEN).toString(), true); + .build(); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimantLipManualDeterminationCallBackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimantLipManualDeterminationCallBackHandlerTest.java index 69eafc950af..e84c0920108 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimantLipManualDeterminationCallBackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimantLipManualDeterminationCallBackHandlerTest.java @@ -3,11 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; @@ -31,73 +29,60 @@ import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_LIP_CLAIMANT_MANUAL_DETERMINATION; import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.LIP_MANUAL_DETERMINATION; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateClaimantLipManualDeterminationCallBackHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) class GenerateClaimantLipManualDeterminationCallBackHandlerTest extends BaseCallbackHandlerTest { + @InjectMocks + private GenerateClaimantLipManualDeterminationCallBackHandler handler; + + @Mock + private ClaimantLipManualDeterminationFormGenerator formGenerator; + + @Mock + private SystemGeneratedDocumentService documentService; + + @Mock + private ObjectMapper mapper; + private static final String BEARER_TOKEN = "BEARER_TOKEN"; private static final CaseDocument FORM = CaseDocument.builder() - .createdBy("John") - .documentName("document name") - .documentSize(0L) - .documentType(LIP_MANUAL_DETERMINATION) - .createdDatetime(LocalDateTime.now()) - .documentLink(Document.builder() - .documentUrl("fake-url") - .documentFileName("file-name") - .documentBinaryUrl("binary-url") - .build()) - .build(); - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - @Autowired - private GenerateClaimantLipManualDeterminationCallBackHandler handler; - @MockBean - private ClaimantLipManualDeterminationFormGenerator lipManualDeterminationHandlerFormGenerator; - @MockBean - private SystemGeneratedDocumentService systemGeneratedDocumentService; + .createdBy("John") + .documentName("document name") + .documentSize(0L) + .documentType(LIP_MANUAL_DETERMINATION) + .createdDatetime(LocalDateTime.now()) + .documentLink(Document.builder() + .documentUrl("fake-url") + .documentFileName("file-name") + .documentBinaryUrl("binary-url") + .build()) + .build(); @Test void shouldGenerateForm_whenAboutToSubmitCalled() { - given(lipManualDeterminationHandlerFormGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); - - CaseData caseData = CaseDataBuilder.builder() - .respondent1(PartyBuilder.builder() - .soleTrader().build().toBuilder() - .type(Party.Type.COMPANY) - .build()) - .build(); + given(formGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); + CaseData caseData = createCaseData(Party.Type.COMPANY); handler.handle(callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); - verify(lipManualDeterminationHandlerFormGenerator).generate(caseData, BEARER_TOKEN); + + verify(formGenerator).generate(caseData, BEARER_TOKEN); } @Test - void shouldNotGenerateForm_whenPartyTypeIsNotCompanyORNotOrganisation() { - given(lipManualDeterminationHandlerFormGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); - - CaseData caseData = CaseDataBuilder.builder() - .respondent1(PartyBuilder.builder() - .soleTrader().build().toBuilder() - .type(Party.Type.SOLE_TRADER) - .build()) - .build(); - + void shouldNotGenerateForm_whenPartyTypeIsNotCompanyOrOrganisation() { + CaseData caseData = createCaseData(Party.Type.SOLE_TRADER); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); params.getRequest().setEventId(GENERATE_LIP_CLAIMANT_MANUAL_DETERMINATION.name()); handler.handle(params); - verify(lipManualDeterminationHandlerFormGenerator, never()).generate(any(CaseData.class), anyString()); - verify(systemGeneratedDocumentService, never()).getSystemGeneratedDocumentsWithAddedDocument(any(CaseDocument.class), any(CaseData.class)); + + verify(formGenerator, never()).generate(any(CaseData.class), anyString()); + verify(documentService, never()).getSystemGeneratedDocumentsWithAddedDocument(any(CaseDocument.class), any(CaseData.class)); } @Test void shouldReturnCorrectActivityId_whenRequestedMDForm() { CaseData caseData = CaseDataBuilder.builder().atStatePendingClaimIssued().build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); assertThat(handler.camundaActivityId(params)).isEqualTo("Generate_LIP_Claimant_MD"); @@ -107,4 +92,13 @@ void shouldReturnCorrectActivityId_whenRequestedMDForm() { void testHandledEvents() { assertThat(handler.handledEvents()).contains(GENERATE_LIP_CLAIMANT_MANUAL_DETERMINATION); } + + private CaseData createCaseData(Party.Type type) { + return CaseDataBuilder.builder() + .respondent1(PartyBuilder.builder() + .soleTrader().build().toBuilder() + .type(type) + .build()) + .build(); + } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/StandardDirectionOrderDJClaimantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/StandardDirectionOrderDJClaimantNotificationHandlerTest.java index 2b1a6913541..4e0402b099a 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/StandardDirectionOrderDJClaimantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/StandardDirectionOrderDJClaimantNotificationHandlerTest.java @@ -1,21 +1,22 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.callback.CallbackParams; -import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.notify.NotificationService; +import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; -import uk.gov.hmcts.reform.civil.notify.NotificationService; import uk.gov.hmcts.reform.civil.service.OrganisationService; -import uk.gov.hmcts.reform.civil.prd.model.Organisation; import java.util.Map; import java.util.Optional; @@ -25,20 +26,23 @@ import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; -@SpringBootTest(classes = { - StandardDirectionOrderDJClaimantNotificationHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) public class StandardDirectionOrderDJClaimantNotificationHandlerTest extends BaseCallbackHandlerTest { - @MockBean + @InjectMocks + private StandardDirectionOrderDJClaimantNotificationHandler handler; + + @Mock private NotificationService notificationService; - @MockBean + + @Mock private NotificationsProperties notificationsProperties; - @MockBean + + @Mock private OrganisationService organisationService; - @Autowired - private StandardDirectionOrderDJClaimantNotificationHandler handler; + + @Mock + private ObjectMapper objectMapper; @Nested class AboutToSubmitCallback { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/StandardDirectionOrderDJDefendantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/StandardDirectionOrderDJDefendantNotificationHandlerTest.java index 86fabe433a1..c2f13079064 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/StandardDirectionOrderDJDefendantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/StandardDirectionOrderDJDefendantNotificationHandlerTest.java @@ -1,21 +1,22 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.callback.CallbackParams; -import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.notify.NotificationService; +import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; -import uk.gov.hmcts.reform.civil.notify.NotificationService; import uk.gov.hmcts.reform.civil.service.OrganisationService; -import uk.gov.hmcts.reform.civil.prd.model.Organisation; import java.util.Map; import java.util.Optional; @@ -28,20 +29,23 @@ import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; -@SpringBootTest(classes = { - StandardDirectionOrderDJDefendantNotificationHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) public class StandardDirectionOrderDJDefendantNotificationHandlerTest extends BaseCallbackHandlerTest { - @MockBean + @InjectMocks + private StandardDirectionOrderDJDefendantNotificationHandler handler; + + @Mock private NotificationService notificationService; - @MockBean + + @Mock private NotificationsProperties notificationsProperties; - @MockBean + + @Mock private OrganisationService organisationService; - @Autowired - private StandardDirectionOrderDJDefendantNotificationHandler handler; + + @Mock + private ObjectMapper objectMapper; @Nested class AboutToSubmitCallback { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TranslatedDocumentUploadedClaimantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TranslatedDocumentUploadedClaimantNotificationHandlerTest.java index 16837086d0b..d6748f31a87 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TranslatedDocumentUploadedClaimantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TranslatedDocumentUploadedClaimantNotificationHandlerTest.java @@ -1,18 +1,16 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.enums.YesOrNo; -import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.notify.NotificationService; import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; @@ -32,22 +30,24 @@ import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_LEGAL_ORG_NAME_SPEC; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; -@SpringBootTest(classes = { - TranslatedDocumentUploadedClaimantNotificationHandler.class, - JacksonAutoConfiguration.class -}) -public class TranslatedDocumentUploadedClaimantNotificationHandlerTest extends BaseCallbackHandlerTest { +@ExtendWith(MockitoExtension.class) +public class TranslatedDocumentUploadedClaimantNotificationHandlerTest { - @MockBean + @InjectMocks + private TranslatedDocumentUploadedClaimantNotificationHandler handler; + + @Mock private NotificationService notificationService; - @MockBean + + @Mock private NotificationsProperties notificationsProperties; - @Autowired - private TranslatedDocumentUploadedClaimantNotificationHandler handler; - @MockBean + + @Mock private OrganisationService organisationService; - @MockBean + + @Mock private FeatureToggleService featureToggleService; + private static final String CLAIMANT_LR_EMAIL_TEMPLATE = "template-id"; private static final String CLAIMANT_LIP_EMAIL_TEMPLATE_BILINGUAL = "template-id-Bilingual"; private static final String CLAIMANT_LIP_EMAIL_TEMPLATE_ENGLISH = "template-id-English"; @@ -58,15 +58,9 @@ public class TranslatedDocumentUploadedClaimantNotificationHandlerTest extends B @Nested class AboutToSubmitCallback { - @BeforeEach - void setup() { - when(notificationsProperties.getNotifyClaimantTranslatedDocumentUploaded()).thenReturn(CLAIMANT_LR_EMAIL_TEMPLATE); - when(notificationsProperties.getNotifyClaimantLiPTranslatedDocumentUploadedWhenClaimIssuedInBilingual()).thenReturn(CLAIMANT_LIP_EMAIL_TEMPLATE_BILINGUAL); - when(notificationsProperties.getNotifyClaimantLiPTranslatedDocumentUploadedWhenClaimIssuedInEnglish()).thenReturn(CLAIMANT_LIP_EMAIL_TEMPLATE_ENGLISH); - } - @Test void shouldNotifyApplicantParty_whenInvoked() { + when(notificationsProperties.getNotifyClaimantTranslatedDocumentUploaded()).thenReturn(CLAIMANT_LR_EMAIL_TEMPLATE); //Given CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified() .setClaimTypeToSpecClaim() @@ -88,6 +82,7 @@ void shouldNotifyApplicantParty_whenInvoked() { @Test void shouldNotifyLipClaimantForClaimIssueTranslatedDoc_whenR2EnabledAndClaimIssuedInBilingual() { + when(notificationsProperties.getNotifyClaimantLiPTranslatedDocumentUploadedWhenClaimIssuedInBilingual()).thenReturn(CLAIMANT_LIP_EMAIL_TEMPLATE_BILINGUAL); // Given CaseData caseData = CaseDataBuilder.builder() .atStatePendingClaimIssued() @@ -115,6 +110,7 @@ void shouldNotifyLipClaimantForClaimIssueTranslatedDoc_whenR2EnabledAndClaimIss @Test void shouldNotifyLipClaimantForClaimIssueTranslatedDoc_whenR2EnabledAndClaimIssuedInEnglish() { + when(notificationsProperties.getNotifyClaimantLiPTranslatedDocumentUploadedWhenClaimIssuedInEnglish()).thenReturn(CLAIMANT_LIP_EMAIL_TEMPLATE_ENGLISH); // Given CaseData caseData = CaseDataBuilder.builder() .atStatePendingClaimIssued() diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TranslatedDocumentUploadedDefendantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TranslatedDocumentUploadedDefendantNotificationHandlerTest.java index db2366936ad..6624c71e9ed 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TranslatedDocumentUploadedDefendantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TranslatedDocumentUploadedDefendantNotificationHandlerTest.java @@ -4,10 +4,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; @@ -28,18 +28,18 @@ import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.RESPONDENT_NAME; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getPartyNameBasedOnType; -@SpringBootTest(classes = { - TranslatedDocumentUploadedDefendantNotificationHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) public class TranslatedDocumentUploadedDefendantNotificationHandlerTest { - @MockBean + @InjectMocks + private TranslatedDocumentUploadedDefendantNotificationHandler handler; + + @Mock private NotificationService notificationService; - @MockBean + + @Mock private NotificationsProperties notificationsProperties; - @Autowired - private TranslatedDocumentUploadedDefendantNotificationHandler handler; + private final String emailTemplate = "template-id"; private final String defendantEmail = "respondent@example.com"; private final String legacyCaseReference = "translated-document-uploaded-defendant-notification-000DC001"; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyApplicantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyApplicantNotificationHandlerTest.java index caf441b4cdf..4cc4953fd33 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyApplicantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyApplicantNotificationHandlerTest.java @@ -1,23 +1,21 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.callback.CallbackParams; 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.IdamUserDetails; +import uk.gov.hmcts.reform.civil.notify.NotificationService; import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; -import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; -import uk.gov.hmcts.reform.civil.notify.NotificationService; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; import java.util.Map; @@ -25,38 +23,32 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; -import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIMANT_V_DEFENDANT; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.HEARING_DATE; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.PARTY_NAME; import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE; import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getAllPartyNames; -@SpringBootTest(classes = { - TrialReadyApplicantNotificationHandler.class, - JacksonAutoConfiguration.class -}) -class TrialReadyApplicantNotificationHandlerTest extends BaseCallbackHandlerTest { +@ExtendWith(MockitoExtension.class) +class TrialReadyApplicantNotificationHandlerTest { + + @InjectMocks + private TrialReadyApplicantNotificationHandler handler; - @MockBean + @Mock private NotificationService notificationService; - @MockBean + + @Mock private NotificationsProperties notificationsProperties; - @Autowired - private TrialReadyApplicantNotificationHandler handler; @Nested class AboutToSubmitCallback { - @BeforeEach - void setup() { - when(notificationsProperties.getSolicitorTrialReady()).thenReturn("template-id"); - when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); - } - @Test void shouldNotifyApplicantSolicitor_whenInvoked() { + when(notificationsProperties.getSolicitorTrialReady()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).build(); @@ -72,6 +64,7 @@ void shouldNotifyApplicantSolicitor_whenInvoked() { @Test void shouldNotNotifyApplicant_whenInvokedWithNoSolicitorRepresentedWithNoEmail() { + when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck() .applicant1(PartyBuilder.builder().company().partyEmail(null).build()) .claimantUserDetails(new IdamUserDetails().toBuilder().email("email@email.com").build()) @@ -92,6 +85,7 @@ void shouldNotNotifyApplicant_whenInvokedWithNoSolicitorRepresentedWithNoEmail() @Test void shouldNotNotifyApplicant_whenInvokedWithNoSolicitorRepresentedWithEmail() { + when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck() .applicant1Represented(YesOrNo.NO) .caseAccessCategory(CaseCategory.SPEC_CLAIM) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyNotifyOthersHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyNotifyOthersHandlerTest.java index 903f9b5f509..a8b023b8c14 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyNotifyOthersHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyNotifyOthersHandlerTest.java @@ -1,23 +1,22 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; -import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.BeforeEach; +import com.launchdarkly.shaded.org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.enums.dq.Language; -import uk.gov.hmcts.reform.civil.model.IdamUserDetails; -import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.IdamUserDetails; +import uk.gov.hmcts.reform.civil.notify.NotificationService; +import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; -import uk.gov.hmcts.reform.civil.notify.NotificationService; import java.util.Map; @@ -40,32 +39,25 @@ import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getAllPartyNames; -@SpringBootTest(classes = { - TrialReadyNotifyOthersHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) public class TrialReadyNotifyOthersHandlerTest extends BaseCallbackHandlerTest { - @MockBean + @InjectMocks + private TrialReadyNotifyOthersHandler handler; + + @Mock private NotificationService notificationService; - @MockBean + + @Mock private NotificationsProperties notificationsProperties; - @Autowired - private TrialReadyNotifyOthersHandler handler; @Nested class AboutToSubmitCallback { - @BeforeEach - void setup() { - when(notificationsProperties.getOtherPartyTrialReady()).thenReturn("template-id"); - when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); - when(notificationsProperties.getNotifyLipUpdateTemplateBilingual()) - .thenReturn("cui-template-id-bilingual"); - } - @Test void shouldNotifyApplicantSolicitor_whenInvoked() { + when(notificationsProperties.getOtherPartyTrialReady()).thenReturn("template-id"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId(NOTIFY_APPLICANT_SOLICITOR_FOR_OTHER_TRIAL_READY.name()).build() @@ -83,6 +75,8 @@ void shouldNotifyApplicantSolicitor_whenInvoked() { @Test void shouldNotifyApplicant_whenInvoked() { + when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheckLiP(true).build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId(NOTIFY_APPLICANT_SOLICITOR_FOR_OTHER_TRIAL_READY.name()).build() @@ -100,6 +94,9 @@ void shouldNotifyApplicant_whenInvoked() { @Test void shouldNotifyApplicant_whenInvokedBilingual() { + when(notificationsProperties.getNotifyLipUpdateTemplateBilingual()) + .thenReturn("cui-template-id-bilingual"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheckLiP(true) .claimantBilingualLanguagePreference(Language.BOTH.toString()).build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( @@ -118,6 +115,8 @@ void shouldNotifyApplicant_whenInvokedBilingual() { @Test void shouldNotifyApplicantWithNoEmail_whenInvoked() { + when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheckLiP(false) .claimantUserDetails(new IdamUserDetails().toBuilder().email("email@email.com").build()).build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( @@ -136,6 +135,8 @@ void shouldNotifyApplicantWithNoEmail_whenInvoked() { @Test void shouldNotifyRespondentSolicitor1_whenInvoked() { + when(notificationsProperties.getOtherPartyTrialReady()).thenReturn("template-id"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId(NOTIFY_RESPONDENT_SOLICITOR1_FOR_OTHER_TRIAL_READY.name()).build() @@ -153,6 +154,8 @@ void shouldNotifyRespondentSolicitor1_whenInvoked() { @Test void shouldNotifyRespondent1_whenInvoked() { + when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheckLiP(true).build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId(NOTIFY_RESPONDENT_SOLICITOR1_FOR_OTHER_TRIAL_READY.name()).build() @@ -187,6 +190,8 @@ void shouldNotNotifyRespondent1_whenInvokedAndTheEmailAddressIsNotProvided() { @Test void shouldNotifyRespondentSolicitor2_whenInvoked() { + when(notificationsProperties.getOtherPartyTrialReady()).thenReturn("template-id"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId(NOTIFY_RESPONDENT_SOLICITOR2_FOR_OTHER_TRIAL_READY.name()).build() @@ -204,6 +209,8 @@ void shouldNotifyRespondentSolicitor2_whenInvoked() { @Test void shouldNotifyRespondent2_whenInvoked() { + when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheckLiP(true).build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId(NOTIFY_RESPONDENT_SOLICITOR2_FOR_OTHER_TRIAL_READY.name()).build() diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyRespondentNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyRespondentNotificationHandlerTest.java index 153b97a906e..f2b5a6595dd 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyRespondentNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/TrialReadyRespondentNotificationHandlerTest.java @@ -1,23 +1,22 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.enums.CaseCategory; -import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.notify.NotificationService; +import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; -import uk.gov.hmcts.reform.civil.notify.NotificationService; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; import java.util.Map; @@ -31,8 +30,8 @@ import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_RESPONDENT_SOLICITOR1_FOR_TRIAL_READY; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_RESPONDENT_SOLICITOR2_FOR_TRIAL_READY; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_TWO_LEGAL_REP; -import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIMANT_V_DEFENDANT; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.HEARING_DATE; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.PARTY_NAME; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.TrialReadyRespondentNotificationHandler.TASK_ID_RESPONDENT_ONE; @@ -41,32 +40,27 @@ import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getAllPartyNames; -@SpringBootTest(classes = { - TrialReadyRespondentNotificationHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) class TrialReadyRespondentNotificationHandlerTest extends BaseCallbackHandlerTest { - @MockBean + @InjectMocks + private TrialReadyRespondentNotificationHandler handler; + + @Mock private NotificationService notificationService; - @MockBean + + @Mock private NotificationsProperties notificationsProperties; - @Autowired - private TrialReadyRespondentNotificationHandler handler; private boolean isRespondentSolicitor1; @Nested class AboutToSubmitCallback { - @BeforeEach - void setup() { - when(notificationsProperties.getSolicitorTrialReady()).thenReturn("template-id"); - when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); - } - @Test void shouldNotifyRespondentSolicitorOne_whenInvoked() { + when(notificationsProperties.getSolicitorTrialReady()).thenReturn("template-id"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId(NOTIFY_RESPONDENT_SOLICITOR1_FOR_TRIAL_READY.name()).build() @@ -85,6 +79,8 @@ void shouldNotifyRespondentSolicitorOne_whenInvoked() { @Test void shouldNotifyRespondentSolicitorTwo_whenInvokedWithDiffSol() { + when(notificationsProperties.getSolicitorTrialReady()).thenReturn("template-id"); + CaseData caseData = CaseDataBuilder.builder() .atStateTrialReadyCheck(ONE_V_TWO_TWO_LEGAL_REP) .respondent2SameLegalRepresentative(YesOrNo.NO) @@ -123,6 +119,8 @@ void shouldNotNotifyRespondent_whenInvokedWithNoSolicitorRepresentedAndNoEmail() @Test void shouldNotNotifyRespondent_whenInvokedWithNoSolicitorRepresentedWithEmail() { + when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("cui-template-id"); + CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck() .respondent1Represented(null) .specRespondent1Represented(YesOrNo.NO) @@ -142,25 +140,17 @@ void shouldNotNotifyRespondent_whenInvokedWithNoSolicitorRepresentedWithEmail() ); } - private Map getNotificationDataMapLRvLiP(CaseData caseData) { - - return Map.of( - CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), - PARTY_NAME, caseData.getRespondent1().getPartyName(), - CLAIMANT_V_DEFENDANT, getAllPartyNames(caseData) - ); - } - @Test void shouldReturnCorrectCamundaActivityId_whenInvoked() { + assertThat(handler.camundaActivityId(CallbackParamsBuilder.builder().request( CallbackRequest.builder().eventId( - NOTIFY_RESPONDENT_SOLICITOR1_FOR_TRIAL_READY.name()).build()).build())) + NOTIFY_RESPONDENT_SOLICITOR1_FOR_TRIAL_READY.name()).build()).build())) .isEqualTo(TASK_ID_RESPONDENT_ONE); assertThat(handler.camundaActivityId(CallbackParamsBuilder.builder().request( CallbackRequest.builder().eventId( - NOTIFY_RESPONDENT_SOLICITOR2_FOR_TRIAL_READY.name()).build()).build())) + NOTIFY_RESPONDENT_SOLICITOR2_FOR_TRIAL_READY.name()).build()).build())) .isEqualTo(TASK_ID_RESPONDENT_TWO); } @@ -178,5 +168,14 @@ HEARING_DATE, formatLocalDate(caseData.getHearingDate(), DATE), ); } } + + private Map getNotificationDataMapLRvLiP(CaseData caseData) { + + return Map.of( + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + PARTY_NAME, caseData.getRespondent1().getPartyName(), + CLAIMANT_V_DEFENDANT, getAllPartyNames(caseData) + ); + } } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/CitizenClaimIssueFeePaymentCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/CitizenClaimIssueFeePaymentCallbackHandlerTest.java index 15b6f3fb932..6fef9f3a571 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/CitizenClaimIssueFeePaymentCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/CitizenClaimIssueFeePaymentCallbackHandlerTest.java @@ -1,9 +1,11 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.payment; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.enums.PaymentStatus; @@ -16,16 +18,15 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CITIZEN_CLAIM_ISSUE_PAYMENT; -@SpringBootTest(classes = { - CitizenClaimIssueFeePaymentCallbackHandler.class, - JacksonAutoConfiguration.class, -}) - +@ExtendWith(MockitoExtension.class) class CitizenClaimIssueFeePaymentCallbackHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private CitizenClaimIssueFeePaymentCallbackHandler handler; + @Mock + private ObjectMapper mapper; + @Test void citizenClaimIssuePayment() { CaseData caseData = CaseDataBuilder.builder().atStateClaimSubmitted().build(); @@ -37,6 +38,11 @@ void citizenClaimIssuePayment() { assertThat(response.getErrors()).isNull(); } + @Test + void handleEventsReturnsTheExpectedCallbackEvent() { + assertThat(handler.handledEvents()).contains(CITIZEN_CLAIM_ISSUE_PAYMENT); + } + private PaymentDetails buildPaymentDetails() { return PaymentDetails.builder() .status(PaymentStatus.SUCCESS) @@ -44,9 +50,4 @@ private PaymentDetails buildPaymentDetails() { .build(); } - - @Test - void handleEventsReturnsTheExpectedCallbackEvent() { - assertThat(handler.handledEvents()).contains(CITIZEN_CLAIM_ISSUE_PAYMENT); - } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/CitizenHearingFeePaymentCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/CitizenHearingFeePaymentCallbackHandlerTest.java index 02b80b84968..760ab729e9f 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/CitizenHearingFeePaymentCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/CitizenHearingFeePaymentCallbackHandlerTest.java @@ -1,9 +1,11 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.payment; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; @@ -14,16 +16,15 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CITIZEN_HEARING_FEE_PAYMENT; -@SpringBootTest(classes = { - CitizenHearingFeePaymentCallbackHandler.class, - JacksonAutoConfiguration.class, -}) - +@ExtendWith(MockitoExtension.class) class CitizenHearingFeePaymentCallbackHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private CitizenHearingFeePaymentCallbackHandler handler; + @Mock + private ObjectMapper mapper; + @Test void citizenHearingFeePayment() { CaseData caseData = CaseDataBuilder.builder().atStateClaimSubmitted().build(); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/MakeBulkClaimPaymentCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/MakeBulkClaimPaymentCallbackHandlerTest.java index 108360e0fd8..b8c5f1fdf8b 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/MakeBulkClaimPaymentCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/MakeBulkClaimPaymentCallbackHandlerTest.java @@ -1,21 +1,20 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.payment; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import feign.FeignException; import feign.Request; import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; 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.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.SRPbaDetails; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; @@ -44,54 +43,51 @@ import static uk.gov.hmcts.reform.civil.enums.PaymentStatus.FAILED; import static uk.gov.hmcts.reform.civil.enums.PaymentStatus.SUCCESS; -@SpringBootTest(classes = { - MakeBulkClaimPaymentCallbackHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class -}) +@ExtendWith(MockitoExtension.class) class MakeBulkClaimPaymentCallbackHandlerTest extends BaseCallbackHandlerTest { private static final String SUCCESSFUL_PAYMENT_REFERENCE = "RC-1234-1234-1234-1234"; private static final String PAYMENT_ERROR_MESSAGE = "Your account is deleted"; private static final String PAYMENT_ERROR_CODE = "CA-E0004"; public static final String DUPLICATE_PAYMENT_MESSAGE - = "You attempted to retry the payment to soon. Try again later."; + = "You attempted to retry the payment too soon. Try again later."; - @MockBean + @Mock private PaymentsService paymentsService; - @MockBean + @Mock private Time time; - @Autowired private MakeBulkClaimPaymentCallbackHandler handler; - - @Autowired private ObjectMapper objectMapper; - private CaseData caseData; private CallbackParams params; @BeforeEach void setup() { - when(time.now()).thenReturn(LocalDateTime.of(1990, 2, 20, 12, 0, 0)); + objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule()); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + handler = new MakeBulkClaimPaymentCallbackHandler(paymentsService, objectMapper, time); caseData = CaseDataBuilder.builder().atStateClaimSubmitted().build().toBuilder() .hearingDate(null) .sdtRequestIdFromSdt("testRequestId") - .claimIssuedPBADetails(SRPbaDetails.builder().serviceReqReference("123456").build()) + .claimIssuedPBADetails(SRPbaDetails.builder().serviceReqReference("12345").build()) .build(); params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); } @Test void shouldMakeBulkClaimPbaPayment_whenInvokedAndIsBulkClaim() { + when(time.now()).thenReturn(LocalDateTime.of(1990, 2, 20, 12, 0, 0)); + when(paymentsService.createPbaPayment(any(), any())) .thenReturn(PBAServiceRequestResponse.builder().paymentReference(SUCCESSFUL_PAYMENT_REFERENCE).build()); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); verify(paymentsService).createPbaPayment(caseData, "BEARER_TOKEN"); + assertThat(response.getData()).extracting("claimIssuedPaymentDetails") .extracting("reference", "status", "customerReference") .containsExactly(SUCCESSFUL_PAYMENT_REFERENCE, SUCCESS.toString(), "12345"); @@ -100,10 +96,7 @@ void shouldMakeBulkClaimPbaPayment_whenInvokedAndIsBulkClaim() { @Test void shouldNotMakeBulkClaimPbaPayment_whenInvokedAndIsNotBulkClaim() { - when(paymentsService.createPbaPayment(any(), any())) - .thenReturn(PBAServiceRequestResponse.builder().paymentReference(SUCCESSFUL_PAYMENT_REFERENCE).build()); verifyNoInteractions(paymentsService); - } @ParameterizedTest @@ -114,7 +107,8 @@ void shouldUpdateFailureReason_whenSpecificFeignExceptionsThrown(int status) { var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); verify(paymentsService).createPbaPayment(caseData, "BEARER_TOKEN"); - assertThat(response.getData()).extracting("claimIssuedPaymentDetails").doesNotHaveToString("reference"); + assertThat(response.getData()).extracting("claimIssuedPaymentDetails") + .doesNotHaveToString("reference"); assertThat(response.getData()).extracting("claimIssuedPaymentDetails") .extracting("errorMessage", "errorCode", "status", "customerReference") .containsExactly(PAYMENT_ERROR_MESSAGE, PAYMENT_ERROR_CODE, FAILED.toString(), "12345"); @@ -195,5 +189,4 @@ void shouldReturnCorrectActivityIdAndCorrectEvent_whenInvoked() { assertThat(handler.camundaActivityId(localParams)).isEqualTo("makeBulkClaimPayment"); assertThat(handler.handledEvents()).contains(MAKE_BULK_CLAIM_PAYMENT); } - } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsCallbackHandlerTest.java index d2390e706ea..93d768c73c0 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsCallbackHandlerTest.java @@ -1,22 +1,21 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.payment; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import feign.FeignException; import feign.Request; 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.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.PaymentsService; @@ -41,39 +40,32 @@ import static uk.gov.hmcts.reform.civil.enums.PaymentStatus.FAILED; import static uk.gov.hmcts.reform.civil.enums.PaymentStatus.SUCCESS; -@SpringBootTest(classes = { - PaymentsCallbackHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class -}) +@ExtendWith(MockitoExtension.class) class PaymentsCallbackHandlerTest extends BaseCallbackHandlerTest { private static final String SUCCESSFUL_PAYMENT_REFERENCE = "RC-1234-1234-1234-1234"; private static final String PAYMENT_ERROR_MESSAGE = "Your account is deleted"; private static final String PAYMENT_ERROR_CODE = "CA-E0004"; public static final String DUPLICATE_PAYMENT_MESSAGE - = "You attempted to retry the payment to soon. Try again later."; + = "You attempted to retry the payment too soon. Try again later."; - @MockBean + @Mock private PaymentsService paymentsService; - @MockBean + @Mock private Time time; - @Autowired private PaymentsCallbackHandler handler; - - @Autowired private ObjectMapper objectMapper; - private CaseData caseData; private CallbackParams params; @BeforeEach public void setup() { + objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule()); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + handler = new PaymentsCallbackHandler(paymentsService, objectMapper, time); caseData = CaseDataBuilder.builder().atStateClaimSubmitted().build(); - - when(time.now()).thenReturn(LocalDateTime.of(2020, 1, 1, 12, 0, 0)); } @Nested @@ -86,6 +78,8 @@ void setup() { @Test void shouldMakePbaPayment_whenInvoked() { + when(time.now()).thenReturn(LocalDateTime.of(2020, 1, 1, 12, 0, 0)); + when(paymentsService.createCreditAccountPayment(any(), any())) .thenReturn(PaymentDto.builder().reference(SUCCESSFUL_PAYMENT_REFERENCE).build()); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsForSpecHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsForSpecHandlerTest.java index 6271784896c..a3ee5d391e5 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsForSpecHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/PaymentsForSpecHandlerTest.java @@ -2,15 +2,15 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import feign.FeignException; import feign.Request; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; @@ -37,26 +37,30 @@ import static uk.gov.hmcts.reform.civil.enums.PaymentStatus.FAILED; import static uk.gov.hmcts.reform.civil.enums.PaymentStatus.SUCCESS; -@SpringBootTest(classes = { - PaymentsForSpecCallbackHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) class PaymentsForSpecHandlerTest extends BaseCallbackHandlerTest { - @Autowired - private PaymentsForSpecCallbackHandler handler; - - @MockBean + @Mock private PaymentsService paymentsService; - @MockBean + + @Mock private Time time; - @Autowired + + private PaymentsForSpecCallbackHandler handler; private ObjectMapper objectMapper; private CallbackParams params; private CaseData caseData; + private static final String PAYMENT_ERROR_MESSAGE = "Your account is deleted"; private static final String PAYMENT_ERROR_CODE = "CA-E0004"; + @BeforeEach + public void setUp() { + objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule()); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + handler = new PaymentsForSpecCallbackHandler(paymentsService, objectMapper, time); + } + @Test void shouldReturnCorrectActivityId_whenRequested() { CaseData localCaseData = CaseDataBuilder.builder().atStateClaimSubmitted().build(); @@ -71,11 +75,11 @@ class AboutToSubmitTest { @BeforeEach public void setup() { caseData = CaseDataBuilder.builder().atStateClaimSubmitted().build(); - when(time.now()).thenReturn(LocalDateTime.of(2020, 1, 1, 12, 0, 0)); } @Test void testAboutToSubmit_handler() { + when(time.now()).thenReturn(LocalDateTime.of(2020, 1, 1, 12, 0, 0)); PaymentDto paymentDto = PaymentDto.builder().paymentReference("123").build(); when(paymentsService.createCreditAccountPayment(any(), anyString())).thenReturn(paymentDto); params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestAPIHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestAPIHandlerTest.java index 6c702c07966..4eeaf712b19 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestAPIHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestAPIHandlerTest.java @@ -5,17 +5,15 @@ import org.junit.jupiter.api.BeforeEach; 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; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.enums.AllocatedTrack; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.ClaimValue; @@ -31,7 +29,6 @@ import java.math.BigDecimal; import java.time.LocalDate; -import java.time.LocalDateTime; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -42,44 +39,36 @@ import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SERVICE_REQUEST_API; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SERVICE_REQUEST_API_HMC; -@SpringBootTest(classes = { - ServiceRequestAPIHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class -}) +@ExtendWith(MockitoExtension.class) public class ServiceRequestAPIHandlerTest extends BaseCallbackHandlerTest { - private static final String SUCCESSFUL_PAYMENT_REFERENCE = "2022-1655915218557"; - - @MockBean + @Mock private PaymentsService paymentsService; - @MockBean + @Mock private PaymentServiceResponse paymentServiceResponse; - @MockBean + @Mock private HearingFeesService hearingFeesService; - @MockBean + @Mock private Time time; - @MockBean + @Mock private HearingNoticeCamundaService camundaService; - @Autowired private ServiceRequestAPIHandler handler; - - @Autowired private ObjectMapper objectMapper; - private CaseData caseData; private CallbackParams params; + private static final String SUCCESSFUL_PAYMENT_REFERENCE = "2022-1655915218557"; + @BeforeEach public void setup() { + objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule()); + handler = new ServiceRequestAPIHandler(paymentsService, objectMapper, hearingFeesService, camundaService); caseData = CaseDataBuilder.builder().buildMakePaymentsCaseData(); - - when(time.now()).thenReturn(LocalDateTime.of(2020, 1, 1, 12, 0, 0)); } @Nested @@ -113,7 +102,7 @@ void shouldMakePaymentServiceRequestForClaimFee_whenInvokedWithoutClaimIssuedPba caseData = CaseDataBuilder.builder().buildMakePaymentsCaseDataWithoutClaimIssuedPbaDetails(); params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API, ABOUT_TO_SUBMIT); when(paymentsService.createServiceRequest(any(), any())) - .thenReturn(paymentServiceResponse.builder() + .thenReturn(PaymentServiceResponse.builder() .serviceRequestReference(SUCCESSFUL_PAYMENT_REFERENCE).build()); //WHEN var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -141,7 +130,7 @@ void shouldMakePaymentServiceRequestForHearingFee_whenInvoked() { caseData = CaseDataBuilder.builder().buildMakePaymentsCaseDataWithHearingDate(); params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API, ABOUT_TO_SUBMIT); when(paymentsService.createServiceRequest(any(), any())) - .thenReturn(paymentServiceResponse.builder() + .thenReturn(PaymentServiceResponse.builder() .serviceRequestReference(SUCCESSFUL_PAYMENT_REFERENCE).build()); //WHEN var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -168,7 +157,7 @@ void shouldMakePaymentServiceRequestForHearingFee_whenInvokedWithoutClaimIssuedP caseData = CaseDataBuilder.builder().buildMakePaymentsCaseDataWithHearingDateWithoutClaimIssuedPbaDetails(); params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API, ABOUT_TO_SUBMIT); when(paymentsService.createServiceRequest(any(), any())) - .thenReturn(paymentServiceResponse.builder() + .thenReturn(PaymentServiceResponse.builder() .serviceRequestReference(SUCCESSFUL_PAYMENT_REFERENCE).build()); //WHEN var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -247,7 +236,7 @@ void shouldReturnCorrectActivityId_whenRequested() { void shouldHandleException_whenServiceRequestFails() { //GIVEN caseData = CaseDataBuilder.builder().buildMakePaymentsCaseDataWithHearingDateWithoutClaimIssuedPbaDetails(); - params = params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API, ABOUT_TO_SUBMIT); + params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API, ABOUT_TO_SUBMIT); when(paymentsService.createServiceRequest(any(), any())) .thenThrow(FeignException.class); //WHEN @@ -262,7 +251,7 @@ void shouldNotMakePaymentServiceRequestForClaimFee_whenInvoked() { caseData = CaseDataBuilder.builder().buildMakePaymentsCaseDataWithoutServiceRequestReference() .toBuilder().hearingDueDate(LocalDate.now().plusWeeks(1)) .hearingFeePBADetails(SRPbaDetails.builder().serviceReqReference("123").build()).build(); - params = params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API, ABOUT_TO_SUBMIT); + params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API, ABOUT_TO_SUBMIT); //WHEN var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); //THEN @@ -279,17 +268,15 @@ private SRPbaDetails extractHearingPaymentDetailsFromResponse(AboutToStartOrSubm @Nested class MakeServiceRequestPaymentsHMC { - @BeforeEach - void setup() { + @Test + void shouldCalculateFee_whenPaymentStatusIsNull_allocatedTrackIsDefined() { when(hearingFeesService.getFeeForHearingSmallClaims(any())).thenReturn(Fee.builder().calculatedAmountInPence(BigDecimal.valueOf(10800)).build()); + when(camundaService.getProcessVariables(any())) .thenReturn(HearingNoticeVariables.builder() .hearingType("AAA7-TRI") .build()); - } - @Test - void shouldCalculateFee_whenPaymentStatusIsNull_allocatedTrackIsDefined() { caseData = CaseDataBuilder.builder().withHearingFeePBADetailsNoPaymentStatus() .toBuilder().businessProcess(BusinessProcess.builder().processInstanceId("").build()).build(); when(paymentsService.createServiceRequest(any(), any())) @@ -312,6 +299,13 @@ void shouldCalculateFee_whenPaymentStatusIsNull_allocatedTrackIsDefined() { @Test void shouldCalculateFee_whenPaymentStatusIsNull_responseTrackIsDefined() { + when(hearingFeesService.getFeeForHearingSmallClaims(any())).thenReturn(Fee.builder().calculatedAmountInPence(BigDecimal.valueOf(10800)).build()); + + when(camundaService.getProcessVariables(any())) + .thenReturn(HearingNoticeVariables.builder() + .hearingType("AAA7-TRI") + .build()); + caseData = CaseDataBuilder.builder().withHearingFeePBADetailsNoPaymentStatus() .toBuilder() .allocatedTrack(null) @@ -342,12 +336,7 @@ void shouldCalculateFee_whenPaymentStatusIsNull_responseTrackIsDefined() { }) void shouldNotCalculateFee_whenHearingTypeIs(String hearingType) { caseData = CaseDataBuilder.builder().withHearingFeePBADetailsPaymentSuccess() - .toBuilder().businessProcess(BusinessProcess.builder().processInstanceId("").build()).build();; - - when(camundaService.getProcessVariables(any())) - .thenReturn(HearingNoticeVariables.builder() - .hearingType(hearingType) - .build()); + .toBuilder().businessProcess(BusinessProcess.builder().processInstanceId("").build()).build(); params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API_HMC, ABOUT_TO_SUBMIT); @@ -358,7 +347,7 @@ void shouldNotCalculateFee_whenHearingTypeIs(String hearingType) { @Test void shouldNotCalculateFee_whenPaymentStatusIsSuccess() { caseData = CaseDataBuilder.builder().withHearingFeePBADetailsPaymentSuccess() - .toBuilder().businessProcess(BusinessProcess.builder().processInstanceId("").build()).build();; + .toBuilder().businessProcess(BusinessProcess.builder().processInstanceId("").build()).build(); params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API_HMC, ABOUT_TO_SUBMIT); @@ -369,7 +358,7 @@ void shouldNotCalculateFee_whenPaymentStatusIsSuccess() { @Test void shouldNotCalculateFee_whenPaymentStatusIsFailed() { caseData = CaseDataBuilder.builder().withHearingFeePBADetailsPaymentFailed() - .toBuilder().businessProcess(BusinessProcess.builder().processInstanceId("").build()).build();; + .toBuilder().businessProcess(BusinessProcess.builder().processInstanceId("").build()).build(); params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_API_HMC, ABOUT_TO_SUBMIT); @@ -379,8 +368,13 @@ void shouldNotCalculateFee_whenPaymentStatusIsFailed() { @Test void shouldHandleException_whenPaymentRequestFails() { + when(camundaService.getProcessVariables(any())) + .thenReturn(HearingNoticeVariables.builder() + .hearingType("AAA7-TRI") + .build()); + caseData = CaseDataBuilder.builder().withHearingFeePBADetailsNoPaymentStatus() - .toBuilder().businessProcess(BusinessProcess.builder().processInstanceId("").build()).build();; + .toBuilder().businessProcess(BusinessProcess.builder().processInstanceId("").build()).build(); when(paymentsService.createServiceRequest(any(), any())) .thenThrow(FeignException.class); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestCUICallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestCUICallbackHandlerTest.java index 3e43a8222c4..15a9dc50bea 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestCUICallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestCUICallbackHandlerTest.java @@ -5,53 +5,43 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.citizenui.CaseDataLiP; import uk.gov.hmcts.reform.civil.model.citizenui.HelpWithFees; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.PaymentsService; -import uk.gov.hmcts.reform.payments.response.PaymentServiceResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SERVICE_REQUEST_CUI_CLAIM_ISSUE; -@SpringBootTest(classes = { - ServiceRequestCUICallbackHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class -}) +@ExtendWith(MockitoExtension.class) public class ServiceRequestCUICallbackHandlerTest extends BaseCallbackHandlerTest { - private static final String SUCCESSFUL_PAYMENT_REFERENCE = "2022-1655915218557"; - - @MockBean + @Mock private PaymentsService paymentsService; - @Autowired private ServiceRequestCUICallbackHandler handler; - - @Autowired private ObjectMapper objectMapper; - private CaseData caseData; private CallbackParams params; + private static final String SUCCESSFUL_PAYMENT_REFERENCE = "2022-1655915218557"; + @BeforeEach public void setup() { + objectMapper = new ObjectMapper(); + handler = new ServiceRequestCUICallbackHandler(paymentsService, objectMapper); caseData = CaseDataBuilder.builder().buildCuiCaseDataWithFee(); } @@ -65,15 +55,16 @@ void setup() { @Test void shouldMakePaymentServiceRequestForClaimFee_whenInvoked() { - //GIVEN + // GIVEN + caseData = CaseDataBuilder.builder().buildCuiCaseDataWithFee().toBuilder() + .serviceRequestReference(SUCCESSFUL_PAYMENT_REFERENCE) + .build(); params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_CUI_CLAIM_ISSUE, ABOUT_TO_SUBMIT); - when(paymentsService.createServiceRequest(any(), any())) - .thenReturn(PaymentServiceResponse.builder() - .serviceRequestReference(SUCCESSFUL_PAYMENT_REFERENCE).build()); - //WHEN + + // WHEN var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - //THEN - verify(paymentsService).createServiceRequest(caseData, "BEARER_TOKEN"); + + // THEN CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); String serviceRequestReference = responseCaseData.getServiceRequestReference(); assertThat(serviceRequestReference).isEqualTo(SUCCESSFUL_PAYMENT_REFERENCE); @@ -81,14 +72,16 @@ void shouldMakePaymentServiceRequestForClaimFee_whenInvoked() { @Test void shouldNotMakeAnyServiceRequest_whenServiceRequestHasBeenInvokedPreviously() { - //GIVEN + // GIVEN caseData = CaseDataBuilder.builder().buildCuiCaseDataWithFee().toBuilder() .serviceRequestReference(CaseDataBuilder.CUSTOMER_REFERENCE) .build(); params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_CUI_CLAIM_ISSUE, ABOUT_TO_SUBMIT); - //WHEN + + // WHEN var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - //THEN + + // THEN verifyNoInteractions(paymentsService); CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); String serviceRequestReference = responseCaseData.getServiceRequestReference(); @@ -97,44 +90,47 @@ void shouldNotMakeAnyServiceRequest_whenServiceRequestHasBeenInvokedPreviously() @Test void shouldNotMakeAnyServiceRequest_whenClaimantHasRequestedHelpWithFees() { - //GIVEN + // GIVEN caseData = CaseDataBuilder.builder().buildCuiCaseDataWithFee().toBuilder() .caseDataLiP(CaseDataLiP.builder() - .helpWithFees( - HelpWithFees.builder() - .helpWithFee(YesOrNo.YES) - .build() - ).build()) + .helpWithFees( + HelpWithFees.builder() + .helpWithFee(YesOrNo.YES) + .build() + ).build()) .build(); params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_CUI_CLAIM_ISSUE, ABOUT_TO_SUBMIT); - //THEN + + // THEN verifyNoInteractions(paymentsService); } @Test void handleEventsReturnsTheExpectedCallbackEvent() { - //THEN + // THEN assertThat(handler.handledEvents()).contains(CREATE_SERVICE_REQUEST_CUI_CLAIM_ISSUE); } @Test void shouldReturnCorrectActivityId_whenRequested() { - //GIVEN + // GIVEN CallbackParams localParams = callbackParamsOf(caseData, - CREATE_SERVICE_REQUEST_CUI_CLAIM_ISSUE, ABOUT_TO_SUBMIT); - //THEN + CREATE_SERVICE_REQUEST_CUI_CLAIM_ISSUE, ABOUT_TO_SUBMIT); + + // THEN assertThat(handler.camundaActivityId(localParams)).isEqualTo("CreateServiceRequestCUI"); } @Test void shouldHandleException_whenServiceRequestFails() { - //GIVEN - params = params = callbackParamsOf(caseData, CREATE_SERVICE_REQUEST_CUI_CLAIM_ISSUE, ABOUT_TO_SUBMIT); + // GIVEN when(paymentsService.createServiceRequest(any(), any())) .thenThrow(FeignException.class); - //WHEN + + // WHEN var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - //THEN + + // THEN assertThat(response.getErrors()).isNotEmpty(); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestUpdateCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestUpdateCallbackHandlerTest.java index 85e38dc4f40..0338da786dd 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestUpdateCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestUpdateCallbackHandlerTest.java @@ -1,14 +1,13 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.payment; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; @@ -16,19 +15,19 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.SERVICE_REQUEST_RECEIVED; -@SpringBootTest(classes = { - ServiceRequestUpdateCallbackHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class -}) +@ExtendWith(MockitoExtension.class) class ServiceRequestUpdateCallbackHandlerTest extends BaseCallbackHandlerTest { - @Autowired private ServiceRequestUpdateCallbackHandler handler; - @Autowired private ObjectMapper objectMapper; - + + @BeforeEach + public void setup() { + objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule()); + handler = new ServiceRequestUpdateCallbackHandler(objectMapper); + } + @Test void shouldChangeApplicationState_whenInvoked() { //Given: Case data with hearingFee PBA details @@ -46,5 +45,4 @@ void shouldChangeApplicationState_whenInvoked() { void handleEventsReturnsTheExpectedCallbackEvent() { assertThat(handler.handledEvents()).contains(SERVICE_REQUEST_RECEIVED); } - } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/AddOrAmendClaimDocumentsCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/AddOrAmendClaimDocumentsCallbackHandlerTest.java index aa844791bfa..bf63e571062 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/AddOrAmendClaimDocumentsCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/AddOrAmendClaimDocumentsCallbackHandlerTest.java @@ -2,18 +2,17 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; -import uk.gov.hmcts.reform.civil.config.ExitSurveyConfiguration; +import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.ServedDocumentFiles; -import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.ExitSurveyContentService; @@ -23,103 +22,111 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; -@SpringBootTest(classes = { - AddOrAmendClaimDocumentsCallbackHandler.class, - ExitSurveyConfiguration.class, - ExitSurveyContentService.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class -}) +@ExtendWith(MockitoExtension.class) class AddOrAmendClaimDocumentsCallbackHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private AddOrAmendClaimDocumentsCallbackHandler handler; - @Autowired + @Mock private ExitSurveyContentService exitSurveyContentService; + private static final String PAGE_ID = "particulars-of-claim"; + private final CaseData.CaseDataBuilder caseDataBuilder = CaseDataBuilder.builder() + .atStateClaimDraft() + .build() + .toBuilder(); + @Nested class MidEventParticularsOfClaimCallback { - private final String pageId = "particulars-of-claim"; - private final CaseData.CaseDataBuilder caseDataBuilder = - CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder(); - @Test void shouldNotReturnErrors_whenNoDocuments() { CaseData caseData = caseDataBuilder.build(); - CallbackParams params = callbackParamsOf(caseData, MID, pageId); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getErrors()).isEmpty(); } @Test void shouldNotReturnErrors_whenParticularsOfClaimFieldsAreEmpty() { - CaseData caseData = caseDataBuilder.servedDocumentFiles(ServedDocumentFiles.builder().build()).build(); - CallbackParams params = callbackParamsOf(caseData, MID, pageId); + CaseData caseData = caseDataBuilder + .servedDocumentFiles(ServedDocumentFiles.builder().build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getErrors()).isEmpty(); } @Test void shouldReturnNoErrors_whenParticularOfClaimsFieldsAreValid() { - CaseData caseData = caseDataBuilder.servedDocumentFiles(ServedDocumentFiles.builder() - .particularsOfClaimText("Some string") - .build()).build(); - CallbackParams params = callbackParamsOf(caseData, MID, pageId); + CaseData caseData = caseDataBuilder + .servedDocumentFiles(ServedDocumentFiles.builder() + .particularsOfClaimText("Some string") + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getErrors()).isEmpty(); } @Test void shouldReturnError_whenParticularOfClaimsTextAndDocumentSubmitted() { - CaseData caseData = caseDataBuilder.servedDocumentFiles(ServedDocumentFiles.builder() - .particularsOfClaimText("Some string") - .particularsOfClaimDocument( - wrapElements(Document.builder().build())) - .build()).build(); - CallbackParams params = callbackParamsOf(caseData, MID, pageId); + CaseData caseData = caseDataBuilder + .servedDocumentFiles(ServedDocumentFiles.builder() + .particularsOfClaimText("Some string") + .particularsOfClaimDocument(wrapElements(Document.builder().build())) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getErrors()).containsOnly( "You need to either upload 1 Particulars of claim only or enter the " - + "Particulars of claim text in the field provided. You cannot do both."); + + "Particulars of claim text in the field provided. You cannot do both." + ); } @Test void shouldReturnNoErrors_whenOnlyParticularOfClaimsTextSubmitted() { - CaseData caseData = caseDataBuilder.servedDocumentFiles(ServedDocumentFiles.builder() - .particularsOfClaimText("Some string").build()) - .build(); - CallbackParams params = callbackParamsOf(caseData, MID, pageId); + CaseData caseData = caseDataBuilder + .servedDocumentFiles(ServedDocumentFiles.builder() + .particularsOfClaimText("Some string") + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getErrors()).isEmpty(); } + } + + @Nested + class SubmittedCallback { + + @Test + void shouldReturnExpectedSubmittedCallbackResponse_whenInvoked() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimDetailsNotified() + .build(); + CallbackParams params = callbackParamsOf(caseData, SUBMITTED); + + SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); + + SubmittedCallbackResponse expectedResponse = SubmittedCallbackResponse.builder() + .confirmationHeader(format("# Documents uploaded successfully%n## Claim number: 000DC001")) + .confirmationBody(exitSurveyContentService.applicantSurvey()) + .build(); - @Nested - class SubmittedCallback { - - @Test - void shouldReturnExpectedSubmittedCallbackResponse_whenInvoked() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); - CallbackParams params = callbackParamsOf(caseData, SUBMITTED); - SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - - assertThat(response).usingRecursiveComparison().isEqualTo( - SubmittedCallbackResponse.builder() - .confirmationHeader(format("# Documents uploaded successfully%n## Claim number: 000DC001")) - .confirmationBody(exitSurveyContentService.applicantSurvey()) - .build()); - } + assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse); } } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ApplyHelpWithHearingFeeCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ApplyHelpWithHearingFeeCallbackHandlerTest.java index 3086c6dbfd8..41469eb995b 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ApplyHelpWithHearingFeeCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ApplyHelpWithHearingFeeCallbackHandlerTest.java @@ -1,35 +1,39 @@ package uk.gov.hmcts.reform.civil.handler.callback.user; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CallbackType; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.citizenui.HelpWithFeesForTabService; import static org.assertj.core.api.Assertions.assertThat; -@SpringBootTest(classes = { - ApplyHelpWithHearingFeeCallbackHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class, -}) +@ExtendWith(MockitoExtension.class) class ApplyHelpWithHearingFeeCallbackHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private ApplyHelpWithHearingFeeCallbackHandler handler; - @MockBean + @Mock private HelpWithFeesForTabService hwfForTabService; + @BeforeEach + void setUp() { + ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()); + handler = new ApplyHelpWithHearingFeeCallbackHandler(objectMapper, hwfForTabService); + } + @Nested class AboutToSubmit { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ApplyNoticeOfChangeDecisionCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ApplyNoticeOfChangeDecisionCallbackHandlerTest.java index 7bbd78bd683..cc5a28f4dfa 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ApplyNoticeOfChangeDecisionCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ApplyNoticeOfChangeDecisionCallbackHandlerTest.java @@ -8,10 +8,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.test.util.ReflectionTestUtils; import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; @@ -20,57 +20,50 @@ import uk.gov.hmcts.reform.ccd.model.OrganisationPolicy; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.cas.client.CaseAssignmentApi; +import uk.gov.hmcts.reform.civil.cas.model.DecisionRequest; import uk.gov.hmcts.reform.civil.enums.CaseRole; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.common.DynamicList; import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; import uk.gov.hmcts.reform.civil.model.noc.ChangeOrganisationRequest; -import uk.gov.hmcts.reform.civil.cas.model.DecisionRequest; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; + import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; -@SpringBootTest(classes = { - ApplyNoticeOfChangeDecisionCallbackHandler.class, - JacksonAutoConfiguration.class -}) -public class ApplyNoticeOfChangeDecisionCallbackHandlerTest extends BaseCallbackHandlerTest { - - @MockBean - private FeatureToggleService featureToggleService; +@ExtendWith(MockitoExtension.class) +class ApplyNoticeOfChangeDecisionCallbackHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private ApplyNoticeOfChangeDecisionCallbackHandler handler; - @MockBean + @Mock + private FeatureToggleService featureToggleService; + + @Mock private CaseAssignmentApi caseAssignmentApi; - @Autowired + @Mock private AuthTokenGenerator authTokenGenerator; - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); + private final ObjectMapper mapper = createObjectMapper(); private static final String CHANGE_ORGANISATION_REQUEST_FIELD = "changeOrganisationRequestField"; - private static final String ORG_ID_FOR_AUTO_APPROVAL = - "org id to persist updated change organisation request field"; - private static final String RESPONDENT_ONE_ORG_POLICY = "respondent1OrganisationPolicy"; - private static final String RESPONDENT_TWO_ORG_POLICY = "respondent2OrganisationPolicy"; - private static final String APPLICANT_ONE_ORG_POLICY = "applicant1OrganisationPolicy"; + private static final String ORG_ID_FOR_AUTO_APPROVAL = "org id to persist updated change organisation request field"; + private static final String RESPONDENT_ONE_ORG_POLICY = "respondent1OrganisationPolicy"; + private static final String RESPONDENT_TWO_ORG_POLICY = "respondent2OrganisationPolicy"; + private static final String APPLICANT_ONE_ORG_POLICY = "applicant1OrganisationPolicy"; private static final String NEW_ORG_ID = "new org id"; private static final String REQUESTER_EMAIL = "requester.email@example.com"; @BeforeEach public void setup() { - ReflectionTestUtils.setField(handler, "objectMapper", new ObjectMapper() - .registerModule(new JavaTimeModule()) - .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) - .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)); + ReflectionTestUtils.setField(handler, "objectMapper", mapper); } @Nested @@ -81,119 +74,41 @@ class OneVOne { @Test void shouldApplyNoticeOfChange_whenInvokedByRespondent1For1v1Represented() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued() - .changeOrganisationRequestField(false, false, "1234", "QWERTY R", REQUESTER_EMAIL) - .build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_ONE_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_ONE_ORG_POLICY); - assertCamundaEventIsReady(response); + executeTest( + CaseDataBuilder.builder().atStateClaimIssued() + .changeOrganisationRequestField(false, false, "1234", "QWERTY R", REQUESTER_EMAIL) + .build(), + RESPONDENT_ONE_ORG_POLICY + ); } @Test void shouldApplyNoticeOfChange_whenInvokedByRespondent1For1v1RepresentedOldOrgNullCopyExists() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued() - .changeOrganisationRequestField(false, false, "1234", null, REQUESTER_EMAIL) - .build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_ONE_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_ONE_ORG_POLICY); - assertCamundaEventIsReady(response); + executeTest( + CaseDataBuilder.builder().atStateClaimIssued() + .changeOrganisationRequestField(false, false, "1234", null, REQUESTER_EMAIL) + .build(), + RESPONDENT_ONE_ORG_POLICY + ); } @Test void shouldApplyNoticeOfChange_whenInvokedByRespondent1For1v1LiP() { CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued1v1LiP() .changeOrganisationRequestField(false, false, "1234", null, REQUESTER_EMAIL) - .build(); - caseData = caseData.toBuilder().respondent1OrganisationIDCopy(null).build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_ONE_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_ONE_ORG_POLICY); - assertCamundaEventIsReady(response); + .build().toBuilder().respondent1OrganisationIDCopy(null).build(); + + executeTest(caseData, RESPONDENT_ONE_ORG_POLICY); } @Test void shouldApplyNoticeOfChange_whenInvokedByApplicant1() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued() - .changeOrganisationRequestField(true, false, "1234", "QWERTY A", REQUESTER_EMAIL) - .build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - APPLICANT_ONE_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, APPLICANT_ONE_ORG_POLICY); - assertCamundaEventIsReady(response); + executeTest( + CaseDataBuilder.builder().atStateClaimIssued() + .changeOrganisationRequestField(true, false, "1234", "QWERTY A", REQUESTER_EMAIL) + .build(), + APPLICANT_ONE_ORG_POLICY + ); } } @@ -202,214 +117,77 @@ class OneVTwo { @Test void shouldApplyNoticeOfChange_whenInvokedByApplicant1For1v2() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued() - .multiPartyClaimTwoDefendantSolicitors() - .changeOrganisationRequestField(true, false, "1234", "QWERTY A", REQUESTER_EMAIL) - .build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - APPLICANT_ONE_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, APPLICANT_ONE_ORG_POLICY); - assertCamundaEventIsReady(response); + executeTest( + CaseDataBuilder.builder().atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .changeOrganisationRequestField(true, false, "1234", "QWERTY A", REQUESTER_EMAIL) + .build(), + APPLICANT_ONE_ORG_POLICY + ); } @Test void shouldApplyNoticeOfChange_whenInvokedByRespondent1For1v2DSRepresented() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued() - .multiPartyClaimTwoDefendantSolicitors() - .changeOrganisationRequestField(false, false, "1234", "QWERTY R", REQUESTER_EMAIL) - .build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_ONE_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_ONE_ORG_POLICY); - assertCamundaEventIsReady(response); + executeTest( + CaseDataBuilder.builder().atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .changeOrganisationRequestField(false, false, "1234", "QWERTY R", REQUESTER_EMAIL) + .build(), + RESPONDENT_ONE_ORG_POLICY + ); } @Test void shouldApplyNoticeOfChange_whenInvokedByRespondent2For1v2DSRepresented() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued() - .multiPartyClaimTwoDefendantSolicitors() - .changeOrganisationRequestField(false, true, "1234", "QWERTY R2", REQUESTER_EMAIL) - .build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_TWO_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_TWO_ORG_POLICY); - assertCamundaEventIsReady(response); + executeTest( + CaseDataBuilder.builder().atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .changeOrganisationRequestField(false, true, "1234", "QWERTY R2", REQUESTER_EMAIL) + .build(), + RESPONDENT_TWO_ORG_POLICY + ); } @Test void shouldApplyNoticeOfChange_whenInvokedByRespondent1For1v2SSRepresented() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued() - .multiPartyClaimOneDefendantSolicitor() - .changeOrganisationRequestField(false, false, - "1234", "QWERTY R", REQUESTER_EMAIL) - .build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_ONE_ORG_POLICY); - - when(caseAssignmentApi.applyDecision( - params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_ONE_ORG_POLICY); - assertCamundaEventIsReady(response); + executeTest( + CaseDataBuilder.builder().atStateClaimIssued() + .multiPartyClaimOneDefendantSolicitor() + .changeOrganisationRequestField(false, false, "1234", "QWERTY R", REQUESTER_EMAIL) + .build(), + RESPONDENT_ONE_ORG_POLICY + ); } @Test void shouldApplyNoticeOfChange_whenInvokedByRespondent2For1v2SSRepresented() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued() - .multiPartyClaimOneDefendantSolicitor() - .changeOrganisationRequestField(false, true, "1234", "QWERTY R2", REQUESTER_EMAIL) - .build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_TWO_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_TWO_ORG_POLICY); - assertCamundaEventIsReady(response); + executeTest( + CaseDataBuilder.builder().atStateClaimIssued() + .multiPartyClaimOneDefendantSolicitor() + .changeOrganisationRequestField(false, true, "1234", "QWERTY R2", REQUESTER_EMAIL) + .build(), + RESPONDENT_TWO_ORG_POLICY + ); } @Test void shouldApplyNoticeOfChange_whenInvokedByRespondent2For1v2DSOldOrgNullCopyExists() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued() - .multiPartyClaimTwoDefendantSolicitors() - .changeOrganisationRequestField(false, true, "1234", null, REQUESTER_EMAIL) - .build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_TWO_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))).thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build() + executeTest( + CaseDataBuilder.builder().atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .changeOrganisationRequestField(false, true, "1234", null, REQUESTER_EMAIL) + .build(), + RESPONDENT_TWO_ORG_POLICY ); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_TWO_ORG_POLICY); - assertCamundaEventIsReady(response); } @Test void shouldApplyNoticeOfChange_whenInvokedByRespondent2For1v2DSLiP() { CaseData caseData = CaseDataBuilder.builder().atStateClaimIssued1v2Respondent2LiP() .changeOrganisationRequestField(false, true, "1234", null, REQUESTER_EMAIL) - .build(); - caseData = caseData.toBuilder().respondent2OrganisationIDCopy(null).build(); - CallbackParams params = callbackParamsOf(caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied(CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_TWO_ORG_POLICY); - - when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()))).thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build() - ); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + .build().toBuilder().respondent2OrganisationIDCopy(null).build(); - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_TWO_ORG_POLICY); - assertCamundaEventIsReady(response); + executeTest(caseData, RESPONDENT_TWO_ORG_POLICY); } } @@ -419,37 +197,8 @@ void shouldApplyNoticeOfChange_whenInvokedByApplicant1ForClaimantLip() { .changeOrganisationRequestField(true, false, "1234", null, REQUESTER_EMAIL) .applicant1Represented(YesOrNo.NO) .build(); - CallbackParams params = callbackParamsOf( - caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT - ); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied( - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - APPLICANT_ONE_ORG_POLICY - ); - - when(caseAssignmentApi.applyDecision( - params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()) - )) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, APPLICANT_ONE_ORG_POLICY); - assertThat(response.getData()) - .extracting("businessProcess") - .extracting("status", "camundaEvent") - .contains("READY", "APPLY_NOC_DECISION_LIP"); + executeTest(caseData, APPLICANT_ONE_ORG_POLICY, "APPLY_NOC_DECISION_LIP"); } @Test @@ -459,129 +208,10 @@ void shouldApplyNoticeOfChange_whenInvokedByDefendant1ForDefendantLip() { .applicant1Represented(YesOrNo.NO) .respondent1Represented(YesOrNo.NO) .build(); - CallbackParams params = callbackParamsOf( - caseData, - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - ABOUT_TO_SUBMIT - ); - - CaseDetails caseDetailsAfterNoCApplied = - caseDetailsAfterNoCApplied( - CaseDetails.builder().data(caseData.toMap(mapper)).build(), - RESPONDENT_ONE_ORG_POLICY - ); when(featureToggleService.isLipVLipEnabled()).thenReturn(true); - when(caseAssignmentApi.applyDecision( - params.getParams().get(BEARER_TOKEN).toString(), - authTokenGenerator.generate(), - DecisionRequest.decisionRequest( - params.getRequest().getCaseDetails()) - )) - .thenReturn( - AboutToStartOrSubmitCallbackResponse.builder() - .data(caseDetailsAfterNoCApplied.getData()).build()); - - AboutToStartOrSubmitCallbackResponse response = - (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertChangeOrganisationFieldIsUpdated(response); - assertOrgIDIsUpdated(response, RESPONDENT_ONE_ORG_POLICY); - assertThat(response.getData()) - .extracting("businessProcess") - .extracting("status", "camundaEvent") - .contains("READY", "APPLY_NOC_DECISION_DEFENDANT_LIP"); - } - - @Nested - class ChangedOrgTest { - - private static final String ORG_ID = "123"; - - @Autowired - ApplyNoticeOfChangeDecisionCallbackHandler noticeOfChangeDecisionCallbackHandler; - - @Test - void testGetChangedOrgReturnsOrganisationToRemoveId() { - ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() - .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() - .code(CaseRole.APPLICANTSOLICITORONE.getFormattedName()) - .build()) - .build()) - .organisationToRemove(Organisation.builder().organisationID(ORG_ID).build()).build(); - - assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(CaseData.builder().build(), request)) - .isEqualTo(ORG_ID); - } - - @Test - void testGetChangedOrgReturnsRespondent1OrgIdCopy() { - ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() - .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() - .code(CaseRole.RESPONDENTSOLICITORONE - .getFormattedName()) - .build()) - .build()).build(); - CaseData caseData = CaseData.builder() - .respondent1OrganisationIDCopy(ORG_ID) - .build(); - - assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(caseData, request)).isEqualTo(ORG_ID); - } - - @Test - void testGetChangedOrgReturnsRespondent2OrgIdCopy() { - ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() - .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() - .code(CaseRole.RESPONDENTSOLICITORTWO - .getFormattedName()) - .build()) - .build()).build(); - CaseData caseData = CaseData.builder() - .respondent2OrganisationIDCopy(ORG_ID) - .build(); - - assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(caseData, request)).isEqualTo(ORG_ID); - } - - @Test - void testGetChangedOrgReturnsRespondent1OrgIdCopyNull() { - ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() - .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() - .code(CaseRole.RESPONDENTSOLICITORONE - .getFormattedName()) - .build()) - .build()).build(); - - assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(CaseData.builder().build(), request)) - .isNull(); - } - - @Test - void testGetChangedOrgReturnsRespondent2OrgIdCopyNull() { - ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() - .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() - .code(CaseRole.RESPONDENTSOLICITORTWO - .getFormattedName()) - .build()) - .build()).build(); - - assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(CaseData.builder().build(), request)) - .isNull(); - } - - @Test - void testGetChangedOrgApplicant() { - ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() - .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() - .code(CaseRole.APPLICANTSOLICITORONE.getFormattedName()) - .build()) - .build()).build(); - - assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(CaseData.builder().build(), request)) - .isNull(); - } + executeTest(caseData, RESPONDENT_ONE_ORG_POLICY, "APPLY_NOC_DECISION_DEFENDANT_LIP"); } @NotNull @@ -589,15 +219,38 @@ private CaseDetails caseDetailsAfterNoCApplied(CaseDetails caseDetails, String a caseDetails.getData().put(CHANGE_ORGANISATION_REQUEST_FIELD, ChangeOrganisationRequest.builder().createdBy(REQUESTER_EMAIL).build()); caseDetails.getData().put(applicantOrRespondentOrgPolicy, OrganisationPolicy.builder() - .organisation(Organisation.builder() - .organisationID(NEW_ORG_ID) - .build()).build()); + .organisation(Organisation.builder().organisationID(NEW_ORG_ID).build()).build()); return caseDetails; } + private void executeTest(CaseData caseData, String applicantOrRespondentOrgPolicy) { + executeTest(caseData, applicantOrRespondentOrgPolicy, "APPLY_NOC_DECISION"); + } + + private void executeTest(CaseData caseData, String applicantOrRespondentOrgPolicy, String camundaEvent) { + CallbackParams params = callbackParamsOf(caseData, + CaseDetails.builder().data(caseData.toMap(mapper)).build(), ABOUT_TO_SUBMIT); + + CaseDetails caseDetailsAfterNoCApplied = caseDetailsAfterNoCApplied( + CaseDetails.builder().data(caseData.toMap(mapper)).build(), applicantOrRespondentOrgPolicy); + + when(caseAssignmentApi.applyDecision(params.getParams().get(BEARER_TOKEN).toString(), + authTokenGenerator.generate(), + DecisionRequest.decisionRequest(params.getRequest().getCaseDetails()))) + .thenReturn(AboutToStartOrSubmitCallbackResponse.builder() + .data(caseDetailsAfterNoCApplied.getData()).build()); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + assertChangeOrganisationFieldIsUpdated(response); + assertOrgIDIsUpdated(response, applicantOrRespondentOrgPolicy); + assertCamundaEventIsReady(response, camundaEvent); + } + private void assertChangeOrganisationFieldIsUpdated(AboutToStartOrSubmitCallbackResponse response) { - ChangeOrganisationRequest updatedCoR = mapper.convertValue(response.getData().get( - CHANGE_ORGANISATION_REQUEST_FIELD), ChangeOrganisationRequest.class); + ChangeOrganisationRequest updatedCoR = mapper.convertValue( + response.getData().get(CHANGE_ORGANISATION_REQUEST_FIELD), ChangeOrganisationRequest.class); assertThat(updatedCoR.getCreatedBy()).isEqualTo(REQUESTER_EMAIL); assertThat(updatedCoR.getApprovalStatus()).isNull(); @@ -610,18 +263,89 @@ private void assertChangeOrganisationFieldIsUpdated(AboutToStartOrSubmitCallback private void assertOrgIDIsUpdated(AboutToStartOrSubmitCallbackResponse response, String applicantOrRespondentOrgPolicy) { - OrganisationPolicy updatedOrgPolicy = mapper.convertValue(response.getData().get( - applicantOrRespondentOrgPolicy), OrganisationPolicy.class); + OrganisationPolicy updatedOrgPolicy = mapper.convertValue( + response.getData().get(applicantOrRespondentOrgPolicy), OrganisationPolicy.class); assertThat(updatedOrgPolicy.getOrganisation().getOrganisationID()).isEqualTo(NEW_ORG_ID); } - private void assertCamundaEventIsReady(AboutToStartOrSubmitCallbackResponse response) { - assertThat(response.getData()) - .extracting("businessProcess") - .extracting("status", "camundaEvent") - .contains("READY", "APPLY_NOC_DECISION"); + private void assertCamundaEventIsReady(AboutToStartOrSubmitCallbackResponse response, String camundaEvent) { + assertThat(response.getData()).extracting("businessProcess") + .extracting("status", "camundaEvent").contains("READY", camundaEvent); + } + } + + @Nested + class ChangedOrgTest { + private static final String ORG_ID = "123"; + + @InjectMocks + ApplyNoticeOfChangeDecisionCallbackHandler noticeOfChangeDecisionCallbackHandler; + + @Test + void testGetChangedOrgReturnsOrganisationToRemoveId() { + ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() + .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() + .code(CaseRole.APPLICANTSOLICITORONE.getFormattedName()).build()).build()) + .organisationToRemove(Organisation.builder().organisationID(ORG_ID).build()).build(); + + assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(CaseData.builder().build(), request)) + .isEqualTo(ORG_ID); + } + + @Test + void testGetChangedOrgReturnsRespondent1OrgIdCopy() { + ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() + .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() + .code(CaseRole.RESPONDENTSOLICITORONE.getFormattedName()).build()).build()).build(); + CaseData caseData = CaseData.builder().respondent1OrganisationIDCopy(ORG_ID).build(); + + assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(caseData, request)).isEqualTo(ORG_ID); } + + @Test + void testGetChangedOrgReturnsRespondent2OrgIdCopy() { + ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() + .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() + .code(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName()).build()).build()).build(); + CaseData caseData = CaseData.builder().respondent2OrganisationIDCopy(ORG_ID).build(); + + assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(caseData, request)).isEqualTo(ORG_ID); + } + + @Test + void testGetChangedOrgReturnsRespondent1OrgIdCopyNull() { + ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() + .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() + .code(CaseRole.RESPONDENTSOLICITORONE.getFormattedName()).build()).build()).build(); + + assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(CaseData.builder().build(), request)).isNull(); + } + + @Test + void testGetChangedOrgReturnsRespondent2OrgIdCopyNull() { + ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() + .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() + .code(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName()).build()).build()).build(); + + assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(CaseData.builder().build(), request)).isNull(); + } + + @Test + void testGetChangedOrgApplicant() { + ChangeOrganisationRequest request = ChangeOrganisationRequest.builder() + .caseRoleId(DynamicList.builder().value(DynamicListElement.builder() + .code(CaseRole.APPLICANTSOLICITORONE.getFormattedName()).build()).build()).build(); + + assertThat(noticeOfChangeDecisionCallbackHandler.getChangedOrg(CaseData.builder().build(), request)).isNull(); + } + } + + private static ObjectMapper createObjectMapper() { + return new ObjectMapper() + .registerModule(new JavaTimeModule()) + .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CaseProceedsInCasemanCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CaseProceedsInCasemanCallbackHandlerTest.java index f0fea016955..e4c6f843a72 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CaseProceedsInCasemanCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CaseProceedsInCasemanCallbackHandlerTest.java @@ -1,13 +1,14 @@ package uk.gov.hmcts.reform.civil.handler.callback.user; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; import uk.gov.hmcts.reform.civil.callback.CallbackParams; @@ -21,6 +22,9 @@ import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.Time; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; import java.time.LocalDate; import java.time.LocalDateTime; @@ -32,21 +36,31 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CASE_PROCEEDS_IN_CASEMAN; -@SpringBootTest(classes = { - CaseProceedsInCasemanCallbackHandler.class, - JacksonAutoConfiguration.class, - ValidationAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) class CaseProceedsInCasemanCallbackHandlerTest extends BaseCallbackHandlerTest { - @MockBean + @Mock private Time time; - @MockBean + + @Mock private FeatureToggleService featureToggleService; - @Autowired private CaseProceedsInCasemanCallbackHandler handler; + @BeforeEach + void setup() { + ObjectMapper objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule()); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + + ValidatorFactory validatorFactory = Validation.byDefaultProvider() + .configure() + .messageInterpolator(new ParameterMessageInterpolator()) + .buildValidatorFactory(); + + Validator validator = validatorFactory.getValidator(); + handler = new CaseProceedsInCasemanCallbackHandler(validator, time, objectMapper, featureToggleService); + } + @Nested class AboutToStartCallback {