ProgramRuleEngine { public List<RuleEffect> evaluate( ProgramInstance enrollment, Set<ProgramStageInstance> events ) { return evaluateProgramRules( enrollment, null, events ); } ProgramRuleEngine( ProgramRuleEntityMapperService programRuleEntityMapperService,
        ProgramRuleVariableService programRuleVariableService,
        OrganisationUnitGroupService organisationUnitGroupService,
        CurrentUserService currentUserService,
        ConstantService constantService,
        ImplementableRuleService implementableRuleService ); List<RuleEffect> evaluate( ProgramInstance enrollment, Set<ProgramStageInstance> events ); List<RuleEffect> evaluate( ProgramInstance enrollment, ProgramStageInstance programStageInstance,
        Set<ProgramStageInstance> events ); RuleValidationResult getDescription( String condition, Program program );  }
@Test public void testSendMessageForEnrollment() { setUpSendMessageForEnrollment(); ProgramInstance programInstance = programInstanceService.getProgramInstance( "UID-P1" ); 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-1", ruleActionSendMessage.notification() ); }
@Test public void testSendMessageForEvent() { setUpSendMessageForEnrollment(); ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( "UID-PS1" ); List<RuleEffect> ruleEffects = programRuleEngine.evaluate( programStageInstance.getProgramInstance(), programStageInstance, Sets.newHashSet() ); assertEquals( 1, ruleEffects.size() ); RuleAction ruleAction = ruleEffects.get( 0 ).ruleAction(); assertTrue( ruleAction instanceof RuleActionSendMessage ); RuleActionSendMessage ruleActionSendMessage = (RuleActionSendMessage) ruleAction; assertEquals( "PNT-1", ruleActionSendMessage.notification() ); }
@Test public void testAssignValueTypeDate() { setUpAssignValueDate(); ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( "UID-PS12" ); List<RuleEffect> ruleEffects = programRuleEngine.evaluate( programStageInstance.getProgramInstance(), programStageInstance, Sets.newHashSet() ); assertNotNull( ruleEffects ); assertEquals( ruleEffects.get( 0 ).data(), "10" ); }
@Test public void testAssignValueTypeAge() { setUpAssignValueAge(); ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( "UID-PS13" ); List<RuleEffect> ruleEffects = programRuleEngine.evaluate( programStageInstance.getProgramInstance(), programStageInstance, Sets.newHashSet() ); assertNotNull( ruleEffects ); assertEquals( ruleEffects.get( 0 ).data(), "10" ); }