Search in sources :

Example 6 with Relationship

use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.

the class PreCheckMandatoryFieldsValidationHookTest method verifyRelationshipValidationSuccess.

@Test
void verifyRelationshipValidationSuccess() {
    Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateRelationship(reporter, relationship);
    assertFalse(reporter.hasErrors());
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 7 with Relationship

use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.

the class TrackerBundleParamsConverterTest method verifyNestedTeiStructureIsFlattenedDuringDeserialization.

@Test
void verifyNestedTeiStructureIsFlattenedDuringDeserialization() throws IOException {
    List<Relationship> relationships1 = createRelationships(2, "rel1");
    List<Relationship> relationships2 = createRelationships(2, "rel2");
    List<Event> events1 = createEvent(3, "ev1", "enr1");
    List<Event> events2 = createEvent(7, "ev2", "enr2");
    List<Enrollment> enrollments = new ArrayList<>();
    Enrollment enrollment1 = createEnrollment("enr1", "teiABC", events1);
    Enrollment enrollment2 = createEnrollment("enr2", "teiABC", events2);
    enrollment1.setRelationships(relationships2);
    enrollment2.setRelationships(relationships1);
    enrollments.add(enrollment1);
    enrollments.add(enrollment2);
    TrackedEntity trackedEntity = createTrackedEntity("teiABC", enrollments);
    trackedEntity.setRelationships(relationships1);
    TrackerBundleParams build = TrackerBundleParams.builder().trackedEntities(Collections.singletonList(trackedEntity)).build();
    String jsonPayload = toJson(build);
    TrackerBundleParams b2 = this.objectMapper.readValue(jsonPayload, TrackerBundleParams.class);
    assertThat(b2.getTrackedEntities(), hasSize(1));
    assertThat(b2.getEnrollments(), hasSize(2));
    assertThat(b2.getEvents(), hasSize(10));
    assertThat(b2.getRelationships(), hasSize(4));
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Relationship(org.hisp.dhis.tracker.domain.Relationship) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.tracker.domain.Event) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Test(org.junit.jupiter.api.Test)

Example 8 with Relationship

use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.

the class TrackerBundleParamsConverterTest method createRelationships.

private List<Relationship> createRelationships(int size, String uid) {
    List<Relationship> relationships = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        Relationship relationship = rnd.nextObject(Relationship.class);
        relationship.setRelationship(uid + i);
        relationships.add(relationship);
    }
    return relationships;
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) ArrayList(java.util.ArrayList)

Example 9 with Relationship

use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.

the class PreCheckUidValidationHookTest method verifyRelationshipWithInvalidUidFails.

@Test
void verifyRelationshipWithInvalidUidFails() {
    // given
    Relationship relationship = Relationship.builder().relationship(INVALID_UID).build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateRelationship(reporter, relationship);
    // then
    hasTrackerError(reporter, E1048, RELATIONSHIP, relationship.getUid());
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 10 with Relationship

use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.

the class PreCheckUidValidationHookTest method verifyRelationshipValidationSuccess.

@Test
void verifyRelationshipValidationSuccess() {
    // given
    Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateRelationship(reporter, relationship);
    // then
    assertFalse(reporter.hasErrors());
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

Relationship (org.hisp.dhis.tracker.domain.Relationship)38 Test (org.junit.jupiter.api.Test)34 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)23 RelationshipType (org.hisp.dhis.relationship.RelationshipType)14 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)9 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)7 ArrayList (java.util.ArrayList)6 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)6 Event (org.hisp.dhis.tracker.domain.Event)6 RelationshipConstraint (org.hisp.dhis.relationship.RelationshipConstraint)4 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)4 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)3 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)3 Collectors (java.util.stream.Collectors)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 CodeGenerator (org.hisp.dhis.common.CodeGenerator)2 ProgramInstance (org.hisp.dhis.program.ProgramInstance)2 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)2 ReferenceTrackerEntity (org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity)2 TrackerErrorReport (org.hisp.dhis.tracker.report.TrackerErrorReport)2