Search in sources :

Example 16 with ProgramMessage

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

the class ProgramMessageServiceTest method testSaveProgramMessage.

@Test
void testSaveProgramMessage() {
    Long pmsgAId = null;
    pmsgAId = programMessageService.saveProgramMessage(pmsgA);
    assertNotNull(pmsgAId);
    ProgramMessage programMessage = programMessageService.getProgramMessage(pmsgAId.intValue());
    assertTrue(programMessage.equals(pmsgA));
}
Also used : ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 17 with ProgramMessage

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

the class ProgramMessageStoreTest method testGetProgramMessage.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testGetProgramMessage() {
    programMessageStore.save(pmsgA);
    Long id = pmsgA.getId();
    ProgramMessage actual = programMessageStore.get(id.intValue());
    assertNotNull(id);
    assertNotNull(actual);
    assertTrue(actual.equals(pmsgA));
}
Also used : ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 18 with ProgramMessage

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

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

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

the class MaintenanceServiceTest method testDeleteSoftDeletedTrackedEntityInstanceAProgramMessage.

@Test
void testDeleteSoftDeletedTrackedEntityInstanceAProgramMessage() {
    ProgramMessageRecipients programMessageRecipients = new ProgramMessageRecipients();
    programMessageRecipients.setEmailAddresses(Sets.newHashSet("testemail"));
    programMessageRecipients.setPhoneNumbers(Sets.newHashSet("testphone"));
    programMessageRecipients.setOrganisationUnit(organisationUnit);
    programMessageRecipients.setTrackedEntityInstance(entityInstanceB);
    ProgramMessage message = ProgramMessage.builder().subject("subject").text("text").recipients(programMessageRecipients).deliveryChannels(Sets.newHashSet(DeliveryChannel.EMAIL)).build();
    long idA = entityInstanceService.addTrackedEntityInstance(entityInstanceB);
    programMessageService.saveProgramMessage(message);
    assertNotNull(entityInstanceService.getTrackedEntityInstance(idA));
    entityInstanceService.deleteTrackedEntityInstance(entityInstanceB);
    assertNull(entityInstanceService.getTrackedEntityInstance(idA));
    assertTrue(entityInstanceService.trackedEntityInstanceExistsIncludingDeleted(entityInstanceB.getUid()));
    maintenanceService.deleteSoftDeletedTrackedEntityInstances();
    assertFalse(entityInstanceService.trackedEntityInstanceExistsIncludingDeleted(entityInstanceB.getUid()));
}
Also used : ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) Test(org.junit.jupiter.api.Test)

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