Search in sources :

Example 11 with BatchResponseStatus

use of org.hisp.dhis.outboundmessage.BatchResponseStatus 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)

Example 12 with BatchResponseStatus

use of org.hisp.dhis.outboundmessage.BatchResponseStatus in project dhis2-core by dhis2.

the class DefaultDataSetNotificationService method sendProgramMessages.

private void sendProgramMessages(List<ProgramMessage> messages) {
    if (messages.isEmpty()) {
        return;
    }
    log.info(String.format("Dispatching %d ProgramMessages", messages.size()));
    BatchResponseStatus status = externalMessageService.sendMessages(messages);
    log.debug(String.format("Resulting status from ProgramMessageService:\n %s", status.toString()));
}
Also used : BatchResponseStatus(org.hisp.dhis.outboundmessage.BatchResponseStatus)

Aggregations

BatchResponseStatus (org.hisp.dhis.outboundmessage.BatchResponseStatus)12 ProgramMessage (org.hisp.dhis.program.message.ProgramMessage)8 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)7 NotificationTemplate (org.hisp.dhis.notification.NotificationTemplate)7 Test (org.junit.jupiter.api.Test)7 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 Date (java.util.Date)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 NotificationMessage (org.hisp.dhis.notification.NotificationMessage)1 OutboundMessageBatch (org.hisp.dhis.outboundmessage.OutboundMessageBatch)1 OutboundMessageResponseSummary (org.hisp.dhis.outboundmessage.OutboundMessageResponseSummary)1 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)1 ProgramMessageBatch (org.hisp.dhis.program.message.ProgramMessageBatch)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1