use of org.hisp.dhis.rules.models.RuleActionSendMessage in project dhis2-core by dhis2.
the class NotificationRuleActionImplementerTest method setUpInstances.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void setUpInstances() {
template = new ProgramNotificationTemplate();
template.setUid(NOTIFICATION_UID);
ruleActionSendMessage = new RuleActionSendMessage() {
@Nonnull
@Override
public String notification() {
return NOTIFICATION_UID;
}
@Nonnull
@Override
public String data() {
return null;
}
};
ruleEffectWithActionSendMessage = RuleEffect.create("", ruleActionSendMessage);
setMandatoryFieldFalse = RuleActionSetMandatoryField.create(MANDATORY_FIELD);
OrganisationUnit organisationUnitA = createOrganisationUnit('A');
Program programA = createProgram('A', new HashSet<>(), organisationUnitA);
programRuleA = createProgramRule('R', programA);
programRuleA.setProgram(programA);
programInstance = new ProgramInstance();
programInstance.setProgram(programA);
programInstance.setAutoFields();
ProgramStage programStageA = createProgramStage('S', programA);
programA.getProgramStages().add(programStageA);
programStageInstance = new ProgramStageInstance();
programStageInstance.setProgramStage(programStageA);
programStageInstance.setProgramInstance(programInstance);
programStageInstance.setAutoFields();
}
use of org.hisp.dhis.rules.models.RuleActionSendMessage in project dhis2-core by dhis2.
the class NotificationRuleActionImplementer method getNotificationTemplate.
@Transactional(readOnly = true)
public ProgramNotificationTemplate getNotificationTemplate(RuleAction action) {
String uid = "";
if (action instanceof RuleActionSendMessage) {
RuleActionSendMessage sendMessage = (RuleActionSendMessage) action;
uid = sendMessage.notification();
} else if (action instanceof RuleActionScheduleMessage) {
RuleActionScheduleMessage scheduleMessage = (RuleActionScheduleMessage) action;
uid = scheduleMessage.notification();
}
return programNotificationTemplateService.getByUid(uid);
}
use of org.hisp.dhis.rules.models.RuleActionSendMessage in project dhis2-core by dhis2.
the class ProgramRuleEngineServiceTest method testWithImplementableActionExist_programInstance.
@Test
void testWithImplementableActionExist_programInstance() {
doAnswer(invocationOnMock -> {
ruleEffects.add((RuleEffect) invocationOnMock.getArguments()[0]);
return ruleEffects;
}).when(ruleActionSendMessage).implement(any(), any(ProgramInstance.class));
List<RuleEffect> effects = new ArrayList<>();
effects.add(RuleEffect.create("", RuleActionSendMessage.create(NOTIFICATION_UID, DATA)));
when(programInstanceService.getProgramInstance(anyLong())).thenReturn(programInstance);
when(programRuleEngine.evaluate(any(), any())).thenReturn(effects);
setProgramRuleActionType_SendMessage();
ArgumentCaptor<ProgramInstance> argumentCaptor = ArgumentCaptor.forClass(ProgramInstance.class);
List<RuleEffect> ruleEffects = service.evaluateEnrollmentAndRunEffects(programInstance.getId());
assertEquals(1, ruleEffects.size());
RuleAction action = ruleEffects.get(0).ruleAction();
if (action instanceof RuleActionSendMessage) {
RuleActionSendMessage ruleActionSendMessage = (RuleActionSendMessage) action;
assertEquals(NOTIFICATION_UID, ruleActionSendMessage.notification());
}
verify(programRuleEngine, times(1)).evaluate(argumentCaptor.capture(), any());
assertEquals(programInstance, argumentCaptor.getValue());
verify(ruleActionSendMessage).accept(action);
verify(ruleActionSendMessage).implement(any(RuleEffect.class), argumentCaptor.capture());
assertEquals(1, this.ruleEffects.size());
assertTrue(this.ruleEffects.get(0).ruleAction() instanceof RuleActionSendMessage);
}
Aggregations