Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

DTSCCI-459 Remove Spring context #5096

Merged
merged 18 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
dbc54e1
DTSCCI-459 Remove Spring context from uk/gov/hmcts/reform/civil/handl…
AbuSalam22 Jul 16, 2024
c386a86
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 16, 2024
b0a6d35
DTSCCI-459 Remove public modifier
AbuSalam22 Jul 16, 2024
ad9b0bc
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 16, 2024
be439c2
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 17, 2024
f34fa21
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 17, 2024
247eda6
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 17, 2024
76454aa
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 17, 2024
227f189
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 19, 2024
4099efd
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 19, 2024
208959d
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 19, 2024
975dd47
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 22, 2024
717e212
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 22, 2024
f725714
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 22, 2024
f7ac4fe
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 22, 2024
6d15b33
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 22, 2024
0d34b03
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 22, 2024
7a1401d
Merge branch 'master' into DTSCCI-459-Remove-Spring-context
AbuSalamHMCTS Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class MakeBulkClaimPaymentCallbackHandler extends CallbackHandler {
private static final List<CaseEvent> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,114 +20,88 @@
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;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.POST_DJ_NON_DIVERGENT_LETTER_DEFENDANT2;
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down
Loading
Loading