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));
}
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));
}
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");
}
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");
}
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");
}
Aggregations