Search in sources :

Example 21 with Relationship

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

the class DuplicateRelationshipsPreProcessorTest method test_on_different_rels_none_is_removed.

/*
     * Verifies that:
     *
     * - given 2 non-identical relationships
     *
     * - none is removed
     */
@Test
void test_on_different_rels_none_is_removed() {
    String fromTeiUid = CodeGenerator.generateUid();
    String toTeiUid = CodeGenerator.generateUid();
    Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(REL_TYPE_NONBIDIRECTIONAL_UID).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
    Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(REL_TYPE_NONBIDIRECTIONAL_UID).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().enrollment(toTeiUid).build()).build();
    TrackerBundle bundle = TrackerBundle.builder().preheat(this.preheat).relationships(Lists.newArrayList(relationship1, relationship2)).build();
    preProcessor.process(bundle);
    assertThat(bundle.getRelationships(), hasSize(2));
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 22 with Relationship

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

the class DuplicateRelationshipsPreProcessorTest method test_on_identical_rels_but_inverted_type_bi_1_is_removed.

/*
     * Verifies that:
     *
     * - given 2 identical relationships having identical but "inverted" data
     *
     * - and relationship type's bidirectional property = true
     *
     * - none is removed
     */
@Test
void test_on_identical_rels_but_inverted_type_bi_1_is_removed() {
    String relType = REL_TYPE_BIDIRECTIONAL_UID;
    String fromTeiUid = CodeGenerator.generateUid();
    String toTeiUid = CodeGenerator.generateUid();
    Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
    Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).from(RelationshipItem.builder().trackedEntity(toTeiUid).build()).to(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).build();
    TrackerBundle bundle = TrackerBundle.builder().preheat(this.preheat).relationships(Lists.newArrayList(relationship1, relationship2)).build();
    preProcessor.process(bundle);
    assertThat(bundle.getRelationships(), hasSize(1));
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 23 with Relationship

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

the class PreCheckMandatoryFieldsValidationHookTest method verifyRelationshipValidationFailsOnMissingFrom.

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

Example 24 with Relationship

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

the class PreCheckMandatoryFieldsValidationHookTest method verifyRelationshipValidationFailsOnMissingTo.

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

Example 25 with Relationship

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

the class PreCheckMandatoryFieldsValidationHookTest method verifyRelationshipValidationFailsOnMissingRelationshipType.

@Test
void verifyRelationshipValidationFailsOnMissingRelationshipType() {
    Relationship relationship = Relationship.builder().relationship(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);
    assertMissingPropertyForRelationship(reporter, relationship.getUid(), "relationshipType");
}
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