use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class FileResourceSupplierTest method getTrackedEntity.
private TrackedEntity getTrackedEntity() {
Attribute attribute = new Attribute();
attribute.setAttribute(NUMERIC_ATTRIBUTE_UID);
attribute.setValueType(ValueType.NUMBER);
TrackedEntity trackedEntity = new TrackedEntity();
trackedEntity.setAttributes(Lists.newArrayList(attribute));
return trackedEntity;
}
use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class EnrollmentAttributeValidationHookTest method shouldFailValidationWhenAttributeIsNotPresentInDB.
@Test
void shouldFailValidationWhenAttributeIsNotPresentInDB() {
Attribute attribute = Attribute.builder().attribute("invalidAttribute").valueType(ValueType.TEXT).value("value").build();
when(program.getProgramAttributes()).thenReturn(Collections.emptyList());
when(enrollment.getAttributes()).thenReturn(Collections.singletonList(attribute));
when(trackedEntityInstance.getTrackedEntityAttributeValues()).thenReturn(new HashSet<>(Collections.singletonList(new TrackedEntityAttributeValue(trackedEntityAttribute, trackedEntityInstance))));
when(preheat.getTrackedEntity(TrackerIdScheme.UID, enrollment.getTrackedEntity())).thenReturn(trackedEntityInstance);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
hookToTest.validateEnrollment(reporter, enrollment);
assertThat(reporter.getReportList(), hasSize(1));
hasTrackerError(reporter, TrackerErrorCode.E1006, TrackerType.ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class EnrollmentAttributeValidationHookTest method shouldFailValidationWhenValueIsNullAndAttributeIsMandatory.
@Test
void shouldFailValidationWhenValueIsNullAndAttributeIsMandatory() {
// given 1 attribute has null value
Attribute attribute = Attribute.builder().attribute(trackedAttribute).valueType(ValueType.TEXT).value("value").build();
Attribute attribute1 = Attribute.builder().attribute(trackedAttribute1).valueType(ValueType.TEXT).build();
// when both tracked attributes are mandatory
when(program.getProgramAttributes()).thenReturn(Arrays.asList(new ProgramTrackedEntityAttribute(program, trackedEntityAttribute, false, true), new ProgramTrackedEntityAttribute(program, trackedEntityAttribute1, false, true)));
when(enrollment.getAttributes()).thenReturn(Arrays.asList(attribute, attribute1));
when(trackedEntityInstance.getTrackedEntityAttributeValues()).thenReturn(new HashSet<>(Arrays.asList(new TrackedEntityAttributeValue(trackedEntityAttribute, trackedEntityInstance), new TrackedEntityAttributeValue(trackedEntityAttribute1, trackedEntityInstance))));
when(preheat.getTrackedEntity(TrackerIdScheme.UID, enrollment.getTrackedEntity())).thenReturn(trackedEntityInstance);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
hookToTest.validateEnrollment(reporter, enrollment);
assertThat(reporter.getReportList(), hasSize(1));
hasTrackerError(reporter, TrackerErrorCode.E1076, TrackerType.ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Attribute in project dhis2-core by dhis2.
the class EnrollmentAttributeValidationHookTest method shouldFailValidationWhenValueIsNullAndAttributeIsNotMandatoryAndAttributeNotExistsInTei.
@Test
void shouldFailValidationWhenValueIsNullAndAttributeIsNotMandatoryAndAttributeNotExistsInTei() {
// given 1 attribute has null value and do not exists in Tei
Attribute attribute = Attribute.builder().attribute(trackedAttribute).valueType(ValueType.TEXT).value("value").build();
Attribute attribute1 = Attribute.builder().attribute(trackedAttribute1).valueType(ValueType.TEXT).build();
// when 2 tracked attributes are mandatory
when(program.getProgramAttributes()).thenReturn(Arrays.asList(new ProgramTrackedEntityAttribute(program, trackedEntityAttribute, false, true), new ProgramTrackedEntityAttribute(program, trackedEntityAttribute1, false, true)));
when(enrollment.getAttributes()).thenReturn(Arrays.asList(attribute, attribute1));
when(trackedEntityInstance.getTrackedEntityAttributeValues()).thenReturn(new HashSet<>(Collections.singletonList(new TrackedEntityAttributeValue(trackedEntityAttribute, trackedEntityInstance))));
when(preheat.getTrackedEntity(TrackerIdScheme.UID, enrollment.getTrackedEntity())).thenReturn(trackedEntityInstance);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
hookToTest.validateEnrollment(reporter, enrollment);
assertThat(reporter.getReportList(), hasSize(2));
hasTrackerError(reporter, TrackerErrorCode.E1076, TrackerType.ENROLLMENT, enrollment.getUid());
hasTrackerError(reporter, TrackerErrorCode.E1018, TrackerType.ENROLLMENT, enrollment.getUid());
}
Aggregations