diff --git a/src/main/java/uk/gov/hmcts/reform/civil/documentmanagement/model/CaseDocument.java b/src/main/java/uk/gov/hmcts/reform/civil/documentmanagement/model/CaseDocument.java index c562107e9c5..a37ae9adc2f 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/documentmanagement/model/CaseDocument.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/documentmanagement/model/CaseDocument.java @@ -2,9 +2,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; import lombok.Builder; import lombok.Data; -import lombok.NoArgsConstructor; import uk.gov.hmcts.reform.civil.enums.CaseRole; import java.time.LocalDateTime; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormCallbackHandler.java index 7b4c098951c..a672c5aa235 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormCallbackHandler.java @@ -53,6 +53,10 @@ public class GenerateClaimFormCallbackHandler extends CallbackHandler { @Value("${stitching.enabled}") private boolean stitchEnabled; + public void setStitchEnabled(boolean stitchEnabled) { + this.stitchEnabled = stitchEnabled; + } + @Override public String camundaActivityId(CallbackParams callbackParams) { return TASK_ID; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/PartyFlagStructure.java b/src/main/java/uk/gov/hmcts/reform/civil/model/PartyFlagStructure.java index 3f03ee042fa..bed2ca7eefa 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/PartyFlagStructure.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/PartyFlagStructure.java @@ -5,13 +5,15 @@ import uk.gov.hmcts.reform.civil.model.caseflags.Flags; @Data +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor @Builder(toBuilder = true) public class PartyFlagStructure { - private final String partyID; - private final String firstName; - private final String lastName; - private final String email; - private final String phone; - private final Flags flags; + private String partyID; + private String firstName; + private String lastName; + private String email; + private String phone; + private Flags flags; } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/ServedDocumentFiles.java b/src/main/java/uk/gov/hmcts/reform/civil/model/ServedDocumentFiles.java index 84db2840843..1bc12c42cc9 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/ServedDocumentFiles.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/ServedDocumentFiles.java @@ -14,9 +14,9 @@ import static java.util.Optional.ofNullable; @Data -@Builder @NoArgsConstructor @AllArgsConstructor +@Builder public class ServedDocumentFiles { private List> other; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/DisclosureOfNonElectronicDocuments.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/DisclosureOfNonElectronicDocuments.java index e2fdb2a5b09..a86788d57cd 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/DisclosureOfNonElectronicDocuments.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/DisclosureOfNonElectronicDocuments.java @@ -7,9 +7,9 @@ import uk.gov.hmcts.reform.civil.enums.YesOrNo; @Data -@Builder -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor +@Builder public class DisclosureOfNonElectronicDocuments { private YesOrNo directionsForDisclosureProposed; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Experts.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Experts.java index 061919492c5..bba1c076c8c 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Experts.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Experts.java @@ -11,9 +11,9 @@ import java.util.List; @Data -@Builder(toBuilder = true) -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor +@Builder(toBuilder = true) public class Experts { private YesOrNo expertRequired; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/FileDirectionsQuestionnaire.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/FileDirectionsQuestionnaire.java index 1eba71f3a02..664fb17d581 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/FileDirectionsQuestionnaire.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/FileDirectionsQuestionnaire.java @@ -9,9 +9,9 @@ import java.util.List; @Data -@Builder -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor +@Builder public class FileDirectionsQuestionnaire { private List explainedToClient; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/FurtherInformation.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/FurtherInformation.java index 5ed41205299..cef38b953e9 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/FurtherInformation.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/FurtherInformation.java @@ -7,9 +7,9 @@ import uk.gov.hmcts.reform.civil.enums.YesOrNo; @Data -@Builder(toBuilder = true) -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor +@Builder(toBuilder = true) public class FurtherInformation { private YesOrNo futureApplications; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Hearing.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Hearing.java index 4dd49a9e2f1..dbff3d9603a 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Hearing.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Hearing.java @@ -12,9 +12,9 @@ import java.util.List; @Data -@Builder(toBuilder = true) -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor +@Builder(toBuilder = true) public class Hearing { private HearingLength hearingLength; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/HearingSupport.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/HearingSupport.java index 556211044d5..6f646b9647e 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/HearingSupport.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/HearingSupport.java @@ -10,9 +10,9 @@ import java.util.List; @Data -@Builder(toBuilder = true) -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor +@Builder(toBuilder = true) public class HearingSupport { // CIV-5557 to be removed diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/RequestedCourt.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/RequestedCourt.java index bf6b17f4b85..8f78bf18065 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/RequestedCourt.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/RequestedCourt.java @@ -9,9 +9,9 @@ import uk.gov.hmcts.reform.civil.model.defaultjudgment.CaseLocationCivil; @Data -@Builder(toBuilder = true) -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor +@Builder(toBuilder = true) public class RequestedCourt { /** diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/VulnerabilityQuestions.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/VulnerabilityQuestions.java index ee0010da92c..6b13608eb4c 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/VulnerabilityQuestions.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/VulnerabilityQuestions.java @@ -10,8 +10,8 @@ @NoArgsConstructor public class VulnerabilityQuestions { - private YesOrNo vulnerabilityAdjustmentsRequired; - private String vulnerabilityAdjustments; + YesOrNo vulnerabilityAdjustmentsRequired; + String vulnerabilityAdjustments; public VulnerabilityQuestions(YesOrNo vulnerabilityAdjustmentsRequired, String vulnerabilityAdjustments) { this.vulnerabilityAdjustmentsRequired = vulnerabilityAdjustmentsRequired; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/WelshLanguageRequirements.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/WelshLanguageRequirements.java index 4d9393daead..87002c6a11b 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/WelshLanguageRequirements.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/WelshLanguageRequirements.java @@ -8,8 +8,8 @@ @Data @Builder(toBuilder = true) -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor public class WelshLanguageRequirements { private Language evidence; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Witnesses.java b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Witnesses.java index 803ee12c947..e70a66bdfaa 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Witnesses.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/dq/Witnesses.java @@ -10,9 +10,9 @@ import java.util.List; @Data -@Builder(toBuilder = true) -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor +@Builder(toBuilder = true) public class Witnesses { private YesOrNo witnessesToAppear; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateCUIResponseSealedFormCallBackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateCUIResponseSealedFormCallBackHandlerTest.java index 96a47204afe..335ad51df30 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateCUIResponseSealedFormCallBackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateCUIResponseSealedFormCallBackHandlerTest.java @@ -1,15 +1,14 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentMatchers; -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 org.springframework.test.util.ReflectionTestUtils; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; @@ -42,31 +41,34 @@ import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.N1; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateCUIResponseSealedFormCallBackHandler.class, - JacksonAutoConfiguration.class, - AssignCategoryId.class -}) +@ExtendWith(MockitoExtension.class) class GenerateCUIResponseSealedFormCallBackHandlerTest extends BaseCallbackHandlerTest { - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - @Autowired + @Mock + private ObjectMapper mapper; + @InjectMocks private GenerateCUIResponseSealedFormCallBackHandler handler; - @MockBean + @Mock private SealedClaimLipResponseFormGenerator formGenerator; - @MockBean + @Mock private SystemGeneratedDocumentService systemGeneratedDocumentService; - @MockBean + @Mock private CivilDocumentStitchingService civilDocumentStitchingService; - @MockBean + @Mock private FeatureToggleService featureToggleService; - @MockBean + @Mock private AssignCategoryId assignCategoryId; + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + handler = new GenerateCUIResponseSealedFormCallBackHandler(mapper, formGenerator, systemGeneratedDocumentService, + assignCategoryId, civilDocumentStitchingService, featureToggleService); + mapper.registerModule(new JavaTimeModule()); + } + private static final CaseDocument FORM = CaseDocument.builder() .createdBy("John") @@ -108,14 +110,9 @@ class GenerateCUIResponseSealedFormCallBackHandlerTest extends BaseCallbackHandl .build(); private static final String BEARER_TOKEN = "BEARER_TOKEN"; - @BeforeEach - void setup() { - when(featureToggleService.isLipVLipEnabled()).thenReturn(false); - ReflectionTestUtils.setField(handler, "stitchEnabled", false); - } - @Test void shouldGenerateForm_whenAboutToSubmitCalled() { + ReflectionTestUtils.setField(handler, "stitchEnabled", false); given(formGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); CaseData caseData = CaseData.builder().build(); handler.handle(callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); @@ -127,7 +124,6 @@ void shouldGenerateForm_whenIsLipVLipEnabledStitchingDisabled() { //Given given(formGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); CaseData caseData = CaseData.builder().build(); - when(featureToggleService.isLipVLipEnabled()).thenReturn(true); //When handler.handle(callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); @@ -139,6 +135,8 @@ void shouldGenerateForm_whenIsLipVLipEnabledStitchingDisabled() { @Test void shouldGenerateForm_whenIsLipVLipEnabledStitchingEnabled() { //Given + when(featureToggleService.isLipVLipEnabled()).thenReturn(false); + ReflectionTestUtils.setField(handler, "stitchEnabled", false); List> documents = List.of( element(CaseDocument.builder().documentName("Stitched document").build()), element(CaseDocument.builder().documentName("document name").build())); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormCallbackHandlerTest.java index 5eec5ee8ed9..9b8a0e8f7de 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormCallbackHandlerTest.java @@ -1,22 +1,19 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; 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.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentMatchers; -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 org.springframework.test.context.NestedTestConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit.jupiter.SpringExtension; + 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.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; @@ -48,32 +45,27 @@ import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.LIP_CLAIM_FORM; import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.N1; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateClaimFormCallbackHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class, - AssignCategoryId.class -}) +@ExtendWith(MockitoExtension.class) class GenerateClaimFormCallbackHandlerTest extends BaseCallbackHandlerTest { - @MockBean + @Mock private Time time; - @MockBean + @Mock private CivilDocumentStitchingService civilDocumentStitchingService; - @MockBean + @Mock private LitigantInPersonFormGenerator litigantInPersonFormGenerator; - @MockBean + @Mock private SealedClaimFormGenerator sealedClaimFormGenerator; - @MockBean + @Mock private FeatureToggleService featureToggleService; - @Autowired + @InjectMocks private GenerateClaimFormCallbackHandler handler; - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - @Autowired + + @Mock + private ObjectMapper mapper; + @Mock private AssignCategoryId assignCategoryId; private static final String BEARER_TOKEN = "BEARER_TOKEN"; @@ -134,20 +126,23 @@ class GenerateClaimFormCallbackHandlerTest extends BaseCallbackHandlerTest { private final LocalDate issueDate = now(); - @BeforeEach - void setup() { - when(sealedClaimFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); - when(litigantInPersonFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(LIP_FORM); - when(civilDocumentStitchingService.bundle(ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), - any(CaseData.class))).thenReturn(STITCHED_DOC); - when(time.now()).thenReturn(issueDate.atStartOfDay()); - } - @Nested class GenerateClaimFormOnly { + @BeforeEach + void setup() { + mapper = new ObjectMapper(); + handler = new GenerateClaimFormCallbackHandler(civilDocumentStitchingService, litigantInPersonFormGenerator, + sealedClaimFormGenerator, mapper, time, assignCategoryId, featureToggleService); + handler.setStitchEnabled(true); + mapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule()); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + } + @Test void shouldGenerateClaimForm_whenOneVsOne_andDefendantRepresented() { + when(sealedClaimFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); CaseData caseData = CaseDataBuilder.builder().atStatePendingClaimIssued().build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -164,6 +159,8 @@ void shouldGenerateClaimForm_whenOneVsOne_andDefendantRepresented() { @Test void shouldGenerateClaimForm_whenOneVsTwo_andBothPartiesRepresented() { + when(sealedClaimFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); CaseData caseData = CaseDataBuilder.builder() .atStatePendingClaimIssued() .multiPartyClaimTwoDefendantSolicitors() @@ -183,6 +180,8 @@ void shouldGenerateClaimForm_whenOneVsTwo_andBothPartiesRepresented() { @Test void shouldGenerateClaimForm_andAssignCategoryId() { + when(sealedClaimFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); CaseData caseData = CaseDataBuilder.builder().atStatePendingClaimIssued().build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -198,15 +197,31 @@ void shouldGenerateClaimForm_andAssignCategoryId() { @Nested class GenerateAndStitchLitigantInPersonForm { + @BeforeEach + void setup() { + mapper = new ObjectMapper(); + handler = new GenerateClaimFormCallbackHandler(civilDocumentStitchingService, litigantInPersonFormGenerator, + sealedClaimFormGenerator, mapper, time, assignCategoryId, featureToggleService); + handler.setStitchEnabled(true); + mapper.registerModule(new JavaTimeModule()); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + } + @Test void shouldStitchClaimFormWithLipForm_whenOneVsOne_withLitigantInPerson() { CaseData caseData = CaseDataBuilder.builder().atStatePendingClaimIssuedUnrepresentedDefendant().build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(sealedClaimFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(litigantInPersonFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(LIP_FORM); + when(civilDocumentStitchingService.bundle(org.mockito.ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), + any(CaseData.class))).thenReturn(STITCHED_DOC); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); assertThat(updatedData.getSystemGeneratedCaseDocuments().get(0).getValue()).isEqualTo(STITCHED_DOC); + verify(sealedClaimFormGenerator).generate(any(CaseData.class), eq(BEARER_TOKEN)); verify(litigantInPersonFormGenerator).generate(any(CaseData.class), eq(BEARER_TOKEN)); verify(civilDocumentStitchingService).bundle(eq(documents), anyString(), anyString(), anyString(), @@ -221,6 +236,11 @@ void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andDef1LitigantInPerson() { .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(sealedClaimFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(litigantInPersonFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(LIP_FORM); + when(civilDocumentStitchingService.bundle(org.mockito.ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), + any(CaseData.class))).thenReturn(STITCHED_DOC); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); @@ -239,6 +259,11 @@ void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andDef2LitigantInPerson() { .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(sealedClaimFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(litigantInPersonFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(LIP_FORM); + when(civilDocumentStitchingService.bundle(org.mockito.ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), + any(CaseData.class))).thenReturn(STITCHED_DOC); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); @@ -252,6 +277,10 @@ void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andDef2LitigantInPerson() { @Test void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andBothDefendantsAreLitigantInPerson() { + when(sealedClaimFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(litigantInPersonFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(LIP_FORM); + when(civilDocumentStitchingService.bundle(org.mockito.ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), + any(CaseData.class))).thenReturn(STITCHED_DOC); CaseData caseData = CaseDataBuilder.builder() .atStateClaimSubmittedNoRespondentRepresented() .build(); @@ -280,36 +309,34 @@ void shouldReturnCorrectActivityId_whenRequested() { @NestedTestConfiguration(NestedTestConfiguration.EnclosingConfiguration.OVERRIDE) @Nested - @TestPropertySource(properties = "stitching.enabled=false") - @ExtendWith(SpringExtension.class) - @SpringBootTest(classes = { - GenerateClaimFormCallbackHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class, - AssignCategoryId.class - }) + @ExtendWith(MockitoExtension.class) class GenerateSealedClaimNoStitch { - @MockBean + @Mock private Time time; - @MockBean + @Mock private CivilDocumentStitchingService civilDocumentStitchingService; - @MockBean + @Mock private LitigantInPersonFormGenerator litigantInPersonFormGenerator; - @MockBean + @Mock private SealedClaimFormGenerator sealedClaimFormGenerator; - @Autowired + @InjectMocks private GenerateClaimFormCallbackHandler handler; - @Autowired + @InjectMocks private AssignCategoryId assignCategoryId; - @MockBean + @Mock private FeatureToggleService featureToggleService; @BeforeEach void setup() { + mapper = new ObjectMapper(); + handler = new GenerateClaimFormCallbackHandler(civilDocumentStitchingService, litigantInPersonFormGenerator, + sealedClaimFormGenerator, mapper, time, assignCategoryId, featureToggleService); + handler.setStitchEnabled(false); + mapper.registerModule(new JavaTimeModule()); when(sealedClaimFormGenerator.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); when(time.now()).thenReturn(issueDate.atStartOfDay()); } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormForSpecHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormForSpecHandlerTest.java index 3dd43214236..d3182796800 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormForSpecHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateClaimFormForSpecHandlerTest.java @@ -1,20 +1,18 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; 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.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentMatchers; -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.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.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; @@ -49,43 +47,45 @@ import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.SEALED_CLAIM; import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.N1; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateClaimFormForSpecCallbackHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class, - AssignCategoryId.class -}) +@ExtendWith(MockitoExtension.class) class GenerateClaimFormForSpecHandlerTest extends BaseCallbackHandlerTest { protected static final String UPLOAD_TIMESTAMP = "14 Apr 2024 00:00:00"; - @Autowired + @InjectMocks private GenerateClaimFormForSpecCallbackHandler handler; - @MockBean + @Mock private SealedClaimFormGeneratorForSpec sealedClaimFormGeneratorForSpec; - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); + @Mock + private ObjectMapper mapper; - @Autowired + @InjectMocks private AssignCategoryId assignCategoryId; - @MockBean + @Mock private Time time; - @MockBean + @Mock private DeadlinesCalculator deadlinesCalculator; - @MockBean + @Mock private CivilDocumentStitchingService civilDocumentStitchingService; - @MockBean + @Mock private LitigantInPersonFormGenerator litigantInPersonFormGenerator; - @MockBean + @Mock private FeatureToggleService toggleService; + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + handler = new GenerateClaimFormForSpecCallbackHandler(sealedClaimFormGeneratorForSpec, mapper, time, deadlinesCalculator, + civilDocumentStitchingService, toggleService, assignCategoryId, toggleService); + mapper.registerModule(new JavaTimeModule()); + } + private static final String BEARER_TOKEN = "BEARER_TOKEN"; private static final CaseDocument CLAIM_FORM = @@ -118,33 +118,26 @@ class GenerateClaimFormForSpecHandlerTest extends BaseCallbackHandlerTest { List documents = new ArrayList<>(); List specClaimTimelineDocuments = new ArrayList<>(); - @BeforeEach - void setup() { - when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); - when(civilDocumentStitchingService.bundle(ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), - any(CaseData.class))).thenReturn(STITCHED_DOC); - when(time.now()).thenReturn(issueDate.atStartOfDay()); - documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), - "Sealed Claim form", - LocalDate.now().toString())); - specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), - "Sealed Claim form", - LocalDate.now().toString())); - specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), - "Claim timeline", - LocalDate.now().toString())); - specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), - "Supported docs", - LocalDate.now().toString())); - - } - @Nested class GenerateClaimFormOnlySpec { @Test void shouldGenerateClaimForm_whenOneVsOne_andDefendantRepresentedSpecClaim() { // Given + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); CaseData caseData = CaseDataBuilder.builder() .atStatePendingClaimIssued().build().toBuilder() .specRespondent1Represented(YES) @@ -166,6 +159,20 @@ void shouldGenerateClaimForm_whenOneVsOne_andDefendantRepresentedSpecClaim() { @Test void shouldGenerateClaimForm_whenOneVsTwo_andBothPartiesRepresentedSpecClaim() { + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); CaseData caseData = CaseDataBuilder.builder() .multiPartyClaimTwoDefendantSolicitorsSpec() .atStatePendingClaimIssued().build().toBuilder() @@ -185,6 +192,22 @@ void shouldGenerateClaimForm_whenOneVsTwo_andBothPartiesRepresentedSpecClaim() { @Test void shouldGenerateClaimFormWithClaimTimeLineDocs_whenUploadedByRespondent() { + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(civilDocumentStitchingService.bundle(ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), + any(CaseData.class))).thenReturn(STITCHED_DOC); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); CaseData caseData = CaseDataBuilder.builder() .atStatePendingClaimIssued().build().toBuilder() .specRespondent1Represented(YES) @@ -213,6 +236,20 @@ void shouldGenerateClaimFormWithClaimTimeLineDocs_whenUploadedByRespondent() { @Test void shouldAssignCategoryId_whenInvoked() { // Given + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); CaseData caseData = CaseDataBuilder.builder() .atStatePendingClaimIssued().build().toBuilder() .specRespondent1Represented(YES) @@ -229,6 +266,22 @@ void shouldAssignCategoryId_whenInvoked() { @Test void shouldAssignCategoryIdParticulars_whenInvoked() { // Given + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(civilDocumentStitchingService.bundle(ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), + any(CaseData.class))).thenReturn(STITCHED_DOC); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); Document testDocument = new Document("testurl", "testBinUrl", "A Fancy Name", "hash", null, UPLOAD_TIMESTAMP); @@ -249,6 +302,22 @@ void shouldAssignCategoryIdParticulars_whenInvoked() { @Test void shouldAssignCategoryIdTimeline_whenInvoked() { // Given + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(civilDocumentStitchingService.bundle(ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), + any(CaseData.class))).thenReturn(STITCHED_DOC); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); Document testDocument = new Document("testurl", "testBinUrl", "A Fancy Name", "hash", null, UPLOAD_TIMESTAMP); @@ -269,6 +338,22 @@ void shouldAssignCategoryIdTimeline_whenInvoked() { @Test void shouldAssignCategoryIdBothTimelineAndParticulars_whenInvoked() { // Given + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(civilDocumentStitchingService.bundle(ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), + any(CaseData.class))).thenReturn(STITCHED_DOC); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); Document testDocument = new Document("testurl", "testBinUrl", "A Fancy Name", "hash", null, UPLOAD_TIMESTAMP); @@ -292,6 +377,22 @@ void shouldAssignCategoryIdBothTimelineAndParticulars_whenInvoked() { @Test void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { // Given + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(civilDocumentStitchingService.bundle(ArgumentMatchers.anyList(), anyString(), anyString(), anyString(), + any(CaseData.class))).thenReturn(STITCHED_DOC); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); Document testDocument = new Document("testurl", "testBinUrl", "A Fancy Name", "hash", null, UPLOAD_TIMESTAMP); @@ -317,6 +418,20 @@ class GenerateAndStitchLitigantInPersonFormSpec { @Test void shouldStitchClaimFormWithLipForm_whenOneVsOne_withLitigantInPersonSpecClaim() { + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); CaseData caseData = CaseDataBuilder.builder() .atStatePendingClaimIssuedUnrepresentedDefendant().build().toBuilder() .specRespondent1Represented(NO) @@ -334,6 +449,20 @@ void shouldStitchClaimFormWithLipForm_whenOneVsOne_withLitigantInPersonSpecClaim @Test void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andDef1LitigantInPersonSpecClaim() { + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); CaseData caseData = CaseDataBuilder.builder() .atStateClaimSubmitted1v2AndOnlySecondRespondentIsRepresented().build().toBuilder() .specRespondent1Represented(NO) @@ -352,6 +481,20 @@ void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andDef1LitigantInPersonSpecCl @Test void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andDef2LitigantInPersonSpecClaim() { + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); CaseData caseData = CaseDataBuilder.builder() .atStateClaimSubmitted1v2AndOnlyFirstRespondentIsRepresented().build().toBuilder() .specRespondent1Represented(YES) @@ -370,6 +513,20 @@ void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andDef2LitigantInPersonSpecCl @Test void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andBothDefendantsAreLitigantInPersonSpecClaim() { + when(sealedClaimFormGeneratorForSpec.generate(any(CaseData.class), anyString())).thenReturn(CLAIM_FORM); + when(time.now()).thenReturn(issueDate.atStartOfDay()); + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); CaseData caseData = CaseDataBuilder.builder() .atStateClaimSubmittedNoRespondentRepresented().build().toBuilder() .specRespondent1Represented(NO) @@ -388,6 +545,18 @@ void shouldStitchClaimFormWithLipForm_whenOneVsTwo_andBothDefendantsAreLitigantI @Test void shouldNotGenerateClaimForm_whenLipvLipFlagIsOnAndApplicantIsLip() { + documents.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Sealed Claim form", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Claim timeline", + LocalDate.now().toString())); + specClaimTimelineDocuments.add(new DocumentMetaData(CLAIM_FORM.getDocumentLink(), + "Supported docs", + LocalDate.now().toString())); given(toggleService.isLipVLipEnabled()).willReturn(true); CaseData caseData = CaseDataBuilder.builder() diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDJFormHandlerSpecNonDivergentTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDJFormHandlerSpecNonDivergentTest.java index 0fd255995da..7ac271790e7 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDJFormHandlerSpecNonDivergentTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDJFormHandlerSpecNonDivergentTest.java @@ -4,19 +4,16 @@ import org.junit.jupiter.api.Nested; 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.autoconfigure.validation.ValidationAutoConfiguration; -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.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; 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; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; +import org.junit.jupiter.api.BeforeEach; 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; @@ -26,6 +23,7 @@ import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.docmosis.dj.DefaultJudgmentFormGenerator; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.time.LocalDateTime; import java.util.ArrayList; @@ -46,27 +44,27 @@ import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DEFAULT_JUDGMENT_DEFENDANT2; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateDJFormHandlerSpecNonDivergent.class, - JacksonAutoConfiguration.class, - ValidationAutoConfiguration.class, - CaseDetailsConverter.class, - AssignCategoryId.class -}) +@ExtendWith(MockitoExtension.class) class GenerateDJFormHandlerSpecNonDivergentTest extends BaseCallbackHandlerTest { - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - @Autowired + @Mock + private ObjectMapper mapper; + @InjectMocks private GenerateDJFormHandlerSpecNonDivergent handler; - @Autowired + @InjectMocks private AssignCategoryId assignCategoryId; - @MockBean + @Mock private DefaultJudgmentFormGenerator defaultJudgmentFormGenerator; - @MockBean + @Mock private FeatureToggleService featureToggleService; + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + handler = new GenerateDJFormHandlerSpecNonDivergent(assignCategoryId, defaultJudgmentFormGenerator, mapper); + mapper.registerModule(new JavaTimeModule()); + } + @Nested class AboutToSubmitCallback { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDJFormHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDJFormHandlerTest.java index f764b84f624..f9af5adbcec 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDJFormHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDJFormHandlerTest.java @@ -1,20 +1,17 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Nested; 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.autoconfigure.validation.ValidationAutoConfiguration; -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.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; 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.common.DynamicList; import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; @@ -26,6 +23,7 @@ import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.docmosis.dj.DefaultJudgmentFormGenerator; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; +import org.junit.jupiter.api.BeforeEach; import java.time.LocalDateTime; import java.util.ArrayList; @@ -44,27 +42,27 @@ import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.DEFAULT_JUDGMENT; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateDJFormHandler.class, - JacksonAutoConfiguration.class, - ValidationAutoConfiguration.class, - CaseDetailsConverter.class, - AssignCategoryId.class -}) +@ExtendWith(MockitoExtension.class) class GenerateDJFormHandlerTest extends BaseCallbackHandlerTest { - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - @Autowired + @Mock + private ObjectMapper mapper; + @InjectMocks private GenerateDJFormHandler handler; - @Autowired + @InjectMocks private AssignCategoryId assignCategoryId; - @MockBean + @Mock private DefaultJudgmentFormGenerator defaultJudgmentFormGenerator; - @MockBean + @Mock private FeatureToggleService featureToggleService; + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + handler = new GenerateDJFormHandler(assignCategoryId, defaultJudgmentFormGenerator, mapper); + mapper.registerModule(new JavaTimeModule()); + } + @Nested class AboutToSubmitCallback { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDirectionQuestionnaireLipCallBackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDirectionQuestionnaireLipCallBackHandlerTest.java index 3bc7014b315..d2d3769c513 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDirectionQuestionnaireLipCallBackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDirectionQuestionnaireLipCallBackHandlerTest.java @@ -1,14 +1,11 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.BeforeEach; 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.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; @@ -29,35 +26,34 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.never; 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.documentmanagement.model.DocumentType.DIRECTIONS_QUESTIONNAIRE; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateDirectionQuestionnaireLipCallBackHandler.class, - JacksonAutoConfiguration.class, - AssignCategoryId.class -}) +@ExtendWith(MockitoExtension.class) class GenerateDirectionQuestionnaireLipCallBackHandlerTest extends BaseCallbackHandlerTest { - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - @Autowired - private GenerateDirectionQuestionnaireLipCallBackHandler handler; - @MockBean + @Mock + private ObjectMapper mapper; + + @Mock private DirectionQuestionnaireLipGeneratorFactory directionQuestionnaireLipGeneratorFactory; - @MockBean + + @Mock private DirectionsQuestionnaireLipGenerator directionsQuestionnaireLipGenerator; - @MockBean + + @Mock private DirectionQuestionnaireLipResponseGenerator directionQuestionnaireLipResponseGenerator; - @MockBean + @Mock private SystemGeneratedDocumentService systemGeneratedDocumentService; - @MockBean + + @Mock private FeatureToggleService featureToggleService; - @MockBean + @Mock private AssignCategoryId assignCategoryId; + @InjectMocks + private GenerateDirectionQuestionnaireLipCallBackHandler handler; + private static final CaseDocument FORM = CaseDocument.builder() .createdBy("John") .documentName("document name") @@ -84,14 +80,9 @@ class GenerateDirectionQuestionnaireLipCallBackHandlerTest extends BaseCallbackH .build(); private static final String BEARER_TOKEN = "BEARER_TOKEN"; - @BeforeEach - void setUp() { - given(directionQuestionnaireLipGeneratorFactory.getDirectionQuestionnaire()).willReturn( - directionsQuestionnaireLipGenerator); - } - @Test void shouldGenerateForm_whenAboutToSubmitCalled() { + given(directionQuestionnaireLipGeneratorFactory.getDirectionQuestionnaire()).willReturn(directionsQuestionnaireLipGenerator); given(directionsQuestionnaireLipGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); CaseData caseData = CaseData.builder().build(); @@ -103,7 +94,6 @@ void shouldGenerateForm_whenAboutToSubmitCalled() { void shouldGenerateForm_whenAboutToSubmitCalledLipVLipEnabled() { given(directionQuestionnaireLipGeneratorFactory.getDirectionQuestionnaire()).willReturn( directionQuestionnaireLipResponseGenerator); - when(featureToggleService.isLipVLipEnabled()).thenReturn(true); given(directionQuestionnaireLipResponseGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); CaseData caseData = CaseData.builder().build(); @@ -123,10 +113,7 @@ void shouldNotGenerateForm_whenAboutToSubmitCalledWithFullAdmission() { // Verify interactions verify(directionsQuestionnaireLipGenerator, never()).generate(any(CaseData.class), anyString()); - verify( - systemGeneratedDocumentService, - never() - ).getSystemGeneratedDocumentsWithAddedDocument(any(CaseDocument.class), any(CaseData.class)); + verify(systemGeneratedDocumentService, never()).getSystemGeneratedDocumentsWithAddedDocument(any(CaseDocument.class), any(CaseData.class)); } @Test @@ -142,15 +129,12 @@ void shouldNotGenerateForm_whenAboutToSubmitCalledWhenClaimantAcceptThePartAdmit // Verify interactions verify(directionsQuestionnaireLipGenerator, never()).generate(any(CaseData.class), anyString()); - verify( - systemGeneratedDocumentService, - never() - ).getSystemGeneratedDocumentsWithAddedDocument(any(CaseDocument.class), any(CaseData.class)); + verify(systemGeneratedDocumentService, never()).getSystemGeneratedDocumentsWithAddedDocument(any(CaseDocument.class), any(CaseData.class)); } @Test void shouldGenerateForm_whenAboutToSubmitCalledWhenClaimantRejectsThePartAdmit() { - // Given + given(directionQuestionnaireLipGeneratorFactory.getDirectionQuestionnaire()).willReturn(directionsQuestionnaireLipGenerator); given(directionsQuestionnaireLipGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); CaseData caseData = CaseData.builder() .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.PART_ADMISSION) @@ -160,16 +144,13 @@ void shouldGenerateForm_whenAboutToSubmitCalledWhenClaimantRejectsThePartAdmit() // Call the handler's callback method handler.handle(callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); - // Verify interactions - given(directionsQuestionnaireLipGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM); verify(directionsQuestionnaireLipGenerator).generate(caseData, BEARER_TOKEN); } @Test void shouldNotGenerateForm_whenAboutToSubmitCalledWithFullAdmissionWithDefendantDoc() { - // Given - given(directionsQuestionnaireLipGenerator.generate(any(CaseData.class), anyString())) - .willReturn(FORM_DEFENDANT); + given(directionQuestionnaireLipGeneratorFactory.getDirectionQuestionnaire()).willReturn(directionsQuestionnaireLipGenerator); + given(directionsQuestionnaireLipGenerator.generate(any(CaseData.class), anyString())).willReturn(FORM_DEFENDANT); CaseData caseData = CaseData.builder().build(); handler.handle(callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDirectionsQuestionnaireCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDirectionsQuestionnaireCallbackHandlerTest.java index ba189849a21..0d4a1fdd88d 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDirectionsQuestionnaireCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDirectionsQuestionnaireCallbackHandlerTest.java @@ -1,20 +1,18 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; 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.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; 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.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Party; @@ -45,13 +43,7 @@ import static uk.gov.hmcts.reform.civil.enums.CaseCategory.UNSPEC_CLAIM; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateDirectionsQuestionnaireCallbackHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class, - AssignCategoryId.class -}) +@ExtendWith(MockitoExtension.class) class GenerateDirectionsQuestionnaireCallbackHandlerTest extends BaseCallbackHandlerTest { public static final CaseDocument DOCUMENT = CaseDocument.builder() @@ -67,27 +59,26 @@ class GenerateDirectionsQuestionnaireCallbackHandlerTest extends BaseCallbackHan .build()) .build(); - @MockBean + @Mock private DirectionsQuestionnaireGenerator directionsQuestionnaireGenerator; - @Autowired + @InjectMocks private GenerateDirectionsQuestionnaireCallbackHandler handler; - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); + @Mock + private ObjectMapper mapper; - @Autowired + @InjectMocks private AssignCategoryId assignCategoryId; - @MockBean + @Mock private FeatureToggleService featureToggleService; @BeforeEach void setup() { - when(directionsQuestionnaireGenerator.generate(any(CaseData.class), anyString())).thenReturn(DOCUMENT); - when(directionsQuestionnaireGenerator.generateDQFor1v2SingleSolDiffResponse(any(CaseData.class), - anyString(), anyString() - )).thenReturn(DOCUMENT); + mapper = new ObjectMapper(); + handler = new GenerateDirectionsQuestionnaireCallbackHandler(directionsQuestionnaireGenerator, mapper, assignCategoryId); + mapper.registerModule(new JavaTimeModule()); } @Test @@ -98,6 +89,8 @@ void shouldAddDocumentToSystemGeneratedDocuments_whenInvoked() { CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(directionsQuestionnaireGenerator.generate(any(CaseData.class), anyString())).thenReturn(DOCUMENT); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); verify(directionsQuestionnaireGenerator).generate(caseData, "BEARER_TOKEN"); @@ -121,6 +114,10 @@ void shouldAddDocumentToSystemGeneratedDocuments_whenSameLRDiffResponseResponden .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(directionsQuestionnaireGenerator.generateDQFor1v2SingleSolDiffResponse(any(CaseData.class), + anyString(), anyString() + )).thenReturn(DOCUMENT); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); verify(directionsQuestionnaireGenerator).generateDQFor1v2SingleSolDiffResponse( @@ -147,6 +144,10 @@ void shouldAddDocumentToSystemGeneratedDocuments_whenSameLRDiffResponseResponden .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(directionsQuestionnaireGenerator.generateDQFor1v2SingleSolDiffResponse(any(CaseData.class), + anyString(), anyString() + )).thenReturn(DOCUMENT); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); verify(directionsQuestionnaireGenerator).generateDQFor1v2SingleSolDiffResponse( @@ -170,6 +171,8 @@ void shouldAddDocumentToSystemGeneratedDocuments_whenSameLRSameResponse() { .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(directionsQuestionnaireGenerator.generate(any(CaseData.class), anyString())).thenReturn(DOCUMENT); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); verify(directionsQuestionnaireGenerator).generate(caseData, "BEARER_TOKEN"); @@ -193,6 +196,8 @@ void shouldAddDocumentToSystemGeneratedDocuments_whenSameLRSameResponseSpec() { .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(directionsQuestionnaireGenerator.generate(any(CaseData.class), anyString())).thenReturn(DOCUMENT); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); verify(directionsQuestionnaireGenerator).generate(caseData, "BEARER_TOKEN"); @@ -217,11 +222,7 @@ void shouldAddDocumentToSystemGeneratedDocuments_when1v2DiffSolRespondent1() { CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); CaseDocument generatedDocument = mock(CaseDocument.class); - when(directionsQuestionnaireGenerator.generateDQFor1v2DiffSol( - caseData, - params.getParams().get(CallbackParams.Params.BEARER_TOKEN).toString(), - "ONE" - )).thenReturn(Optional.of(generatedDocument)); + when(directionsQuestionnaireGenerator.generate(any(CaseData.class), anyString())).thenReturn(DOCUMENT); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -233,11 +234,13 @@ void shouldAddDocumentToSystemGeneratedDocuments_when1v2DiffSolRespondent1() { @Test void shouldAddDocumentToSystemGeneratedDocuments_when1v2DiffSolRespondent1Spec() { - for (RespondentResponseTypeSpec responseType : EnumSet.of(RespondentResponseTypeSpec.FULL_DEFENCE, - RespondentResponseTypeSpec.PART_ADMISSION)) { + for (RespondentResponseTypeSpec responseType : EnumSet.of( + RespondentResponseTypeSpec.FULL_DEFENCE, + RespondentResponseTypeSpec.PART_ADMISSION + )) { when(directionsQuestionnaireGenerator.generateDQFor1v2DiffSol(any(CaseData.class), - anyString(), anyString() + anyString(), anyString() )).thenReturn(Optional.of(DOCUMENT)); CaseData caseData = CaseDataBuilder.builder().atStateRespondentFullDefence() @@ -272,11 +275,7 @@ void shouldAddDocumentToSystemGeneratedDocuments_when1v2DiffSolRespondent2() { CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); CaseDocument generatedDocument = mock(CaseDocument.class); - when(directionsQuestionnaireGenerator.generateDQFor1v2DiffSol( - caseData, - params.getParams().get(CallbackParams.Params.BEARER_TOKEN).toString(), - "TWO" - )).thenReturn(Optional.of(generatedDocument)); + when(directionsQuestionnaireGenerator.generate(any(CaseData.class), anyString())).thenReturn(DOCUMENT); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -404,6 +403,7 @@ void shouldAssignDefendantCategoryId_whenInvokedAnd1v2DiffSolicitorUnspecified() .respondent2DocumentGeneration("userRespondent2") .build(); // When + when(directionsQuestionnaireGenerator.generate(any(CaseData.class), anyString())).thenReturn(DOCUMENT); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); @@ -511,6 +511,9 @@ void shouldAssignDefendantCategoryId_1v2SameSolicitorNotSameResponseSpecified() .respondentResponseIsSame(YesOrNo.NO) .build(); // When + when(directionsQuestionnaireGenerator.generateDQFor1v2SingleSolDiffResponse(any(CaseData.class), + anyString(), anyString() + )).thenReturn(DOCUMENT); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingFormHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingFormHandlerTest.java index 7fe76d6231f..6961c42b7e5 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingFormHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingFormHandlerTest.java @@ -3,16 +3,13 @@ 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.autoconfigure.validation.ValidationAutoConfiguration; -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.junit.jupiter.api.BeforeEach; +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.common.Element; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; @@ -20,6 +17,7 @@ import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; import uk.gov.hmcts.reform.civil.service.docmosis.hearing.HearingFormGenerator; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import java.time.LocalDateTime; import java.util.ArrayList; @@ -37,22 +35,23 @@ import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.HEARING_FORM; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateHearingFormHandler.class, - JacksonAutoConfiguration.class, - ValidationAutoConfiguration.class, - CaseDetailsConverter.class, -}) +@ExtendWith(MockitoExtension.class) class GenerateHearingFormHandlerTest extends BaseCallbackHandlerTest { - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - @Autowired + @Mock + private ObjectMapper mapper; + @InjectMocks private GenerateHearingFormHandler handler; - @MockBean + @Mock private HearingFormGenerator hearingFormGenerator; + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + handler = new GenerateHearingFormHandler(hearingFormGenerator, mapper); + mapper.registerModule(new JavaTimeModule()); + } + @Test void shouldGenerateForm_when1v1() { CaseDocument document = CaseDocument.builder() diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandlerTest.java index 400c77d8a59..c6d5599f3c4 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandlerTest.java @@ -1,19 +1,17 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 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.autoconfigure.validation.ValidationAutoConfiguration; -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.junit.jupiter.api.BeforeEach; +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.documentmanagement.model.CaseDocument; 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.referencedata.model.LocationRefData; @@ -46,28 +44,31 @@ import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.HEARING_NOTICE_HMC; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateHearingNoticeHmcHandler.class, - JacksonAutoConfiguration.class, - ValidationAutoConfiguration.class, - CaseDetailsConverter.class, -}) +@ExtendWith(MockitoExtension.class) class GenerateHearingNoticeHmcHandlerTest extends BaseCallbackHandlerTest { - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - @Autowired + @Mock + private ObjectMapper mapper; + + @InjectMocks private GenerateHearingNoticeHmcHandler handler; - @MockBean + @Mock private HearingsService hearingsService; - @MockBean + @Mock private HearingNoticeCamundaService camundaService; - @MockBean + @Mock private HearingNoticeHmcGenerator hearingNoticeHmcGenerator; - @MockBean + @Mock private LocationReferenceDataService locationRefDataService; + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + handler = new GenerateHearingNoticeHmcHandler(camundaService, hearingsService, hearingNoticeHmcGenerator, mapper, locationRefDataService); + mapper.registerModule(new JavaTimeModule()); + + } + private static Long CASE_ID = 1L; private static String HEARING_ID = "1234"; private static String PROCESS_INSTANCE_ID = "process-instance-id"; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateSettlementAgreementFormCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateSettlementAgreementFormCallbackHandlerTest.java index 8b51364a88a..0882389c799 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateSettlementAgreementFormCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateSettlementAgreementFormCallbackHandlerTest.java @@ -2,11 +2,9 @@ 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; @@ -17,6 +15,7 @@ import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; import uk.gov.hmcts.reform.civil.service.SystemGeneratedDocumentService; import uk.gov.hmcts.reform.civil.service.docmosis.settlementagreement.SettlementAgreementFormGenerator; +import com.fasterxml.jackson.databind.ObjectMapper; import java.time.LocalDateTime; @@ -29,19 +28,17 @@ import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_LIP_SIGN_SETTLEMENT_AGREEMENT_FORM; import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.SETTLEMENT_AGREEMENT; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateSettlementAgreementFormCallbackHandler.class, - JacksonAutoConfiguration.class, -}) +@ExtendWith(MockitoExtension.class) class GenerateSettlementAgreementFormCallbackHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private GenerateSettlementAgreementFormCallbackHandler handler; - @MockBean + @Mock private SettlementAgreementFormGenerator formGenerator; - @MockBean + @Mock private SystemGeneratedDocumentService systemGeneratedDocumentService; + @Mock + private ObjectMapper mapper; private static final String BEARER_TOKEN = "BEARER_TOKEN"; private static final CaseDocument caseDocument = CaseDocument.builder() diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateTrialReadyFormHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateTrialReadyFormHandlerTest.java index 02edab5333d..e18dfa6bcd7 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateTrialReadyFormHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateTrialReadyFormHandlerTest.java @@ -3,20 +3,18 @@ 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.autoconfigure.validation.ValidationAutoConfiguration; -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.junit.jupiter.api.BeforeEach; +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.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; import uk.gov.hmcts.reform.civil.enums.CaseRole; 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 com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import uk.gov.hmcts.reform.civil.model.common.Element; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; @@ -39,22 +37,23 @@ import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.TRIAL_READY_DOCUMENT; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - GenerateTrialReadyFormHandler.class, - JacksonAutoConfiguration.class, - ValidationAutoConfiguration.class, - CaseDetailsConverter.class, -}) +@ExtendWith(MockitoExtension.class) class GenerateTrialReadyFormHandlerTest extends BaseCallbackHandlerTest { - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); - @Autowired + @Mock + private ObjectMapper mapper; + @InjectMocks private GenerateTrialReadyFormHandler handler; - @MockBean + @Mock private TrialReadyFormGenerator trialReadyFormGenerator; + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + handler = new GenerateTrialReadyFormHandler(trialReadyFormGenerator, mapper); + mapper.registerModule(new JavaTimeModule()); + } + @Test void shouldGenerateForm_when1v1() { // Given diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/JudgmentByAdmissionPinInPostLiPDefendant1LetterHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/JudgmentByAdmissionPinInPostLiPDefendant1LetterHandlerTest.java index cebc2830896..de5a77cbc39 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/JudgmentByAdmissionPinInPostLiPDefendant1LetterHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/JudgmentByAdmissionPinInPostLiPDefendant1LetterHandlerTest.java @@ -1,10 +1,10 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; 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.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; @@ -22,15 +22,12 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.JUDGMENT_BY_ADMISSION_DEFENDANT1_PIN_IN_LETTER; -@SpringBootTest(classes = { - JudgmentByAdmissionPinInPostLiPDefendant1LetterHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) public class JudgmentByAdmissionPinInPostLiPDefendant1LetterHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private JudgmentByAdmissionPinInPostLiPDefendant1LetterHandler handler; - @MockBean + @Mock private JudgmentByAdmissionPiPLetterGenerator letterGenerator; public static final String TASK_ID = "SendJudgmentByAdmissionLiPLetterDef1"; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostDJNonDivergentPinInLetterLiPDefendant1HandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostDJNonDivergentPinInLetterLiPDefendant1HandlerTest.java index 61b8d60ae86..744caa329bd 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostDJNonDivergentPinInLetterLiPDefendant1HandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostDJNonDivergentPinInLetterLiPDefendant1HandlerTest.java @@ -1,10 +1,10 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; 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.mockito.InjectMocks; +import org.mockito.Mock; +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.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; @@ -22,15 +22,12 @@ 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_PIN_IN_LETTER_DEFENDANT1; -@SpringBootTest(classes = { - PostDJNonDivergentPinInLetterLiPDefendant1Handler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) public class PostDJNonDivergentPinInLetterLiPDefendant1HandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private PostDJNonDivergentPinInLetterLiPDefendant1Handler handler; - @MockBean + @Mock private DefaultJudgmentNonDivergentSpecPiPLetterGenerator lipLetterGenerator; public static final String TASK_ID = "PostPINInLetterLIPDefendant1"; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/RecordJudgementDeterminationOfMeansLiPDefendant1LetterHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/RecordJudgementDeterminationOfMeansLiPDefendant1LetterHandlerTest.java index 96d2823b07f..c960267b16c 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/RecordJudgementDeterminationOfMeansLiPDefendant1LetterHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/RecordJudgementDeterminationOfMeansLiPDefendant1LetterHandlerTest.java @@ -1,10 +1,10 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; 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.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; @@ -19,16 +19,13 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.POST_JO_DEFENDANT1_PIN_IN_LETTER; -@SpringBootTest(classes = { - RecordJudgmentDeterminationOfMeansLiPDefendant1LetterHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) public class RecordJudgementDeterminationOfMeansLiPDefendant1LetterHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private RecordJudgmentDeterminationOfMeansLiPDefendant1LetterHandler handler; - @MockBean + @Mock private RecordJudgmentDeterminationOfMeansPiPLetterGenerator lipLetterGenerator; public static final String TASK_ID_DEFENDANT = "SendRecordJudgmentDeterminationOfMeansLiPLetterDef1"; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/SetAsideJudgementInErrorLiPDefendant1LetterHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/SetAsideJudgementInErrorLiPDefendant1LetterHandlerTest.java index 800796bbffe..7077e25b625 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/SetAsideJudgementInErrorLiPDefendant1LetterHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/SetAsideJudgementInErrorLiPDefendant1LetterHandlerTest.java @@ -1,10 +1,10 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis; 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.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; @@ -22,15 +22,12 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.SEND_SET_ASIDE_JUDGEMENT_IN_ERROR_LETTER_TO_LIP_DEFENDANT1; -@SpringBootTest(classes = { - SetAsideJudgementInErrorLiPDefendant1LetterHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) public class SetAsideJudgementInErrorLiPDefendant1LetterHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private SetAsideJudgementInErrorLiPDefendant1LetterHandler handler; - @MockBean + @Mock private SetAsideJudgmentInErrorLiPLetterGenerator lipLetterGenerator; public static final String TASK_ID_DEFENDANT = "SendSetAsideLiPLetterDef1"; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/noticeofchange/UpdateCaseDetailsAfterNoCHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/noticeofchange/UpdateCaseDetailsAfterNoCHandlerTest.java index 13585b5b433..5cc190de141 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/noticeofchange/UpdateCaseDetailsAfterNoCHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/noticeofchange/UpdateCaseDetailsAfterNoCHandlerTest.java @@ -3,10 +3,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; 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.junit.jupiter.api.BeforeEach; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +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.CaseCategory; @@ -24,23 +26,27 @@ import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; -@SpringBootTest(classes = { - UpdateCaseDetailsAfterNoCHandler.class, - JacksonAutoConfiguration.class, -}) +@ExtendWith(MockitoExtension.class) public class UpdateCaseDetailsAfterNoCHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private UpdateCaseDetailsAfterNoCHandler handler; - @Autowired - private final ObjectMapper mapper = new ObjectMapper(); + @Mock + private ObjectMapper mapper; - @MockBean + @Mock private CoreCaseUserService coreCaseUserService; private static final String NEW_ORG_ID = "1234"; + @BeforeEach + void setUp() { + mapper = new ObjectMapper(); + handler = new UpdateCaseDetailsAfterNoCHandler(mapper, coreCaseUserService); + mapper.registerModule(new JavaTimeModule()); + } + @Nested class AboutToSubmit { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantForSpecNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantForSpecNotificationHandlerTest.java index 378567eaa83..f9a1d7ffae3 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantForSpecNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantForSpecNotificationHandlerTest.java @@ -1,13 +1,12 @@ 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.notify.NotificationsProperties; @@ -37,35 +36,27 @@ import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate; import static uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder.LEGACY_CASE_REFERENCE; -@SpringBootTest(classes = { - AcknowledgeClaimApplicantForSpecNotificationHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) class AcknowledgeClaimApplicantForSpecNotificationHandlerTest extends BaseCallbackHandlerTest { - @MockBean + @Mock private NotificationService notificationService; - @MockBean + @Mock private NotificationsProperties notificationsProperties; - @Autowired + @InjectMocks private AcknowledgeClaimApplicantForSpecNotificationHandler handler; - @MockBean + @Mock private OrganisationService organisationService; private final String legalOrgName = "legalOrgName"; - @MockBean + @Mock private FeatureToggleService toggleService; @Nested class AboutToSubmitCallback { - @BeforeEach - void setup() { - when(notificationsProperties.getRespondentSolicitorAcknowledgeClaimForSpec()).thenReturn("template-id"); - when(notificationsProperties.getApplicantSolicitorAcknowledgeClaimForSpec()).thenReturn("template-id"); - } - @Test void shouldNotifyApplicantSolicitor_whenInvoked() { + when(notificationsProperties.getApplicantSolicitorAcknowledgeClaimForSpec()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId("NOTIFY_APPLICANT_SOLICITOR1_FOR_SPEC_CLAIM_ACKNOWLEDGEMENT").build()) @@ -83,6 +74,7 @@ void shouldNotifyApplicantSolicitor_whenInvoked() { @Test void shouldNotifyRespondentSolicitor_whenInvokedWithCcEvent() { + when(notificationsProperties.getRespondentSolicitorAcknowledgeClaimForSpec()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder() @@ -115,7 +107,6 @@ RESPONSE_DEADLINE, formatLocalDate(caseData.getRespondent1ResponseDeadline().toL } public String getApplicantLegalOrganizationName(String id, CaseData caseData) { - Optional organisation = organisationService.findOrganisationById(id); return organisation.isPresent() ? organisation.get().getName() : caseData.getApplicantSolicitor1ClaimStatementOfTruth().getName(); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandlerTest.java index d32dd7e979f..a0be6dfbcfb 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandlerTest.java @@ -1,13 +1,12 @@ 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.model.IdamUserDetails; @@ -49,29 +48,22 @@ import static uk.gov.hmcts.reform.civil.utils.PartyUtils.buildPartiesReferences; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getResponseIntentionForEmail; -@SpringBootTest(classes = { - AcknowledgeClaimApplicantNotificationHandler.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) class AcknowledgeClaimApplicantNotificationHandlerTest extends BaseCallbackHandlerTest { - @MockBean + @Mock private NotificationService notificationService; - @MockBean + @Mock private NotificationsProperties notificationsProperties; - @Autowired + @InjectMocks private AcknowledgeClaimApplicantNotificationHandler handler; @Nested class AboutToSubmitCallback { - @BeforeEach - void setup() { - when(notificationsProperties.getRespondentSolicitorAcknowledgeClaim()).thenReturn("template-id"); - } - @Test void shouldNotifyApplicantSolicitor_whenInvoked() { + when(notificationsProperties.getRespondentSolicitorAcknowledgeClaim()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId("NOTIFY_APPLICANT_SOLICITOR1_FOR_CLAIM_ACKNOWLEDGEMENT").build()) @@ -88,7 +80,7 @@ void shouldNotifyApplicantSolicitor_whenInvoked() { } @Test - void shouldNotNotifyApplicantSolicitor_whenRecipeintIsNull() { + void shouldNotNotifyApplicantSolicitor_whenRecipientIsNull() { CaseData caseData = CaseDataBuilder.builder() .atStateNotificationAcknowledged() .applicantSolicitor1UserDetails(IdamUserDetails.builder().email(null).build()) @@ -103,7 +95,7 @@ void shouldNotNotifyApplicantSolicitor_whenRecipeintIsNull() { } @Test - void shouldNotNotifyRespondentSolicitor_whenRecipeint1IsNull() { + void shouldNotNotifyRespondentSolicitor_whenRecipient1IsNull() { CaseData caseData = CaseDataBuilder.builder() .atStateNotificationAcknowledged() .respondentSolicitor1EmailAddress(null) @@ -118,7 +110,7 @@ void shouldNotNotifyRespondentSolicitor_whenRecipeint1IsNull() { } @Test - void shouldNotNotifyRespondentSolicitor_whenRecipeint2IsNull() { + void shouldNotNotifyRespondentSolicitor_whenRecipient2IsNull() { CaseData caseData = CaseDataBuilder.builder() .atStateNotificationAcknowledged() .respondentSolicitor2EmailAddress(null) @@ -134,6 +126,7 @@ void shouldNotNotifyRespondentSolicitor_whenRecipeint2IsNull() { @Test void shouldNotifyRespondentSolicitor_whenInvokedWithCcEvent() { + when(notificationsProperties.getRespondentSolicitorAcknowledgeClaim()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId("NOTIFY_APPLICANT_SOLICITOR1_FOR_CLAIM_ACKNOWLEDGEMENT_CC").build()) @@ -152,6 +145,7 @@ void shouldNotifyRespondentSolicitor_whenInvokedWithCcEvent() { @Test void shouldNotifyRespondentSolicitor2WhenSolicitor2RespondsFirst_whenInvokedWithCcEvent() { //solicitor 2 acknowledges claim, solicitor 1 does not + when(notificationsProperties.getRespondentSolicitorAcknowledgeClaim()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() .addRespondent2(YES) .respondent2SameLegalRepresentative(NO) @@ -179,6 +173,7 @@ void shouldNotifyRespondentSolicitor2WhenSolicitor2RespondsFirst_whenInvokedWith @Test void shouldNotifyRespondentSolicitor2WhenSolicitor2RespondsLast_whenInvokedWithCcEvent() { //solicitor 2 acknowledges claim,solicitor 1 already acknowledged + when(notificationsProperties.getRespondentSolicitorAcknowledgeClaim()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() .addRespondent2(YES) .respondent2SameLegalRepresentative(NO) @@ -206,6 +201,7 @@ void shouldNotifyRespondentSolicitor2WhenSolicitor2RespondsLast_whenInvokedWithC @Test void shouldNotifyRespondentSolicitor1WhenSolicitor1RespondsLast_whenInvokedWithCcEvent() { //solicitor 1 acknowledges claim,solicitor 2 already acknowledged + when(notificationsProperties.getRespondentSolicitorAcknowledgeClaim()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() .addRespondent2(YES) .respondent2SameLegalRepresentative(NO) @@ -231,6 +227,7 @@ void shouldNotifyRespondentSolicitor1WhenSolicitor1RespondsLast_whenInvokedWithC @Test void shouldNotifyRespondentSolicitor1v2SameSolicitor_whenInvokedWithCcEvent() { + when(notificationsProperties.getRespondentSolicitorAcknowledgeClaim()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() .addRespondent2(YES) .respondent2SameLegalRepresentative(YES) @@ -259,6 +256,7 @@ void shouldNotifyRespondentSolicitor1v2SameSolicitor_whenInvokedWithCcEvent() { @Test void shouldNotifyRespondentSolicitor2v1SameSolicitor_whenInvokedWithCcEvent() { + when(notificationsProperties.getRespondentSolicitorAcknowledgeClaim()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() .addApplicant2(YesOrNo.YES) .applicant2(PartyBuilder.builder().individual().build()) @@ -285,6 +283,7 @@ void shouldNotifyRespondentSolicitor2v1SameSolicitor_whenInvokedWithCcEvent() { @Test void shouldNotifyRespondentSolicitor1_whenInvokedWithCcEvent() { //solicitor 1 acknowledges claim,solicitor 2 not + when(notificationsProperties.getRespondentSolicitorAcknowledgeClaim()).thenReturn("template-id"); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() .addRespondent2(YES) .respondent2SameLegalRepresentative(NO) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgementClaimApplicantForSpecHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgementClaimApplicantForSpecHandlerTest.java index b3feb9dbec5..358d51b4db0 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgementClaimApplicantForSpecHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgementClaimApplicantForSpecHandlerTest.java @@ -2,10 +2,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -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.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; @@ -17,25 +16,22 @@ import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.AcknowledgeClaimApplicantForSpecNotificationHandler.TASK_ID; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.AcknowledgeClaimApplicantForSpecNotificationHandler.TASK_ID_CC; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - AcknowledgeClaimApplicantForSpecNotificationHandler.class -}) +@ExtendWith(MockitoExtension.class) class AcknowledgementClaimApplicantForSpecHandlerTest { - @Autowired + @InjectMocks private AcknowledgeClaimApplicantForSpecNotificationHandler handler; - @MockBean + @Mock private NotificationService notificationService; - @MockBean + @Mock private NotificationsProperties notificationsProperties; - @MockBean + @Mock private OrganisationService organisationService; - @MockBean + @Mock private FeatureToggleService toggleService; @Test