use of org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method verifyValidationSuccessWhenLinkedTrackedEntityIsFound.
@Test
void verifyValidationSuccessWhenLinkedTrackedEntityIsFound() {
TrackedEntityInstance validTrackedEntity = new TrackedEntityInstance();
validTrackedEntity.setUid("validTrackedEntity");
when(ctx.getTrackedEntityInstance("validTrackedEntity")).thenReturn(validTrackedEntity);
ReferenceTrackerEntity anotherValidTrackedEntity = new ReferenceTrackerEntity("anotherValidTrackedEntity", null);
when(ctx.getReference("anotherValidTrackedEntity")).thenReturn(Optional.of(anotherValidTrackedEntity));
RelationshipType relType = createRelTypeConstraint(TRACKED_ENTITY_INSTANCE, TRACKED_ENTITY_INSTANCE);
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity("validTrackedEntity").build()).to(RelationshipItem.builder().trackedEntity("anotherValidTrackedEntity").build()).relationshipType(relType.getUid()).build();
hook.validateRelationship(reporter, relationship);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity in project dhis2-core by dhis2.
the class PreCheckMetaValidationHookTest method verifyEnrollmentValidationSuccessWhenTeiIsInPayload.
@Test
void verifyEnrollmentValidationSuccessWhenTeiIsInPayload() {
// given
Enrollment enrollment = validEnrollment();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
// when
when(ctx.getReference(TRACKED_ENTITY_UID)).thenReturn(Optional.of(new ReferenceTrackerEntity("", "")));
when(ctx.getOrganisationUnit(ORG_UNIT_UID)).thenReturn(new OrganisationUnit());
when(ctx.getProgram(PROGRAM_UID)).thenReturn(new Program());
validatorToTest.validateEnrollment(reporter, enrollment);
// then
assertFalse(reporter.hasErrors());
}
Aggregations