use of org.hisp.dhis.tracker.programrule.IssueType.WARNING in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentInTeiAndCanBeOverwritten.
@Test
void testAssignAttributeValueForEnrollmentsWhenAttributeIsAlreadyPresentInTeiAndCanBeOverwritten() {
when(systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE)).thenReturn(Boolean.TRUE);
List<Enrollment> enrollments = Lists.newArrayList(getEnrollmentWithAttributeNOTSet());
List<TrackedEntity> trackedEntities = Lists.newArrayList(getTrackedEntitiesWithAttributeSet());
bundle.setEnrollments(enrollments);
bundle.setTrackedEntities(trackedEntities);
bundle.setRuleEffects(getRuleEnrollmentEffects(enrollments));
Map<String, List<ProgramRuleIssue>> enrollmentIssues = implementerToTest.validateEnrollments(bundle);
Enrollment enrollment = bundle.getEnrollments().stream().filter(e -> e.getEnrollment().equals(SECOND_ENROLLMENT_ID)).findAny().get();
TrackedEntity trackedEntity = bundle.getTrackedEntities().stream().filter(e -> e.getTrackedEntity().equals(TRACKED_ENTITY_ID)).findAny().get();
Optional<Attribute> enrollmentAttribute = enrollment.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
Optional<Attribute> teiAttribute = trackedEntity.getAttributes().stream().filter(at -> at.getAttribute().equals(ATTRIBUTE_ID)).findAny();
assertFalse(enrollmentAttribute.isPresent());
assertTrue(teiAttribute.isPresent());
assertEquals(TEI_ATTRIBUTE_NEW_VALUE, teiAttribute.get().getValue());
assertEquals(1, enrollmentIssues.size());
assertEquals(1, enrollmentIssues.get(SECOND_ENROLLMENT_ID).size());
assertEquals(WARNING, enrollmentIssues.get(SECOND_ENROLLMENT_ID).get(0).getIssueType());
}
use of org.hisp.dhis.tracker.programrule.IssueType.WARNING in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignDataElementValueForEventsWhenDataElementIsAlreadyPresentAndHasSameValue.
@Test
void testAssignDataElementValueForEventsWhenDataElementIsAlreadyPresentAndHasSameValue() {
List<Event> events = Lists.newArrayList(getEventWithDataValueSetSameValue());
bundle.setEvents(events);
bundle.setRuleEffects(getRuleEventEffects(events));
Map<String, List<ProgramRuleIssue>> eventIssues = implementerToTest.validateEvents(bundle);
Event event = bundle.getEvents().stream().filter(e -> e.getEvent().equals(FIRST_EVENT_ID)).findAny().get();
Optional<DataValue> newDataValue = event.getDataValues().stream().filter(dv -> dv.getDataElement().equals(dataElementA.getUid())).findAny();
assertTrue(newDataValue.isPresent());
assertEquals(DATA_ELEMENT_NEW_VALUE, newDataValue.get().getValue());
assertEquals(1, eventIssues.size());
assertEquals(1, eventIssues.get(FIRST_EVENT_ID).size());
assertEquals(WARNING, eventIssues.get(FIRST_EVENT_ID).get(0).getIssueType());
}
use of org.hisp.dhis.tracker.programrule.IssueType.WARNING in project dhis2-core by dhis2.
the class AssignValueImplementerTest method testAssignDataElementValueForEventsWhenDataElementIsAlreadyPresentAndSystemSettingToOverwriteIsTrue.
@Test
void testAssignDataElementValueForEventsWhenDataElementIsAlreadyPresentAndSystemSettingToOverwriteIsTrue() {
List<Event> events = Lists.newArrayList(getEventWithDataValueSet());
bundle.setEvents(events);
bundle.setRuleEffects(getRuleEventEffects(events));
when(systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE)).thenReturn(Boolean.TRUE);
Map<String, List<ProgramRuleIssue>> eventIssues = implementerToTest.validateEvents(bundle);
Event event = bundle.getEvents().stream().filter(e -> e.getEvent().equals(FIRST_EVENT_ID)).findAny().get();
Optional<DataValue> newDataValue = event.getDataValues().stream().filter(dv -> dv.getDataElement().equals(dataElementA.getUid())).findAny();
assertTrue(newDataValue.isPresent());
assertEquals(DATA_ELEMENT_NEW_VALUE, newDataValue.get().getValue());
assertEquals(1, eventIssues.size());
assertEquals(1, eventIssues.get(FIRST_EVENT_ID).size());
assertEquals(WARNING, eventIssues.get(FIRST_EVENT_ID).get(0).getIssueType());
}
Aggregations