Search in sources :

Example 11 with ProgramMessage

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

Example 12 with ProgramMessage

use of org.hisp.dhis.program.message.ProgramMessage 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());
}
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 13 with ProgramMessage

use of org.hisp.dhis.program.message.ProgramMessage 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 14 with ProgramMessage

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

Example 15 with ProgramMessage

use of org.hisp.dhis.program.message.ProgramMessage in project dhis2-core by dhis2.

the class DhisConvenienceTest method createProgramMessage.

public static ProgramMessage createProgramMessage(String text, String subject, ProgramMessageRecipients recipients, ProgramMessageStatus status, Set<DeliveryChannel> channels) {
    ProgramMessage message = new ProgramMessage();
    message.setText(text);
    message.setSubject(subject);
    message.setRecipients(recipients);
    message.setMessageStatus(status);
    message.setDeliveryChannels(channels);
    return message;
}
Also used : ProgramMessage(org.hisp.dhis.program.message.ProgramMessage)

Aggregations

ProgramMessage (org.hisp.dhis.program.message.ProgramMessage)22 Test (org.junit.jupiter.api.Test)16 BatchResponseStatus (org.hisp.dhis.outboundmessage.BatchResponseStatus)8 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)7 NotificationTemplate (org.hisp.dhis.notification.NotificationTemplate)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 ProgramMessageRecipients (org.hisp.dhis.program.message.ProgramMessageRecipients)4 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 SqlHelper (org.hisp.dhis.commons.util.SqlHelper)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 NotificationMessage (org.hisp.dhis.notification.NotificationMessage)1 ProgramMessageBatch (org.hisp.dhis.program.message.ProgramMessageBatch)1 ProgramMessageQueryParams (org.hisp.dhis.program.message.ProgramMessageQueryParams)1