use of org.hisp.dhis.outboundmessage.BatchResponseStatus in project dhis2-core by dhis2.
the class ProgramNotificationServiceTest method testDataElementRecipientWithEmail.
@Test
void testDataElementRecipientWithEmail() {
when(programStageInstanceStore.get(anyLong())).thenReturn(programStageInstances.iterator().next());
when(programMessageService.sendMessages(anyList())).thenAnswer(invocation -> {
sentProgramMessages.addAll((List<ProgramMessage>) invocation.getArguments()[0]);
return new BatchResponseStatus(Collections.emptyList());
});
when(programStageNotificationRenderer.render(any(ProgramStageInstance.class), any(NotificationTemplate.class))).thenReturn(notificationMessage);
programNotificationTemplate.setNotificationRecipient(ProgramNotificationRecipient.DATA_ELEMENT);
programNotificationTemplate.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.EMAIL));
programNotificationTemplate.setRecipientDataElement(dataElementEmail);
programNotificationTemplate.setNotificationTrigger(NotificationTrigger.COMPLETION);
ProgramStageInstance programStageInstance = programStageInstances.iterator().next();
programNotificationService.sendEventCompletionNotifications(programStageInstance.getId());
// no message when no template is attached
assertEquals(0, sentProgramMessages.size());
programStageInstance.getProgramStage().getNotificationTemplates().add(programNotificationTemplate);
programNotificationService.sendEventCompletionNotifications(programStageInstance.getId());
assertEquals(1, sentProgramMessages.size());
}
use of org.hisp.dhis.outboundmessage.BatchResponseStatus in project dhis2-core by dhis2.
the class ProgramNotificationServiceTest method testSendCompletionNotification.
@Test
void testSendCompletionNotification() {
when(programInstanceStore.get(anyLong())).thenReturn(programInstances.iterator().next());
when(programMessageService.sendMessages(anyList())).thenAnswer(invocation -> {
sentProgramMessages.addAll((List<ProgramMessage>) invocation.getArguments()[0]);
return new BatchResponseStatus(Collections.emptyList());
});
when(programNotificationRenderer.render(any(ProgramInstance.class), any(NotificationTemplate.class))).thenReturn(notificationMessage);
programNotificationTemplate.setNotificationTrigger(NotificationTrigger.COMPLETION);
programNotificationService.sendEnrollmentCompletionNotifications(programInstances.iterator().next().getId());
assertEquals(1, sentProgramMessages.size());
ProgramMessage programMessage = sentProgramMessages.iterator().next();
assertEquals(TrackedEntityInstance.class, programMessage.getRecipients().getTrackedEntityInstance().getClass());
assertEquals(tei, programMessage.getRecipients().getTrackedEntityInstance());
}
use of org.hisp.dhis.outboundmessage.BatchResponseStatus in project dhis2-core by dhis2.
the class ProgramNotificationServiceTest method testProgramAttributeRecipientWithSMS.
@Test
void testProgramAttributeRecipientWithSMS() {
when(programInstanceStore.get(anyLong())).thenReturn(programInstances.iterator().next());
when(programMessageService.sendMessages(anyList())).thenAnswer(invocation -> {
sentProgramMessages.addAll((List<ProgramMessage>) invocation.getArguments()[0]);
return new BatchResponseStatus(Collections.emptyList());
});
when(programNotificationRenderer.render(any(ProgramInstance.class), any(NotificationTemplate.class))).thenReturn(notificationMessage);
programNotificationTemplate.setNotificationRecipient(ProgramNotificationRecipient.PROGRAM_ATTRIBUTE);
programNotificationTemplate.setRecipientProgramAttribute(trackedEntityAttribute);
programNotificationTemplate.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.SMS));
programNotificationService.sendEnrollmentNotifications(programInstances.iterator().next().getId());
assertEquals(1, sentProgramMessages.size());
ProgramMessage programMessage = sentProgramMessages.iterator().next();
assertTrue(programMessage.getRecipients().getPhoneNumbers().contains(ATT_PHONE_NUMBER));
assertTrue(programMessage.getDeliveryChannels().contains(DeliveryChannel.SMS));
assertEquals(programMessage.getNotificationTemplate(), notificationTemplate);
}
use of org.hisp.dhis.outboundmessage.BatchResponseStatus in project dhis2-core by dhis2.
the class ProgramNotificationServiceTest method testDataElementRecipientWithSMS.
@Test
void testDataElementRecipientWithSMS() {
when(programStageInstanceStore.get(anyLong())).thenReturn(programStageInstances.iterator().next());
when(programMessageService.sendMessages(anyList())).thenAnswer(invocation -> {
sentProgramMessages.addAll((List<ProgramMessage>) invocation.getArguments()[0]);
return new BatchResponseStatus(Collections.emptyList());
});
when(programStageNotificationRenderer.render(any(ProgramStageInstance.class), any(NotificationTemplate.class))).thenReturn(notificationMessage);
programNotificationTemplate.setNotificationRecipient(ProgramNotificationRecipient.DATA_ELEMENT);
programNotificationTemplate.setDeliveryChannels(Sets.newHashSet(DeliveryChannel.SMS));
programNotificationTemplate.setRecipientDataElement(dataElement);
programNotificationTemplate.setNotificationTrigger(NotificationTrigger.COMPLETION);
ProgramStageInstance programStageInstance = programStageInstances.iterator().next();
programNotificationService.sendEventCompletionNotifications(programStageInstance.getId());
// no message when no template is attached
assertEquals(0, sentProgramMessages.size());
programStageInstance.getProgramStage().getNotificationTemplates().add(programNotificationTemplate);
programNotificationService.sendEventCompletionNotifications(programStageInstance.getId());
assertEquals(1, sentProgramMessages.size());
}
use of org.hisp.dhis.outboundmessage.BatchResponseStatus in project dhis2-core by dhis2.
the class ProgramNotificationServiceTest method testOuContactRecipient.
@Test
void testOuContactRecipient() {
when(programInstanceStore.get(anyLong())).thenReturn(programInstances.iterator().next());
when(programMessageService.sendMessages(anyList())).thenAnswer(invocation -> {
sentProgramMessages.addAll((List<ProgramMessage>) invocation.getArguments()[0]);
return new BatchResponseStatus(Collections.emptyList());
});
when(programNotificationRenderer.render(any(ProgramInstance.class), any(NotificationTemplate.class))).thenReturn(notificationMessage);
programNotificationTemplate.setNotificationRecipient(ProgramNotificationRecipient.ORGANISATION_UNIT_CONTACT);
programNotificationService.sendEnrollmentNotifications(programInstances.iterator().next().getId());
assertEquals(1, sentProgramMessages.size());
ProgramMessage programMessage = sentProgramMessages.iterator().next();
assertEquals(OrganisationUnit.class, programMessage.getRecipients().getOrganisationUnit().getClass());
assertEquals(lvlTwoLeftLeft, programMessage.getRecipients().getOrganisationUnit());
assertEquals(programMessage.getNotificationTemplate(), notificationTemplate);
}
Aggregations