diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/LipApplicantContactDetails.java b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/LipApplicantContactDetails.java new file mode 100644 index 00000000000..0d07203bef1 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/LipApplicantContactDetails.java @@ -0,0 +1,19 @@ +package uk.gov.hmcts.reform.civil.service.mediation; + +public class LipApplicantContactDetails extends LipContactDetails implements ApplicantContactDetails { + + @Override + public String getApplicantContactName(MediationParams params) { + return getCsvIndividualName(params.getCaseData().getApplicant1()); + } + + @Override + public String getApplicantContactNumber(MediationParams params) { + return params.getCaseData().getApplicant1().getPartyPhone(); + } + + @Override + public String getApplicantContactEmail(MediationParams params) { + return params.getCaseData().getApplicant1Email(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipService.java new file mode 100644 index 00000000000..f6d71cf5243 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipService.java @@ -0,0 +1,27 @@ +package uk.gov.hmcts.reform.civil.service.mediation; + +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.civil.model.CaseData; + +@Service +@AllArgsConstructor +public class MediationCSVLipVLipService extends MediationCSVService { + + @Override + protected ApplicantContactDetails getApplicantContactDetails() { + return new LipApplicantContactDetails(); + } + + @Override + protected DefendantContactDetails getDefendantContactDetails() { + return new LipDefendantContactDetails(); + } + + @Override + protected MediationParams getMediationParams(CaseData caseData) { + return MediationParams.builder() + .caseData(caseData) + .build(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCsvServiceFactory.java b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCsvServiceFactory.java index e9ddc527dfd..323361210ee 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCsvServiceFactory.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCsvServiceFactory.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; @Service @RequiredArgsConstructor @@ -10,10 +11,14 @@ public class MediationCsvServiceFactory { private final MediationCSVLrvLrService mediationServiceLrvLr; private final MediationCSVLrvLipService mediationCSVLrvLipService; + private final MediationCSVLipVLipService mediationCSVLipVLipService; + private final FeatureToggleService toggleService; public MediationCSVService getMediationCSVService(CaseData caseData) { - if (caseData.isRespondent1LiP()) { + if (caseData.isRespondent1LiP() && !caseData.isApplicantLiP()) { return mediationCSVLrvLipService; + } else if (caseData.isApplicantLiP() && toggleService.isLipVLipEnabled()) { + return mediationCSVLipVLipService; } return mediationServiceLrvLr; } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipServiceTest.java new file mode 100644 index 00000000000..7b2e7253f24 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVLipVLipServiceTest.java @@ -0,0 +1,166 @@ +package uk.gov.hmcts.reform.civil.service.mediation; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.Party; + +import java.math.BigDecimal; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@SpringBootTest(classes = { + MediationCSVLipVLipService.class +}) +public class MediationCSVLipVLipServiceTest { + + private static final String APPLICANT_COMPANY_NAME = "Applicant company name"; + private static final String APPLICANT_ORGANISATION_NAME = "Applicant organisation name"; + private static final String APPLICANT_EMAIL_ADDRESS = "Applicant@company.com"; + private static final String APPLICANT_PHONE_NUMBER = "7553072111"; + private static final String APPLICANT_INDIVIDUAL_FIST_NAME = "Applicant Individual First Name"; + private static final String APPLICANT_INDIVIDUAL_LAST_NAME = "Applicant Individual Last Name"; + private static final String APPLICANT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME = "Applicant Sole Trader First Name"; + private static final String APPLICANT_INDIVIDUAL_SOLE_TRADER_LAST_NAME = "Applicant Sole Trader Last Name"; + private static final String RESPONDENT_COMPANY_NAME = "Respondent company name"; + private static final String RESPONDENT_ORGANISATION_NAME = "Respondent organisation name"; + private static final String RESPONDENT_EMAIL_ADDRESS = "respondent@company.com"; + private static final String RESPONDENT_PHONE_NUMBER = "0022002200"; + private static final String RESPONDENT_INDIVIDUAL_FIST_NAME = "Respondent Individual First Name"; + private static final String RESPONDENT_INDIVIDUAL_LAST_NAME = "Respondent Individual Last Name"; + private static final String RESPONDENT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME = "Respondent Sole Trader First Name"; + private static final String RESPONDENT_INDIVIDUAL_SOLE_TRADER_LAST_NAME = "Respondent Sole Trader Last Name"; + private static final String TOTAL_AMOUNT = "9000"; + private static final String ID = "123456789"; + private static final String RESPONDENT = "2"; + private static final String APPLICANT = "1"; + + @Autowired + private MediationCSVLipVLipService service; + + @Test + void shouldReturn_properDataForFile_ForIndividual() { + //Given + CaseData caseData = getCaseData(Party.Type.INDIVIDUAL); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_INDIVIDUAL_FIST_NAME + " " + APPLICANT_INDIVIDUAL_LAST_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_INDIVIDUAL_FIST_NAME + " " + RESPONDENT_INDIVIDUAL_LAST_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + @Test + void shouldReturn_properDataForFile_ForCompany() { + //Given + CaseData caseData = getCaseData(Party.Type.COMPANY); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_COMPANY_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_COMPANY_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + @Test + void shouldReturn_properDataForFile_ForOrganisation() { + //Given + CaseData caseData = getCaseData(Party.Type.ORGANISATION); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_ORGANISATION_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_ORGANISATION_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + @Test + void shouldReturn_properDataForFile_ForSoleTrader() { + //Given + CaseData caseData = getCaseData(Party.Type.SOLE_TRADER); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME + " " + APPLICANT_INDIVIDUAL_SOLE_TRADER_LAST_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME + " " + RESPONDENT_INDIVIDUAL_SOLE_TRADER_LAST_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + @Test + void shouldReturn_properDataForFile_ForBilingualFlag() { + //Given + CaseData caseData = getCaseData(Party.Type.SOLE_TRADER); + //When + String result = service.generateCSVContent(caseData); + //Then + assertThat(result).contains(ID); + assertThat(result).contains(APPLICANT); + assertThat(result).contains(APPLICANT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME + " " + APPLICANT_INDIVIDUAL_SOLE_TRADER_LAST_NAME); + assertThat(result).contains(APPLICANT_PHONE_NUMBER); + assertThat(result).contains(APPLICANT_EMAIL_ADDRESS); + assertThat(result).contains(RESPONDENT); + assertThat(result).contains(RESPONDENT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME + " " + RESPONDENT_INDIVIDUAL_SOLE_TRADER_LAST_NAME); + assertThat(result).contains(TOTAL_AMOUNT); + assertThat(result).contains(RESPONDENT_PHONE_NUMBER); + assertThat(result).contains(RESPONDENT_EMAIL_ADDRESS); + } + + private CaseData getCaseData(Party.Type partyType) { + CaseData caseData = CaseData.builder() + .legacyCaseReference(ID) + .totalClaimAmount(new BigDecimal(9000)) + .applicant1(Party.builder() + .type(partyType) + .companyName(APPLICANT_COMPANY_NAME) + .partyPhone(APPLICANT_PHONE_NUMBER) + .partyEmail(APPLICANT_EMAIL_ADDRESS) + .individualFirstName(APPLICANT_INDIVIDUAL_FIST_NAME) + .individualLastName(APPLICANT_INDIVIDUAL_LAST_NAME) + .soleTraderFirstName(APPLICANT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME) + .soleTraderLastName(APPLICANT_INDIVIDUAL_SOLE_TRADER_LAST_NAME) + .organisationName(APPLICANT_ORGANISATION_NAME) + .build()) + .respondent1(Party.builder() + .type(partyType) + .soleTraderFirstName(RESPONDENT_INDIVIDUAL_SOLE_TRADER_FIRST_NAME) + .soleTraderLastName(RESPONDENT_INDIVIDUAL_SOLE_TRADER_LAST_NAME) + .individualFirstName(RESPONDENT_INDIVIDUAL_FIST_NAME) + .individualLastName(RESPONDENT_INDIVIDUAL_LAST_NAME) + .companyName(RESPONDENT_COMPANY_NAME) + .organisationName(RESPONDENT_ORGANISATION_NAME) + .partyPhone(RESPONDENT_PHONE_NUMBER) + .partyEmail(RESPONDENT_EMAIL_ADDRESS) + .build()) + .build(); + return caseData; + } +} \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVServiceFactoryTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVServiceFactoryTest.java index 611e6dfaec8..ccdb35b0156 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVServiceFactoryTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/mediation/MediationCSVServiceFactoryTest.java @@ -6,6 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.OrganisationService; import static org.assertj.core.api.Assertions.assertThat; @@ -14,6 +15,7 @@ @SpringBootTest(classes = { MediationCSVLrvLipService.class, MediationCSVLrvLrService.class, + MediationCSVLipVLipService.class, MediationCsvServiceFactory.class }) public class MediationCSVServiceFactoryTest { @@ -24,6 +26,9 @@ public class MediationCSVServiceFactoryTest { @MockBean private OrganisationService organisationService; + @MockBean + private FeatureToggleService toggleService; + @Autowired private MediationCsvServiceFactory mediationCsvServiceFactory; @@ -46,4 +51,16 @@ void shouldReturnMediationCSVLrvLip_whenDefendantLip() { //Then assertThat(mediationCSVService).isInstanceOf(MediationCSVLrvLipService.class); } + + @Test + void shouldReturnMediationCSVLipVLip_whenApplicantLip() { + //Given + given(toggleService.isLipVLipEnabled()).willReturn(true); + given(caseData.isApplicantLiP()).willReturn(true); + //When + MediationCSVService mediationCSVService = mediationCsvServiceFactory.getMediationCSVService(caseData); + //Then + assertThat(mediationCSVService).isInstanceOf(MediationCSVLipVLipService.class); + } } +