Search in sources :

Example 1 with ReferenceTrackerEntity

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());
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) ReferenceTrackerEntity(org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity) RelationshipType(org.hisp.dhis.relationship.RelationshipType) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 2 with ReferenceTrackerEntity

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ReferenceTrackerEntity(org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

ReferenceTrackerEntity (org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity)2 Test (org.junit.jupiter.api.Test)2 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.program.Program)1 RelationshipType (org.hisp.dhis.relationship.RelationshipType)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)1 Relationship (org.hisp.dhis.tracker.domain.Relationship)1 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)1