use of org.hisp.dhis.notification.NotificationMessage in project dhis2-core by dhis2.
the class ValidationNotificationServiceTest method initTest.
/*
* Configure org unit hierarchy like so:
*
* Root / \ lvlOneLeft lvlOneRight / \ lvlTwoLeftLeft lvlTwoLeftRight
*/
/**
* We mock the sending of messages to write to a local List (which we can
* inspect). Also, the renderer is replaced with a mock which returns a
* static subject/message-pair.
*/
@BeforeEach
void initTest() {
subject = new DefaultValidationNotificationService(renderer, messageService, validationResultService);
this.periodService = new DefaultPeriodService(periodStore);
sentMessages = new ArrayList<>();
when(messageService.sendValidationMessage(anySet(), anyString(), anyString(), any(MessageConversationPriority.class))).then(invocation -> {
sentMessages.add(new MockMessage(invocation.getArguments()));
return 42L;
});
// Stub renderer
when(renderer.render(any(), any())).thenReturn(new NotificationMessage(STATIC_MOCK_SUBJECT, STATIC_MOCK_MESSAGE));
}
use of org.hisp.dhis.notification.NotificationMessage in project dhis2-core by dhis2.
the class DefaultValidationNotificationService method createSingleNotifications.
private Map<Set<User>, NotificationMessage> createSingleNotifications(SortedSet<MessagePair> messagePairs) {
BiMap<Set<User>, NotificationMessage> singleNotificationCollection = HashBiMap.create();
for (MessagePair messagePair : messagePairs) {
NotificationMessage notificationMessage = notificationMessageRenderer.render(messagePair.result, messagePair.template);
notificationMessage.setPriority(getPriority(messagePair.result.getValidationRule().getImportance()));
singleNotificationCollection.put(new HashSet<>(), notificationMessage);
resolveRecipients(messagePair).forEach(user -> singleNotificationCollection.inverse().get(notificationMessage).add(user));
}
return singleNotificationCollection;
}
Aggregations