use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class DuplicateRelationshipsPreProcessorTest method test_relationshipIsIgnored_on_null_relType.
@Test
void test_relationshipIsIgnored_on_null_relType() {
String relType = CodeGenerator.generateUid();
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(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(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_but_inverted_rels_none_is_removed.
/*
* Verifies that:
*
* - given 2 relationships having identical but "inverted" data
*
* - none is removed
*/
@Test
void test_on_identical_but_inverted_rels_none_is_removed() {
String relType = REL_TYPE_NONBIDIRECTIONAL_UID;
String fromTeiUid = CodeGenerator.generateUid();
String toTeiUid = CodeGenerator.generateUid();
Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).bidirectional(false).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).bidirectional(false).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(2));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class BidirectionalRelationshipsPreProcessorTest method testPreprocessorPopulateRelationshipBidirectionalFieldCorrectly.
@Test
void testPreprocessorPopulateRelationshipBidirectionalFieldCorrectly() {
Relationship uniDirectionalRelationship = new Relationship();
uniDirectionalRelationship.setRelationshipType(RELATIONSHIP_TYPE_UID);
uniDirectionalRelationship.setBidirectional(true);
Relationship biDirectionalRelationship = new Relationship();
biDirectionalRelationship.setRelationshipType(BIDIRECTIONAL_RELATIONSHIP_TYPE_UID);
biDirectionalRelationship.setBidirectional(false);
TrackerBundle bundle = TrackerBundle.builder().relationships(Lists.newArrayList(uniDirectionalRelationship, biDirectionalRelationship)).preheat(getPreheat()).build();
assertTrue(uniDirectionalRelationship.isBidirectional());
assertFalse(biDirectionalRelationship.isBidirectional());
preProcessorToTest.process(bundle);
assertFalse(uniDirectionalRelationship.isBidirectional());
assertTrue(biDirectionalRelationship.isBidirectional());
}
use of org.hisp.dhis.tracker.domain.Relationship 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.domain.Relationship in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method verifyValidationFailsWhenLinkedTrackedEntityIsNotFound.
@Test
void verifyValidationFailsWhenLinkedTrackedEntityIsNotFound() {
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);
assertTrue(reporter.hasErrors());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E4012));
assertThat(reporter.getReportList().stream().map(TrackerErrorReport::getErrorMessage).collect(Collectors.toList()), hasItem("Could not find `trackedEntity`: `validTrackedEntity`, linked to Relationship."));
assertThat(reporter.getReportList().stream().map(TrackerErrorReport::getErrorMessage).collect(Collectors.toList()), hasItem("Could not find `trackedEntity`: `anotherValidTrackedEntity`, linked to Relationship."));
}
Aggregations