use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHookTest method verifyRelationshipValidationSuccessWhenIsCreate.
@Test
void verifyRelationshipValidationSuccessWhenIsCreate() {
// given
Relationship rel = Relationship.builder().relationship(NOT_PRESENT_RELATIONSHIP_UID).build();
// when
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, rel);
// then
assertFalse(reporter.hasErrors());
assertThat(reporter.getWarningsReportList(), empty());
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHookTest method verifyRelationshipValidationFailsWhenUpdate.
@Test
void verifyRelationshipValidationFailsWhenUpdate() {
// given
Relationship rel = getPayloadRelationship();
// when
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, rel);
// then
assertFalse(reporter.hasErrors());
assertTrue(reporter.hasWarningReport(r -> E4015.equals(r.getWarningCode()) && TrackerType.RELATIONSHIP.equals(r.getTrackerType()) && rel.getUid().equals(r.getUid())));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationSuccessWhenSomeObjectsFailButNoParentObject.
@Test
void verifyValidationSuccessWhenSomeObjectsFailButNoParentObject() {
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("anotherValidTrackedEntity").build()).relationshipType(relType.getUid()).build();
TrackerErrorReport error = TrackerErrorReport.builder().uid("notValidTrackedEntity").trackerType(TRACKED_ENTITY).errorCode(TrackerErrorCode.E9999).build(bundle);
reporter.addError(error);
validationHook.validateRelationship(reporter, relationship);
assertTrue(reporter.hasErrors());
assertThat(reporter.getReportList().stream().map(TrackerErrorReport::getErrorCode).collect(Collectors.toList()), not(hasItem(TrackerErrorCode.E4011)));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationFailsOnInvalidFromConstraint.
@Test
void verifyValidationFailsOnInvalidFromConstraint() {
RelationshipType relType = createRelTypeConstraint(PROGRAM_INSTANCE, TRACKED_ENTITY_INSTANCE);
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().event(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().trackedEntity(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 `from` constraint requires a enrollment but a event was found."));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyFailAuto.
@Test
void verifyFailAuto() {
RelationshipType relType = createRelTypeConstraint(TRACKED_ENTITY_INSTANCE, TRACKED_ENTITY_INSTANCE);
String uid = CodeGenerator.generateUid();
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(uid).build()).to(RelationshipItem.builder().trackedEntity(uid).build()).relationshipType(relType.getUid()).build();
when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relType));
reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
hasTrackerError(reporter, E4000, RELATIONSHIP, relationship.getUid());
assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship: `" + relationship.getRelationship() + "` cannot link to itself"));
}
Aggregations