use of org.hisp.dhis.program.notification.ProgramNotificationTemplate in project dhis2-core by dhis2.
the class ProgramRuleEngineTest method testNotificationWhenUsingD2HasValueWithTEA.
@Test
void testNotificationWhenUsingD2HasValueWithTEA() {
setUpNotificationForD2HasValue();
ProgramInstance programInstance = programInstanceService.getProgramInstance("UID-P2");
List<RuleEffect> ruleEffects = programRuleEngine.evaluate(programInstance, Sets.newHashSet());
assertEquals(1, ruleEffects.size());
RuleAction ruleAction = ruleEffects.get(0).ruleAction();
assertTrue(ruleAction instanceof RuleActionSendMessage);
RuleActionSendMessage ruleActionSendMessage = (RuleActionSendMessage) ruleAction;
assertEquals("PNT-2", ruleActionSendMessage.notification());
ProgramNotificationTemplate template = programNotificationTemplateStore.getByUid("PNT-2");
assertNotNull(template);
assertEquals(NotificationTrigger.PROGRAM_RULE, template.getNotificationTrigger());
assertEquals(ProgramNotificationRecipient.PROGRAM_ATTRIBUTE, template.getNotificationRecipient());
assertEquals("message_template", template.getMessageTemplate());
}
use of org.hisp.dhis.program.notification.ProgramNotificationTemplate in project dhis2-core by dhis2.
the class ProgramRuleEngineTest method testSendMessageForEnrollmentAndEvent.
@Test
void testSendMessageForEnrollmentAndEvent() {
setUpSendMessageForEnrollment();
ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance("UID-PS1");
List<RuleEffects> ruleEffects = programRuleEngine.evaluateEnrollmentAndEvents(programStageInstance.getProgramInstance(), Sets.newHashSet(programStageInstance), Lists.newArrayList());
assertEquals(2, ruleEffects.size());
RuleEffects enrollmentRuleEffects = ruleEffects.stream().filter(RuleEffects::isEnrollment).findFirst().get();
RuleEffects eventRuleEffects = ruleEffects.stream().filter(RuleEffects::isEvent).findFirst().get();
assertEquals("UID-PS1", eventRuleEffects.getTrackerObjectUid());
RuleAction eventRuleAction = eventRuleEffects.getRuleEffects().get(0).ruleAction();
RuleAction enrollmentRuleAction = enrollmentRuleEffects.getRuleEffects().get(0).ruleAction();
assertTrue(eventRuleAction instanceof RuleActionSendMessage);
assertTrue(enrollmentRuleAction instanceof RuleActionSendMessage);
RuleActionSendMessage ruleActionSendMessage = (RuleActionSendMessage) eventRuleAction;
assertEquals("PNT-1", ruleActionSendMessage.notification());
ProgramNotificationTemplate template = programNotificationTemplateStore.getByUid("PNT-1");
assertNotNull(template);
assertEquals(NotificationTrigger.PROGRAM_RULE, template.getNotificationTrigger());
assertEquals(ProgramNotificationRecipient.USER_GROUP, template.getNotificationRecipient());
assertEquals("message_template", template.getMessageTemplate());
}
Aggregations