diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateTrialReadyFormHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateTrialReadyFormHandler.java index b3d4a15d761..6791d2db88a 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateTrialReadyFormHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateTrialReadyFormHandler.java @@ -10,7 +10,6 @@ import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; -import uk.gov.hmcts.reform.civil.enums.CaseRole; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.service.docmosis.trialready.TrialReadyFormGenerator; @@ -76,19 +75,10 @@ private CallbackResponse generateClaimForm(CallbackParams callbackParams) { private void buildDocument(CallbackParams callbackParams, CaseData.CaseDataBuilder caseDataBuilder, CaseData caseData) { - String activityID = camundaActivityId(callbackParams); - CaseRole role = switch (activityID) { - case TASK_ID_APPLICANT -> CaseRole.CLAIMANT; - case TASK_ID_RESPONDENT1 -> CaseRole.DEFENDANT; - case TASK_ID_RESPONDENT2 -> CaseRole.RESPONDENTSOLICITORTWO; - default -> null; - }; - CaseDocument caseDocument = trialReadyFormGenerator.generate( callbackParams.getCaseData(), callbackParams.getParams().get(BEARER_TOKEN).toString(), - camundaActivityId(callbackParams), - role + camundaActivityId(callbackParams) ); var documents = caseData.getTrialReadyDocuments(); documents.add(element(caseDocument)); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimCuiCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimCuiCallbackHandler.java index 8743600e72f..b4ce2c6b1b2 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimCuiCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimCuiCallbackHandler.java @@ -72,7 +72,7 @@ private CaseData getUpdatedCaseData(CallbackParams callbackParams) { CaseDocument dummyDocument = new CaseDocument(null, null, null, 0, null, null, null); LocalDateTime responseDate = time.now(); AllocatedTrack allocatedTrack = caseData.getAllocatedTrack(); - return caseData.toBuilder() + CaseData updatedData = caseData.toBuilder() .businessProcess(BusinessProcess.ready(DEFENDANT_RESPONSE_CUI)) .respondent1ResponseDate(responseDate) .respondent1GeneratedResponseDocument(dummyDocument) @@ -82,5 +82,6 @@ private CaseData getUpdatedCaseData(CallbackParams callbackParams) { allocatedTrack )) .build(); + return updatedData; } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandler.java index adf2965ffa2..4bf327728cf 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandler.java @@ -10,10 +10,13 @@ import uk.gov.hmcts.reform.civil.callback.CallbackHandler; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.enums.CaseRole; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; -import uk.gov.hmcts.reform.civil.utils.UserRoleCaching; +import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; +import uk.gov.hmcts.reform.civil.service.UserService; +import uk.gov.hmcts.reform.idam.client.models.UserInfo; import java.time.LocalDate; import java.util.ArrayList; @@ -27,19 +30,15 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_APPLICANT; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_RESPONDENT1; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_RESPONDENT2; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIAL_READINESS; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.APPLICANT_TRIAL_READY_NOTIFY_OTHERS; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_APPLICANT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RESPONDENT1_TRIAL_READY_NOTIFY_OTHERS; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_RESPONDENT1; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RESPONDENT2_TRIAL_READY_NOTIFY_OTHERS; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_RESPONDENT2; import static uk.gov.hmcts.reform.civil.enums.AllocatedTrack.SMALL_CLAIM; import static uk.gov.hmcts.reform.civil.utils.HearingUtils.formatHearingDuration; -import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isLIPClaimant; -import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isApplicantSolicitor; -import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isLIPDefendant; -import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isRespondentSolicitorOne; @Service @RequiredArgsConstructor @@ -55,16 +54,17 @@ public class TrialReadinessCallbackHandler extends CallbackHandler { + "you will need to make an application as soon as possible and pay the appropriate fee."; public static final String NOT_READY_HEADER = "## You have said this case is not ready for trial or hearing"; public static final String NOT_READY_BODY = "### What happens next \n\n" - + "You can view your and other party's trial arrangements in documents in the case details. " - + "If there are any additional changes between now and the hearing date, " - + "you will need to make an application as soon as possible and pay the appropriate fee.\n\n" - + "The trial will go ahead on the specified date " - + "unless a judge makes an order changing the date of the hearing. " - + "If you want the date of the hearing to be changed (or any other order to make the case ready for trial)" - + "you will need to make an application to the court and pay the appropriate fee."; + + "You can view your and other party's trial arrangements in documents in the case details. " + + "If there are any additional changes between now and the hearing date, " + + "you will need to make an application as soon as possible and pay the appropriate fee.\n\n" + + "The trial will go ahead on the specified date " + + "unless a judge makes an order changing the date of the hearing. " + + "If you want the date of the hearing to be changed (or any other order to make the case ready for trial)" + + "you will need to make an application to the court and pay the appropriate fee."; private final ObjectMapper objectMapper; - private final UserRoleCaching userRoleCaching; + private final UserService userService; + private final CoreCaseUserService coreCaseUserService; @Override protected Map callbacks() { @@ -78,17 +78,14 @@ protected Map callbacks() { CallbackResponse populateValues(CallbackParams callbackParams) { var caseData = callbackParams.getCaseData(); CaseData.CaseDataBuilder updatedData = caseData.toBuilder(); - String bearerToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); - String ccdCaseRef = callbackParams.getCaseData().getCcdCaseReference().toString(); - List userRoles = userRoleCaching.getUserRoles(bearerToken, ccdCaseRef); var isApplicant = YesOrNo.NO; var isRespondent1 = YesOrNo.NO; var isRespondent2 = YesOrNo.NO; - if (isApplicantSolicitor(userRoles)) { + if (checkUserRoles(callbackParams, CaseRole.APPLICANTSOLICITORONE)) { isApplicant = YesOrNo.YES; updatedData.hearingDurationTextApplicant(formatHearingDuration(caseData.getHearingDuration())); - } else if (isRespondentSolicitorOne(userRoles)) { + } else if (checkUserRoles(callbackParams, CaseRole.RESPONDENTSOLICITORONE)) { isRespondent1 = YesOrNo.YES; updatedData.hearingDurationTextRespondent1(formatHearingDuration(caseData.getHearingDuration())); } else { @@ -120,17 +117,19 @@ CallbackResponse setBusinessProcess(CallbackParams callbackParams) { var caseData = callbackParams.getCaseData(); CaseData.CaseDataBuilder updatedData = caseData.toBuilder(); - String bearerToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); - String ccdCaseRef = callbackParams.getCaseData().getCcdCaseReference().toString(); - List roles = userRoleCaching.getUserRoles(bearerToken, ccdCaseRef); - - if (isApplicantSolicitor(roles) || isLIPClaimant(roles)) { + if (checkUserRoles(callbackParams, CaseRole.APPLICANTSOLICITORONE) || checkUserRoles( + callbackParams, + CaseRole.CLAIMANT + )) { if (caseData.getTrialReadyApplicant() == YesOrNo.YES) { updatedData.businessProcess(BusinessProcess.ready(APPLICANT_TRIAL_READY_NOTIFY_OTHERS)); } else { updatedData.businessProcess(BusinessProcess.ready(GENERATE_TRIAL_READY_DOCUMENT_APPLICANT)); } - } else if (isRespondentSolicitorOne(roles) || isLIPDefendant(roles)) { + } else if (checkUserRoles(callbackParams, CaseRole.RESPONDENTSOLICITORONE) || checkUserRoles( + callbackParams, + CaseRole.DEFENDANT + )) { if (caseData.getTrialReadyRespondent1() == YesOrNo.YES) { updatedData.businessProcess(BusinessProcess.ready(RESPONDENT1_TRIAL_READY_NOTIFY_OTHERS)); } else { @@ -159,19 +158,23 @@ private SubmittedCallbackResponse buildConfirmation(CallbackParams callbackParam private YesOrNo checkUserReady(CallbackParams callbackParams) { var caseData = callbackParams.getCaseData(); - String bearerToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); - String ccdCaseRef = callbackParams.getCaseData().getCcdCaseReference().toString(); - List userRoles = userRoleCaching.getUserRoles(bearerToken, ccdCaseRef); - if (isApplicantSolicitor(userRoles) || isLIPClaimant(userRoles)) { + if (checkUserRoles(callbackParams, CaseRole.APPLICANTSOLICITORONE)) { return caseData.getTrialReadyApplicant(); - } else if (isRespondentSolicitorOne(userRoles) || isLIPDefendant(userRoles)) { + } else if (checkUserRoles(callbackParams, CaseRole.RESPONDENTSOLICITORONE)) { return caseData.getTrialReadyRespondent1(); } else { return caseData.getTrialReadyRespondent2(); } } + private boolean checkUserRoles(CallbackParams callbackParams, CaseRole userRole) { + UserInfo userInfo = userService.getUserInfo(callbackParams.getParams().get(BEARER_TOKEN).toString()); + return coreCaseUserService.userHasCaseRole(callbackParams.getCaseData().getCcdCaseReference().toString(), + userInfo.getUid(), userRole + ); + } + @Override public List handledEvents() { return EVENTS; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/trialready/TrialReadyFormGenerator.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/trialready/TrialReadyFormGenerator.java index 14f3e63284c..d6ea12ae165 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/trialready/TrialReadyFormGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/trialready/TrialReadyFormGenerator.java @@ -7,7 +7,6 @@ import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF; -import uk.gov.hmcts.reform.civil.enums.CaseRole; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Party; @@ -36,12 +35,12 @@ public class TrialReadyFormGenerator { private static final String TASK_ID_APPLICANT = "GenerateTrialReadyFormApplicant"; private static final String TASK_ID_RESPONDENT1 = "GenerateTrialReadyFormRespondent1"; - public CaseDocument generate(CaseData caseData, String authorisation, String camundaActivity, CaseRole userRole) { + public CaseDocument generate(CaseData caseData, String authorisation, String camundaActivity) { TrialReadyForm templateData = getTemplateData(caseData, camundaActivity); DocmosisTemplates template = TRIAL_READY; DocmosisDocument document = documentGeneratorService.generateDocmosisDocument(templateData, template); - CaseDocument trialReadyDocument = documentManagementService.uploadDocument( + return documentManagementService.uploadDocument( authorisation, new PDF( getFileName(caseData, template, camundaActivity), @@ -49,8 +48,6 @@ public CaseDocument generate(CaseData caseData, String authorisation, String cam DocumentType.TRIAL_READY_DOCUMENT ) ); - - return trialReadyDocument.toBuilder().ownedBy(userRole).build(); } private TrialReadyForm getTemplateData(CaseData caseData, String camundaActivity) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/UserRoleUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/UserRoleUtils.java index 4b726af23b2..1069133fcdd 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/UserRoleUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/UserRoleUtils.java @@ -6,8 +6,6 @@ import static uk.gov.hmcts.reform.civil.enums.CaseRole.APPLICANTSOLICITORONE; import static uk.gov.hmcts.reform.civil.enums.CaseRole.RESPONDENTSOLICITORONE; import static uk.gov.hmcts.reform.civil.enums.CaseRole.RESPONDENTSOLICITORTWO; -import static uk.gov.hmcts.reform.civil.enums.CaseRole.CLAIMANT; -import static uk.gov.hmcts.reform.civil.enums.CaseRole.DEFENDANT; public class UserRoleUtils { @@ -27,14 +25,6 @@ public static boolean isRespondentSolicitorTwo(List roles) { return hasRole(roles, RESPONDENTSOLICITORTWO); } - public static boolean isLIPClaimant(List roles) { - return hasRole(roles, CLAIMANT); - } - - public static boolean isLIPDefendant(List roles) { - return hasRole(roles, DEFENDANT); - } - private static boolean hasRole(List roles, CaseRole role) { return roles.stream().anyMatch(role.getFormattedName()::contains); } 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 56556078d48..15d5bdb1772 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 @@ -13,7 +13,6 @@ 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; @@ -69,10 +68,9 @@ public void shouldGenerateForm_when1v1() { .documentFileName("file-name") .documentBinaryUrl("binary-url") .build()) - .ownedBy(CaseRole.CLAIMANT) .build(); - when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString(), any(CaseRole.class))).thenReturn(document); + when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString())).thenReturn(document); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); params.getRequest().setEventId(GENERATE_TRIAL_READY_FORM_APPLICANT.name()); @@ -80,10 +78,10 @@ public void shouldGenerateForm_when1v1() { var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); // Then verify(trialReadyFormGenerator).generate( - any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormApplicant"), eq(CaseRole.CLAIMANT)); + any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormApplicant")); CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); - assertThat(updatedData.getTrialReadyDocuments()).hasSize(1); + assertThat(updatedData.getTrialReadyDocuments().size()).isEqualTo(1); } @@ -101,10 +99,9 @@ public void shouldGenerateForm_when1v1AndRespondent1() { .documentFileName("file-name") .documentBinaryUrl("binary-url") .build()) - .ownedBy(CaseRole.DEFENDANT) .build(); - when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString(), any(CaseRole.class))).thenReturn(document); + when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString())).thenReturn(document); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); params.getRequest().setEventId(GENERATE_TRIAL_READY_FORM_RESPONDENT1.name()); @@ -112,10 +109,10 @@ public void shouldGenerateForm_when1v1AndRespondent1() { var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); // Then verify(trialReadyFormGenerator).generate( - any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormRespondent1"), eq(CaseRole.DEFENDANT)); + any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormRespondent1")); CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); - assertThat(updatedData.getTrialReadyDocuments()).hasSize(1); + assertThat(updatedData.getTrialReadyDocuments().size()).isEqualTo(1); } @@ -133,12 +130,11 @@ public void shouldGenerateForm_when1v2AndOneSeveralPartiesGeneratesDocument() { .documentFileName("file-name") .documentBinaryUrl("binary-url") .build()) - .ownedBy(CaseRole.RESPONDENTSOLICITORTWO) .build(); List> systemGeneratedCaseDocuments = new ArrayList<>(); systemGeneratedCaseDocuments.add(element(document)); - when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString(), any(CaseRole.class))).thenReturn(document); + when(trialReadyFormGenerator.generate(any(CaseData.class), anyString(), anyString())).thenReturn(document); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() .trialReadyDocuments(systemGeneratedCaseDocuments).build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -147,10 +143,10 @@ public void shouldGenerateForm_when1v2AndOneSeveralPartiesGeneratesDocument() { var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); // Then verify(trialReadyFormGenerator).generate( - any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormRespondent2"), eq(CaseRole.RESPONDENTSOLICITORTWO)); + any(CaseData.class), eq("BEARER_TOKEN"), eq("GenerateTrialReadyFormRespondent2")); CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); - assertThat(updatedData.getTrialReadyDocuments()).hasSize(2); + assertThat(updatedData.getTrialReadyDocuments().size()).isEqualTo(2); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandlerTest.java index d55977b7deb..1d4f4769e51 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandlerTest.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.civil.handler.callback.user; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -19,14 +20,14 @@ import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; -import uk.gov.hmcts.reform.civil.utils.UserRoleCaching; +import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; import uk.gov.hmcts.reform.idam.client.models.UserInfo; import java.time.LocalDate; -import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; @@ -37,13 +38,14 @@ TrialReadinessCallbackHandler.class, JacksonAutoConfiguration.class }) + public class TrialReadinessCallbackHandlerTest extends BaseCallbackHandlerTest { @Autowired private TrialReadinessCallbackHandler handler; @MockBean - private UserRoleCaching userRoleCaching; + private CoreCaseUserService coreCaseUserService; public static final String READY_HEADER = "## You have said this case is ready for trial or hearing"; public static final String READY_BODY = "### What happens next \n\n" @@ -67,19 +69,18 @@ public void setup() { @Nested class AboutToStartCallback { - @Test void shouldNotReturnError_WhenAboutToStartIsInvoked_ApplicantSolicitor() { //given: applicant solicitor logs in more than 3 weeks before hearing CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.APPLICANTSOLICITORONE.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.APPLICANTSOLICITORONE))) + .thenReturn(true); //when: Event is started AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - //then: no error is given assertThat(response.getErrors()).isEmpty(); } @@ -89,13 +90,13 @@ void shouldNotReturnError_WhenAboutToStartIsInvoked_RespondentSolicitor1() { //given: respondent 1 solicitor logs in more than 3 weeks before hearing CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORONE.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORONE))) + .thenReturn(true); //when: Event is started AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - //then: no error is given assertThat(response.getErrors()).isEmpty(); } @@ -105,13 +106,13 @@ void shouldNotReturnError_WhenAboutToStartIsInvoked_RespondentSolicitor2() { //given: respondent 2 solicitor logs in more than 3 weeks before hearing CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORTWO))) + .thenReturn(true); //when: Event is started AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - //then: no error is given assertThat(response.getErrors()).isEmpty(); } @@ -122,13 +123,13 @@ void shouldReturnError_WhenAboutToStartIsInvokedWithinThreeWeeksOfHearingDate_Ap CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck() .hearingDate(LocalDate.now().plusWeeks(2).plusDays(6)).build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.APPLICANTSOLICITORONE.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.APPLICANTSOLICITORONE))) + .thenReturn(true); //when: Event is started AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - //then: an error is returned assertThat(response.getErrors()).isNotEmpty(); } @@ -139,13 +140,13 @@ void shouldReturnError_WhenAboutToStartIsInvokedWithinThreeWeeksOfHearingDate_Re CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck() .hearingDate(LocalDate.now().plusWeeks(2).plusDays(6)).build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORONE.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORONE))) + .thenReturn(true); //when: Event is started AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - //then: an error is returned assertThat(response.getErrors()).isNotEmpty(); } @@ -156,13 +157,13 @@ void shouldReturnError_WhenAboutToStartIsInvokedWithinThreeWeeksOfHearingDate_Re CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck() .hearingDate(LocalDate.now().plusWeeks(2).plusDays(6)).build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORTWO))) + .thenReturn(true); //when: Event is started AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - //then: an error is returned assertThat(response.getErrors()).isNotEmpty(); } @@ -170,30 +171,14 @@ void shouldReturnError_WhenAboutToStartIsInvokedWithinThreeWeeksOfHearingDate_Re @Nested class AboutToSubmitCallback { - @Test void shouldTriggerApplicantNotifyOthers_WhenAboutToSubmitIsInvoked_ApplicantSolicitor() { CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build().toBuilder() .trialReadyApplicant(YesOrNo.YES).build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.APPLICANTSOLICITORONE.getFormattedName())); - - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertThat(response.getErrors()).isNull(); - assertThat(response.getData()).extracting("businessProcess") - .extracting("camundaEvent", "status") - .containsOnly(CaseEvent.APPLICANT_TRIAL_READY_NOTIFY_OTHERS.name(), "READY"); - } - - @Test - void shouldTriggerApplicantNotifyOthers_WhenAboutToSubmitIsInvoked_Claimant() { - CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build().toBuilder() - .trialReadyApplicant(YesOrNo.YES).build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.CLAIMANT.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.APPLICANTSOLICITORONE))) + .thenReturn(true); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -201,7 +186,6 @@ void shouldTriggerApplicantNotifyOthers_WhenAboutToSubmitIsInvoked_Claimant() { assertThat(response.getData()).extracting("businessProcess") .extracting("camundaEvent", "status") .containsOnly(CaseEvent.APPLICANT_TRIAL_READY_NOTIFY_OTHERS.name(), "READY"); - } @Test @@ -209,25 +193,11 @@ void shouldTriggerRespondent1NotifyOthers_WhenAboutToSubmitIsInvoked_Respondent1 CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build().toBuilder() .trialReadyRespondent1(YesOrNo.YES).build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORONE.getFormattedName())); - - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - assertThat(response.getErrors()).isNull(); - assertThat(response.getData()).extracting("businessProcess") - .extracting("camundaEvent", "status") - .containsOnly(CaseEvent.RESPONDENT1_TRIAL_READY_NOTIFY_OTHERS.name(), "READY"); - - } - - @Test - void shouldTriggerRespondent1NotifyOthers_WhenAboutToSubmitIsInvoked_Defendant() { - CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build().toBuilder() - .trialReadyRespondent1(YesOrNo.YES).build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.DEFENDANT.getFormattedName())); + ObjectMapper objectmapper = new ObjectMapper(); + CaseData.CaseDataBuilder updatedData = caseData.toBuilder(); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORONE))) + .thenReturn(true); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -235,7 +205,6 @@ void shouldTriggerRespondent1NotifyOthers_WhenAboutToSubmitIsInvoked_Defendant() assertThat(response.getData()).extracting("businessProcess") .extracting("camundaEvent", "status") .containsOnly(CaseEvent.RESPONDENT1_TRIAL_READY_NOTIFY_OTHERS.name(), "READY"); - } @Test @@ -243,8 +212,11 @@ void shouldTriggerRespondent2NotifyOthers_WhenAboutToSubmitIsInvoked_Respondent2 CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build().toBuilder() .trialReadyRespondent2(YesOrNo.YES).build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName())); + ObjectMapper objectmapper = new ObjectMapper(); + CaseData.CaseDataBuilder updatedData = caseData.toBuilder(); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORTWO))) + .thenReturn(true); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -259,8 +231,9 @@ void shouldTriggerApplicantDocument_WhenAboutToSubmitIsInvoked_ApplicantSolicito CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build().toBuilder() .trialReadyApplicant(YesOrNo.NO).build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.APPLICANTSOLICITORONE.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.APPLICANTSOLICITORONE))) + .thenReturn(true); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -268,7 +241,6 @@ void shouldTriggerApplicantDocument_WhenAboutToSubmitIsInvoked_ApplicantSolicito assertThat(response.getData()).extracting("businessProcess") .extracting("camundaEvent", "status") .containsOnly(CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_APPLICANT.name(), "READY"); - } @Test @@ -276,8 +248,11 @@ void shouldTriggerRespondent1Document_WhenAboutToSubmitIsInvoked_Respondent1Soli CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build().toBuilder() .trialReadyRespondent1(YesOrNo.NO).build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORONE.getFormattedName())); + ObjectMapper objectmapper = new ObjectMapper(); + CaseData.CaseDataBuilder updatedData = caseData.toBuilder(); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORONE))) + .thenReturn(true); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -285,7 +260,6 @@ void shouldTriggerRespondent1Document_WhenAboutToSubmitIsInvoked_Respondent1Soli assertThat(response.getData()).extracting("businessProcess") .extracting("camundaEvent", "status") .containsOnly(CaseEvent.GENERATE_TRIAL_READY_DOCUMENT_RESPONDENT1.name(), "READY"); - } @Test @@ -293,8 +267,11 @@ void shouldTriggerRespondent2Document_WhenAboutToSubmitIsInvoked_Respondent2Soli CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyCheck().build().toBuilder() .trialReadyRespondent2(YesOrNo.NO).build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName())); + ObjectMapper objectmapper = new ObjectMapper(); + CaseData.CaseDataBuilder updatedData = caseData.toBuilder(); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORTWO))) + .thenReturn(true); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); @@ -307,38 +284,17 @@ void shouldTriggerRespondent2Document_WhenAboutToSubmitIsInvoked_Respondent2Soli @Nested class SubmittedCallback { - @Test void shouldReturnConfirmationScreen_when1v1ReadySubmitted_ApplicantSolicitor() { //given: applicant solicitor selects Ready CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyApplicant().build(); CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.APPLICANTSOLICITORONE.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.APPLICANTSOLICITORONE))) + .thenReturn(true); //when: Event is submitted SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - - //then: header + body for the ready status get used in the confirmation - assertThat(response).usingRecursiveComparison().isEqualTo( - SubmittedCallbackResponse.builder() - .confirmationHeader(READY_HEADER) - .confirmationBody(READY_BODY) - .build() - ); - } - - @Test - void shouldReturnConfirmationScreen_when1v1ReadySubmitted_Claimant() { - //given: claimant selects Ready - CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyApplicant().build(); - CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.CLAIMANT.getFormattedName())); - - //when: Event is submitted - SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - //then: header + body for the ready status get used in the confirmation assertThat(response).usingRecursiveComparison().isEqualTo( SubmittedCallbackResponse.builder() @@ -353,32 +309,12 @@ void shouldReturnConfirmationScreen_when1v1NotReadySubmitted_ApplicantSolicitor( //given: applicant solicitor selects Not Ready CaseData caseData = CaseDataBuilder.builder().atStateTrialNotReadyApplicant().build(); CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.APPLICANTSOLICITORONE.getFormattedName())); - - //when: Event is submitted - SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - - //then: header + body for the not ready status get used in the confirmation - assertThat(response).usingRecursiveComparison().isEqualTo( - SubmittedCallbackResponse.builder() - .confirmationHeader(NOT_READY_HEADER) - .confirmationBody(NOT_READY_BODY) - .build() - ); - } - - @Test - void shouldReturnConfirmationScreen_when1v1NotReadySubmitted_Claimant() { - //given: claimant selects Not Ready - CaseData caseData = CaseDataBuilder.builder().atStateTrialNotReadyApplicant().build(); - CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.CLAIMANT.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.APPLICANTSOLICITORONE))) + .thenReturn(true); //when: Event is submitted SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - //then: header + body for the not ready status get used in the confirmation assertThat(response).usingRecursiveComparison().isEqualTo( SubmittedCallbackResponse.builder() @@ -393,32 +329,12 @@ void shouldReturnConfirmationScreen_when1v1ReadySubmitted_Respondent1Solicitor() //given: respondent 1 solicitor selects Ready CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyRespondent1().build(); CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORONE.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORONE))) + .thenReturn(true); //when: Event is submitted SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - - //then: header + body for the ready status get used in the confirmation - assertThat(response).usingRecursiveComparison().isEqualTo( - SubmittedCallbackResponse.builder() - .confirmationHeader(READY_HEADER) - .confirmationBody(READY_BODY) - .build() - ); - } - - @Test - void shouldReturnConfirmationScreen_when1v1ReadySubmitted_Defendant() { - //given: defendant selects Ready - CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyRespondent1().build(); - CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.DEFENDANT.getFormattedName())); - - //when: Event is submitted - SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - //then: header + body for the ready status get used in the confirmation assertThat(response).usingRecursiveComparison().isEqualTo( SubmittedCallbackResponse.builder() @@ -433,32 +349,12 @@ void shouldReturnConfirmationScreen_when1v1NotReadySubmitted_Respondent1Solicito //given: respondent 1 solicitor selects Not Ready CaseData caseData = CaseDataBuilder.builder().atStateTrialNotReadyRespondent1().build(); CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORONE.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORONE))) + .thenReturn(true); //when: Event is submitted SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - - //then: header + body for the not ready status get used in the confirmation - assertThat(response).usingRecursiveComparison().isEqualTo( - SubmittedCallbackResponse.builder() - .confirmationHeader(NOT_READY_HEADER) - .confirmationBody(NOT_READY_BODY) - .build() - ); - } - - @Test - void shouldReturnConfirmationScreen_when1v1NotReadySubmitted_Defendant() { - //given: defendant selects Not Ready - CaseData caseData = CaseDataBuilder.builder().atStateTrialNotReadyRespondent1().build(); - CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.DEFENDANT.getFormattedName())); - - //when: Event is submitted - SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - //then: header + body for the not ready status get used in the confirmation assertThat(response).usingRecursiveComparison().isEqualTo( SubmittedCallbackResponse.builder() @@ -473,12 +369,12 @@ void shouldReturnConfirmationScreen_when1v1ReadySubmitted_Respondent2Solicitor() //given: Respondent 2 selects Ready CaseData caseData = CaseDataBuilder.builder().atStateTrialReadyRespondent2().build(); CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORTWO))) + .thenReturn(true); //when: Event is submitted SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - //then: head + body for ready status are used in confirmation assertThat(response).usingRecursiveComparison().isEqualTo( SubmittedCallbackResponse.builder() @@ -493,12 +389,12 @@ void shouldReturnConfirmationScreen_when1v1NotReadySubmitted_Respondent2Solicito //given: Respondent 2 solicitor selects Not Ready CaseData caseData = CaseDataBuilder.builder().atStateTrialNotReadyRespondent2().build(); CallbackParams params = CallbackParamsBuilder.builder().of(SUBMITTED, caseData).build(); - when(userRoleCaching.getUserRoles(anyString(), anyString())) - .thenReturn(List.of(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName())); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), eq(CaseRole.RESPONDENTSOLICITORTWO))) + .thenReturn(true); //when: Event is submitted SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - //then: head + body for not ready status are used in confirmation assertThat(response).usingRecursiveComparison().isEqualTo( SubmittedCallbackResponse.builder() diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/trialready/TrialReadyFormGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/trialready/TrialReadyFormGeneratorTest.java index 9f15389e4e1..44fda5b3c12 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/trialready/TrialReadyFormGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/trialready/TrialReadyFormGeneratorTest.java @@ -10,7 +10,6 @@ import uk.gov.hmcts.reform.civil.documentmanagement.UnsecuredDocumentManagementService; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF; -import uk.gov.hmcts.reform.civil.enums.CaseRole; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Party; @@ -38,6 +37,7 @@ TrialReadyFormGenerator.class, JacksonAutoConfiguration.class }) + public class TrialReadyFormGeneratorTest { private static final String BEARER_TOKEN = "Bearer Token"; @@ -48,13 +48,10 @@ public class TrialReadyFormGeneratorTest { .documentName(fileName_application) .documentType(TRIAL_READY_DOCUMENT) .build(); - @MockBean private UnsecuredDocumentManagementService documentManagementService; - @MockBean private DocumentGeneratorService documentGeneratorService; - @Autowired private TrialReadyFormGenerator generator; @@ -73,14 +70,12 @@ void shouldTrialReadyFormGeneratorOneForm_whenValidDataIsProvided() { .revisedHearingRequirements(YesOrNo.YES) .revisedHearingComments("Revised Hearing Comments").build()).build(); // When - CaseDocument caseDocument = generator.generate(caseData, BEARER_TOKEN, "GenerateTrialReadyFormApplicant", CaseRole.APPLICANTSOLICITORONE); + CaseDocument caseDocument = generator.generate(caseData, BEARER_TOKEN, "GenerateTrialReadyFormApplicant"); // Then assertThat(caseDocument).isNotNull(); - assertThat(caseDocument.getOwnedBy()).isEqualTo(CaseRole.APPLICANTSOLICITORONE); verify(documentManagementService) .uploadDocument(BEARER_TOKEN, new PDF(fileName_application, bytes, TRIAL_READY_DOCUMENT)); - assertThat(caseDocument.getOwnedBy()).isEqualTo(CaseRole.APPLICANTSOLICITORONE); } @Test @@ -100,10 +95,9 @@ void shouldTrialReadyFormGeneratorOneForm_whenRespondent1GenerateDocs() { .revisedHearingRequirements(YesOrNo.YES) .revisedHearingComments("Revised Hearing Comments").build()).build(); // When - CaseDocument caseDocument = generator.generate(caseData, BEARER_TOKEN, "GenerateTrialReadyFormRespondent1", CaseRole.RESPONDENTSOLICITORONE); + CaseDocument caseDocument = generator.generate(caseData, BEARER_TOKEN, "GenerateTrialReadyFormRespondent1"); // Then assertThat(caseDocument).isNotNull(); - assertThat(caseDocument.getOwnedBy()).isEqualTo(CaseRole.RESPONDENTSOLICITORONE); verify(documentManagementService) .uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, TRIAL_READY_DOCUMENT)); @@ -127,10 +121,9 @@ void shouldTrialReadyFormGeneratorOneForm_whenRespondent2GenerateDocs() { .revisedHearingRequirements(YesOrNo.YES) .revisedHearingComments("Revised Hearing Comments").build()).build(); // When - CaseDocument caseDocument = generator.generate(caseData, BEARER_TOKEN, "GenerateTrialReadyFormRespondent2", CaseRole.RESPONDENTSOLICITORTWO); + CaseDocument caseDocument = generator.generate(caseData, BEARER_TOKEN, "GenerateTrialReadyFormRespondent2"); // Then assertThat(caseDocument).isNotNull(); - assertThat(caseDocument.getOwnedBy()).isEqualTo(CaseRole.RESPONDENTSOLICITORTWO); verify(documentManagementService) .uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, TRIAL_READY_DOCUMENT)); @@ -154,10 +147,9 @@ void shouldTrialReadyFormGeneratorOneForm_whenRespondent2OrganisationGenerateDoc .revisedHearingRequirements(YesOrNo.NO) .revisedHearingComments("Revised Hearing Comments").build()).build(); // When - CaseDocument caseDocument = generator.generate(caseData, BEARER_TOKEN, "GenerateTrialReadyFormRespondent2", CaseRole.RESPONDENTSOLICITORTWO); + CaseDocument caseDocument = generator.generate(caseData, BEARER_TOKEN, "GenerateTrialReadyFormRespondent2"); // Then assertThat(caseDocument).isNotNull(); - assertThat(caseDocument.getOwnedBy()).isEqualTo(CaseRole.RESPONDENTSOLICITORTWO); verify(documentManagementService) .uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, TRIAL_READY_DOCUMENT)); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/UserRoleCachingTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/UserRoleCachingTest.java deleted file mode 100644 index 5cc1996c1cf..00000000000 --- a/src/test/java/uk/gov/hmcts/reform/civil/utils/UserRoleCachingTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package uk.gov.hmcts.reform.civil.utils; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; -import uk.gov.hmcts.reform.civil.service.UserService; -import uk.gov.hmcts.reform.idam.client.models.UserInfo; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - -@SpringBootTest(classes = { - UserRoleCaching.class, - CoreCaseUserService.class, - UserService.class -}) -public class UserRoleCachingTest { - - @MockBean - private CoreCaseUserService coreCaseUserService; - @MockBean - private UserService userService; - @Autowired - private UserRoleCaching userRoleCaching; - - @Test - void getUserRolesTest() { - List caseRoles = new ArrayList<>(); - caseRoles.add("[APPLICANTSOLICITORONE]"); - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(coreCaseUserService.getUserCaseRoles(anyString(), anyString())).thenReturn(caseRoles); - assertThat(userRoleCaching.getUserRoles("bearerToken", "ccdcase")) - .contains("[APPLICANTSOLICITORONE]"); - } - -}