Search in sources :

Example 1 with NotificationTemplate

use of org.hisp.dhis.notification.NotificationTemplate 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);
}
Also used : BatchResponseStatus(org.hisp.dhis.outboundmessage.BatchResponseStatus) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) NotificationTemplate(org.hisp.dhis.notification.NotificationTemplate) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 2 with NotificationTemplate

use of org.hisp.dhis.notification.NotificationTemplate 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);
}
Also used : BatchResponseStatus(org.hisp.dhis.outboundmessage.BatchResponseStatus) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) NotificationTemplate(org.hisp.dhis.notification.NotificationTemplate) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 3 with NotificationTemplate

use of org.hisp.dhis.notification.NotificationTemplate in project dhis2-core by dhis2.

the class ProgramNotificationServiceTest method testProgramAttributeRecipientWithEMAIL.

@Test
void testProgramAttributeRecipientWithEMAIL() {
    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.EMAIL));
    programNotificationService.sendEnrollmentNotifications(programInstances.iterator().next().getId());
    assertEquals(1, sentProgramMessages.size());
    ProgramMessage programMessage = sentProgramMessages.iterator().next();
    assertTrue(programMessage.getRecipients().getEmailAddresses().contains(ATT_EMAIL));
    assertTrue(programMessage.getDeliveryChannels().contains(DeliveryChannel.EMAIL));
    assertEquals(programMessage.getNotificationTemplate(), notificationTemplate);
}
Also used : BatchResponseStatus(org.hisp.dhis.outboundmessage.BatchResponseStatus) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) NotificationTemplate(org.hisp.dhis.notification.NotificationTemplate) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)3 NotificationTemplate (org.hisp.dhis.notification.NotificationTemplate)3 BatchResponseStatus (org.hisp.dhis.outboundmessage.BatchResponseStatus)3 ProgramInstance (org.hisp.dhis.program.ProgramInstance)3 ProgramMessage (org.hisp.dhis.program.message.ProgramMessage)3 Test (org.junit.jupiter.api.Test)3