use of org.hisp.dhis.rules.models.RuleEnrollment in project dhis2-android-sdk by dhis2.
the class RuleEngineShould method throw_illegal_state_exception_if_evaluate_and_enrollemnt_is_already_in_context.
@Test
public void throw_illegal_state_exception_if_evaluate_and_enrollemnt_is_already_in_context() {
RuleEnrollment ruleEnrollment = mock(RuleEnrollment.class);
RuleEngine ruleEngine = ruleEngineContext.toEngineBuilder().enrollment(ruleEnrollment).build();
try {
ruleEngine.evaluate(ruleEnrollment);
fail("IllegalStateException was expected, but nothing was thrown.");
} catch (IllegalStateException illegalStateException) {
// noop
}
}
use of org.hisp.dhis.rules.models.RuleEnrollment in project dhis2-android-sdk by dhis2.
the class RuleEngineShould method throw_illegal_argument_exception_when_evaluate_with_null_enrollment.
@Test
public void throw_illegal_argument_exception_when_evaluate_with_null_enrollment() {
try {
RuleEnrollment ruleEnrollment = null;
ruleEngineContext.toEngineBuilder().build().evaluate(ruleEnrollment);
fail("IllegalArgumentException was expected, but nothing was thrown.");
} catch (IllegalArgumentException illegalArgumentException) {
// noop
}
}
use of org.hisp.dhis.rules.models.RuleEnrollment in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilderShould method contain_values_from_context_enrollment_in_attribute_variable.
@Test
public void contain_values_from_context_enrollment_in_attribute_variable() throws ParseException {
RuleVariable ruleVariableOne = RuleVariableAttribute.create("test_variable_one", "test_attribute_one", RuleValueType.TEXT);
RuleVariable ruleVariableTwo = RuleVariableAttribute.create("test_variable_two", "test_attribute_two", RuleValueType.TEXT);
Date eventDate = dateFormat.parse("2015-01-01");
Date enrollmentDate = dateFormat.parse("2014-03-01");
// values from ruleEnrollment should end up in ruleVariables
RuleEnrollment ruleEnrollment = RuleEnrollment.create("test_enrollment", enrollmentDate, enrollmentDate, RuleEnrollment.Status.ACTIVE, Arrays.asList(RuleAttributeValue.create("test_attribute_one", "test_attribute_value_one"), RuleAttributeValue.create("test_attribute_two", "test_attribute_value_two")));
// values from context ruleEvents should be ignored
RuleEvent contextEvent = RuleEvent.create("test_context_event_one", "test_program_stage", RuleEvent.Status.ACTIVE, eventDate, new Date(), Arrays.asList(RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_one", "test_context_value_one"), RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_two", "test_context_value_two")));
RuleEvent currentEvent = RuleEvent.create("test_event_uid", "test_program_stage", RuleEvent.Status.ACTIVE, eventDate, eventDate, Arrays.asList(RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_one", "test_value_one"), RuleDataValue.create(eventDate, "test_program_stage", "test_dataelement_two", "test_value_two")));
// here we will expect correct values to be returned
Map<String, RuleVariableValue> valueMap = RuleVariableValueMapBuilder.target(currentEvent).ruleEnrollment(ruleEnrollment).ruleVariables(Arrays.asList(ruleVariableOne, ruleVariableTwo)).ruleEvents(Arrays.asList(contextEvent)).build();
assertThat(valueMap.size()).isEqualTo(12);
assertThatVariable(valueMap.get("current_date")).hasValue(wrap(dateFormat.format(new Date()))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(new Date()));
assertThatVariable(valueMap.get("event_date")).hasValue(wrap(dateFormat.format(eventDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(eventDate));
assertThatVariable(valueMap.get("event_count")).hasValue("2").isTypeOf(RuleValueType.NUMERIC).hasCandidates("2");
assertThatVariable(valueMap.get("event_id")).hasValue("'test_event_uid'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_event_uid");
assertThatVariable(valueMap.get("due_date")).hasValue(wrap(dateFormat.format(eventDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(eventDate));
assertThatVariable(valueMap.get("enrollment_date")).hasValue(wrap(dateFormat.format(enrollmentDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(enrollmentDate));
assertThatVariable(valueMap.get("enrollment_id")).hasValue("'test_enrollment'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_enrollment");
assertThatVariable(valueMap.get("enrollment_count")).hasValue("1").isTypeOf(RuleValueType.NUMERIC).hasCandidates("1");
assertThatVariable(valueMap.get("incident_date")).hasValue(wrap(dateFormat.format(enrollmentDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(enrollmentDate));
assertThatVariable(valueMap.get("tei_count")).hasValue("1").isTypeOf(RuleValueType.NUMERIC).hasCandidates("1");
assertThatVariable(valueMap.get("test_variable_one")).hasValue("'test_attribute_value_one'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_attribute_value_one");
assertThatVariable(valueMap.get("test_variable_two")).hasValue("'test_attribute_value_two'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_attribute_value_two");
}
use of org.hisp.dhis.rules.models.RuleEnrollment in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilderShould method propagate_to_map_correctly_the_given_rule_enrollment_values.
@Test
public void propagate_to_map_correctly_the_given_rule_enrollment_values() throws ParseException {
RuleVariable ruleVariableOne = RuleVariableAttribute.create("test_variable_one", "test_attribute_one", RuleValueType.NUMERIC);
RuleVariable ruleVariableTwo = RuleVariableAttribute.create("test_variable_two", "test_attribute_two", RuleValueType.TEXT);
RuleVariable ruleVariableThree = RuleVariableCurrentEvent.create("test_variable_three", "test_dataelement_one", RuleValueType.BOOLEAN);
String currentDate = dateFormat.format(new Date());
Date enrollmentDate = dateFormat.parse("2017-02-02");
Date incidentDate = dateFormat.parse("2017-04-02");
RuleEnrollment ruleEnrollment = RuleEnrollment.create("test_enrollment", incidentDate, enrollmentDate, RuleEnrollment.Status.ACTIVE, Arrays.asList(RuleAttributeValue.create("test_attribute_one", "test_attribute_value_one"), RuleAttributeValue.create("test_attribute_two", "test_attribute_value_two"), RuleAttributeValue.create("test_attribute_three", "test_attribute_value_three")));
RuleEvent ruleEventOne = RuleEvent.create("test_event_one", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), new ArrayList<RuleDataValue>());
RuleEvent ruleEventTwo = RuleEvent.create("test_event_two", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), new ArrayList<RuleDataValue>());
Map<String, RuleVariableValue> valueMap = RuleVariableValueMapBuilder.target(ruleEnrollment).ruleVariables(Arrays.asList(ruleVariableOne, ruleVariableTwo, ruleVariableThree)).ruleEvents(Arrays.asList(ruleEventOne, ruleEventTwo)).build();
assertThat(valueMap.size()).isEqualTo(9);
assertThatVariable(valueMap.get("current_date")).hasValue(wrap(currentDate)).isTypeOf(RuleValueType.TEXT).hasCandidates(currentDate);
assertThatVariable(valueMap.get("event_count")).hasValue("2").isTypeOf(RuleValueType.NUMERIC).hasCandidates("2");
assertThatVariable(valueMap.get("enrollment_date")).hasValue(wrap(dateFormat.format(enrollmentDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(enrollmentDate));
assertThatVariable(valueMap.get("enrollment_id")).hasValue("'test_enrollment'").isTypeOf(RuleValueType.TEXT).hasCandidates("test_enrollment");
assertThatVariable(valueMap.get("enrollment_count")).hasValue("1").isTypeOf(RuleValueType.NUMERIC).hasCandidates("1");
assertThatVariable(valueMap.get("incident_date")).hasValue(wrap(dateFormat.format(incidentDate))).isTypeOf(RuleValueType.TEXT).hasCandidates(dateFormat.format(incidentDate));
assertThatVariable(valueMap.get("tei_count")).hasValue("1").isTypeOf(RuleValueType.NUMERIC).hasCandidates("1");
assertThatVariable(valueMap.get("test_variable_one")).hasValue("test_attribute_value_one").isTypeOf(RuleValueType.NUMERIC).hasCandidates("test_attribute_value_one");
assertThatVariable(valueMap.get("test_variable_two")).isTypeOf(RuleValueType.TEXT).hasValue("'test_attribute_value_two'").hasCandidates("test_attribute_value_two");
}
use of org.hisp.dhis.rules.models.RuleEnrollment in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilderShould method throw_illegal_state_exception_when_build_a_rule_enrollment_if_target_enrollment_is_already_set.
@Test
public void throw_illegal_state_exception_when_build_a_rule_enrollment_if_target_enrollment_is_already_set() {
try {
RuleEnrollment ruleEnrollment = mock(RuleEnrollment.class);
RuleVariableValueMapBuilder.target(ruleEnrollment).ruleEnrollment(ruleEnrollment).build();
fail("IllegalStateException was expected, but nothing was thrown.");
} catch (IllegalStateException illegalStateException) {
// noop
}
}
Aggregations