-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CIV-7829 Notify successful payment claimant Lip (#3741)
* CIV-7829 add notification service * CIV-7829 update test * CIV-7829 camunda changes * CIV-7829 camunda changes * CIV-7829 Test cases * CIV-7829 white space issue * CIV-7829 fixing build failure * CIV-7829 fixing build failure --------- Co-authored-by: kannan-v-hmcts <[email protected]> Co-authored-by: VijayaKumarK <[email protected]> Co-authored-by: m-meulendijks-v1 <[email protected]> Co-authored-by: marianadpereira <[email protected]>
- Loading branch information
1 parent
e10f2c9
commit 7acdac0
Showing
6 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...m/civil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; | ||
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; | ||
import uk.gov.hmcts.reform.civil.callback.Callback; | ||
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.model.CaseData; | ||
import uk.gov.hmcts.reform.civil.notify.NotificationService; | ||
import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; | ||
import uk.gov.hmcts.reform.civil.utils.PartyUtils; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; | ||
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_APPLICANT1_GENERIC_TEMPLATE; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class NotifyApplicant1GenericTemplateHandler extends CallbackHandler implements NotificationData { | ||
|
||
public static final String TASK_ID = "NotifyApplicant1GenericTemplate"; | ||
private static final String REFERENCE_TEMPLATE = | ||
"generic-notification-lip-%s"; | ||
private final NotificationService notificationService; | ||
private final NotificationsProperties notificationsProperties; | ||
private static final List<CaseEvent> EVENTS = List.of( | ||
NOTIFY_APPLICANT1_GENERIC_TEMPLATE | ||
); | ||
|
||
@Override | ||
protected Map<String, Callback> callbacks() { | ||
return Map.of( | ||
callbackKey(ABOUT_TO_SUBMIT), this::sendGenericNotificationLip | ||
); | ||
} | ||
|
||
@Override | ||
public String camundaActivityId(CallbackParams callbackParams) { | ||
return TASK_ID; | ||
} | ||
|
||
@Override | ||
public List<CaseEvent> handledEvents() { | ||
return EVENTS; | ||
} | ||
|
||
public CallbackResponse sendGenericNotificationLip(CallbackParams callbackParams) { | ||
CaseData caseData = callbackParams.getCaseData(); | ||
notificationService.sendMail( | ||
getRecipientEmail(caseData), | ||
getNotificationTemplate(), | ||
addProperties(caseData), | ||
String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference()) | ||
); | ||
return AboutToStartOrSubmitCallbackResponse.builder().build(); | ||
} | ||
|
||
public Map<String, String> addProperties(CaseData caseData) { | ||
return Map.of( | ||
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), | ||
PARTY_NAME, caseData.getApplicant1().getPartyName(), | ||
CLAIMANT_V_DEFENDANT, PartyUtils.getAllPartyNames(caseData) | ||
); | ||
} | ||
|
||
private String getNotificationTemplate() { | ||
return notificationsProperties.getNotifyLipUpdateTemplate(); | ||
} | ||
|
||
private String getRecipientEmail(CaseData caseData) { | ||
return caseData.getClaimantUserDetails().getEmail(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...vil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import uk.gov.hmcts.reform.civil.callback.CallbackParams; | ||
import uk.gov.hmcts.reform.civil.model.CaseData; | ||
import uk.gov.hmcts.reform.civil.model.IdamUserDetails; | ||
import uk.gov.hmcts.reform.civil.model.Party; | ||
import uk.gov.hmcts.reform.civil.notify.NotificationService; | ||
import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; | ||
import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; | ||
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; | ||
|
||
import java.util.Map; | ||
|
||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; | ||
import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; | ||
import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.PARTY_NAME; | ||
import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIMANT_V_DEFENDANT; | ||
|
||
@SpringBootTest(classes = { | ||
NotifyApplicant1GenericTemplateHandler.class, | ||
JacksonAutoConfiguration.class | ||
}) | ||
class NotifyApplicant1GenericTemplateHandlerTest { | ||
|
||
public static final String TEMPLATE_ID = "template-id"; | ||
|
||
@MockBean | ||
private NotificationService notificationService; | ||
@MockBean | ||
private NotificationsProperties notificationsProperties; | ||
@Autowired | ||
NotifyApplicant1GenericTemplateHandler handler; | ||
|
||
@BeforeEach | ||
void setup() { | ||
when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn( | ||
TEMPLATE_ID); | ||
} | ||
|
||
@Test | ||
void shouldSendGenericEmailWhenAllDataIsCorrect() { | ||
|
||
CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified() | ||
.claimantUserDetails(IdamUserDetails.builder().email("[email protected]").build()) | ||
.applicant1(Party.builder().individualFirstName("John").individualLastName("Doe") | ||
.type(Party.Type.INDIVIDUAL).build()) | ||
.respondent1(Party.builder().individualFirstName("Jack").individualLastName("Jackson") | ||
.type(Party.Type.INDIVIDUAL).build()).build(); | ||
|
||
CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).build(); | ||
|
||
handler.handle(params); | ||
|
||
verify(notificationService).sendMail( | ||
"[email protected]", | ||
TEMPLATE_ID, | ||
getNotificationDataMap(caseData), | ||
"generic-notification-lip-000DC001" | ||
); | ||
|
||
} | ||
|
||
private Map<String, String> getNotificationDataMap(CaseData caseData) { | ||
return Map.of( | ||
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), | ||
PARTY_NAME, "John Doe", | ||
CLAIMANT_V_DEFENDANT, "John Doe V Jack Jackson" | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters