use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationFailsOnToWithMultipleDataset.
@Test
void verifyValidationFailsOnToWithMultipleDataset() {
String relationshipUid = "nBx6auGDUHG";
Relationship relationship = Relationship.builder().relationship(relationshipUid).relationshipType(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).enrollment(CodeGenerator.generateUid()).build()).build();
RelationshipType relationshipType = new RelationshipType();
relationshipType.setUid(relationship.getRelationshipType());
RelationshipConstraint constraint = new RelationshipConstraint();
constraint.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
relationshipType.setFromConstraint(constraint);
relationshipType.setToConstraint(constraint);
when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relationshipType));
reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
hasTrackerError(reporter, E4001, RELATIONSHIP, relationship.getUid());
assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Item `to` for Relationship `nBx6auGDUHG` is invalid: an Item can link only one Tracker entity."));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationFailsWhenParentObjectFailed.
@Test
void verifyValidationFailsWhenParentObjectFailed() {
RelationshipType relType = createRelTypeConstraint(TRACKED_ENTITY_INSTANCE, TRACKED_ENTITY_INSTANCE);
when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relType));
reporter = new ValidationErrorReporter(ctx);
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity("validTrackedEntity").build()).to(RelationshipItem.builder().trackedEntity("notValidTrackedEntity").build()).relationshipType(relType.getUid()).build();
TrackerErrorReport error = TrackerErrorReport.builder().uid(relationship.getTo().getTrackedEntity()).trackerType(TRACKED_ENTITY).errorCode(TrackerErrorCode.E9999).build(bundle);
reporter.addError(error);
validationHook.validateRelationship(reporter, relationship);
hasTrackerError(reporter, TrackerErrorCode.E4011, RELATIONSHIP, relationship.getUid());
assertThat(reporter.getReportList().stream().map(TrackerErrorReport::getErrorMessage).collect(Collectors.toList()), hasItem("Relationship: `" + relationship.getRelationship() + "` cannot be persisted because trackedEntity notValidTrackedEntity referenced by this relationship is not valid."));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationFailsOnInvalidToConstraintOfTypeProgramStage.
@Test
void verifyValidationFailsOnInvalidToConstraintOfTypeProgramStage() {
RelationshipType relType = createRelTypeConstraint(TRACKED_ENTITY_INSTANCE, PROGRAM_STAGE_INSTANCE);
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().enrollment(CodeGenerator.generateUid()).build()).relationshipType(relType.getUid()).build();
when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relType));
reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
hasTrackerError(reporter, E4010, RELATIONSHIP, relationship.getUid());
assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Type `to` constraint requires a event but a enrollment was found."));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class PreCheckMetaValidationHookTest method verifyRelationshipValidationSuccess.
@Test
void verifyRelationshipValidationSuccess() {
// given
Relationship relationship = validRelationship();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
// when
when(ctx.getRelationShipType(RELATIONSHIP_TYPE_UID)).thenReturn(new RelationshipType());
validatorToTest.validateRelationship(reporter, relationship);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class PreCheckMetaValidationHookTest method verifyRelationshipValidationFailsWhenRelationshipTypeIsNotPresentInDb.
@Test
void verifyRelationshipValidationFailsWhenRelationshipTypeIsNotPresentInDb() {
// given
Relationship relationship = validRelationship();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
// when
validatorToTest.validateRelationship(reporter, relationship);
// then
hasTrackerError(reporter, E4006, RELATIONSHIP, relationship.getUid());
}
Aggregations