use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationFailsOnFromWithMultipleDataset.
@Test
void verifyValidationFailsOnFromWithMultipleDataset() {
String relationshipUid = "nBx6auGDUHG";
Relationship relationship = Relationship.builder().relationship(relationshipUid).relationshipType(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).enrollment(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().trackedEntity(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);
assertTrue(reporter.hasErrors());
assertThat(reporter.getReportList().get(0).getErrorCode(), is(TrackerErrorCode.E4001));
assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Item `from` 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 verifyValidationFailsOnInvalidRelationshipType.
@Test
void verifyValidationFailsOnInvalidRelationshipType() {
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType("do-not-exist").from(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).build();
reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
hasTrackerError(reporter, E4009, RELATIONSHIP, relationship.getUid());
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationFailsOnFromWithNoDataset.
@Test
void verifyValidationFailsOnFromWithNoDataset() {
String relationshipUid = "nBx6auGDUHG";
Relationship relationship = Relationship.builder().relationship(relationshipUid).relationshipType(CodeGenerator.generateUid()).from(RelationshipItem.builder().build()).to(RelationshipItem.builder().trackedEntity(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, E4013, RELATIONSHIP, relationship.getUid());
assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Type `from` constraint is missing trackedEntity."));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationFailsOnInvalidFromTrackedEntityType.
@Test
void verifyValidationFailsOnInvalidFromTrackedEntityType() {
RelationshipType relType = createRelTypeConstraint(TRACKED_ENTITY_INSTANCE, PROGRAM_INSTANCE);
String trackedEntityUid = CodeGenerator.generateUid();
TrackedEntityType constraintTrackedEntityType = new TrackedEntityType();
constraintTrackedEntityType.setUid(CodeGenerator.generateUid());
relType.getFromConstraint().setTrackedEntityType(constraintTrackedEntityType);
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(trackedEntityUid).build()).to(RelationshipItem.builder().enrollment(CodeGenerator.generateUid()).build()).relationshipType(relType.getUid()).build();
when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relType));
List<TrackedEntity> trackedEntities = new ArrayList<>();
TrackedEntity trackedEntity = new TrackedEntity();
trackedEntity.setTrackedEntity(trackedEntityUid);
trackedEntity.setTrackedEntityType(CodeGenerator.generateUid());
trackedEntities.add(trackedEntity);
when(bundle.getTrackedEntities()).thenReturn(trackedEntities);
reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
hasTrackerError(reporter, E4014, RELATIONSHIP, relationship.getUid());
assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Type `from` constraint requires a Tracked Entity having type `" + constraintTrackedEntityType.getUid() + "` but `" + trackedEntity.getTrackedEntityType() + "` was found."));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class RelationshipsValidationHookTest method verifyValidationFailsOnInvalidToTrackedEntityType.
@Test
void verifyValidationFailsOnInvalidToTrackedEntityType() {
RelationshipType relType = createRelTypeConstraint(PROGRAM_INSTANCE, TRACKED_ENTITY_INSTANCE);
String trackedEntityUid = CodeGenerator.generateUid();
TrackedEntityType constraintTrackedEntityType = new TrackedEntityType();
constraintTrackedEntityType.setUid(CodeGenerator.generateUid());
relType.getToConstraint().setTrackedEntityType(constraintTrackedEntityType);
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).from(RelationshipItem.builder().enrollment(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().trackedEntity(trackedEntityUid).build()).relationshipType(relType.getUid()).build();
when(preheat.getAll(RelationshipType.class)).thenReturn(Collections.singletonList(relType));
TrackedEntityType teiTrackedEntityType = new TrackedEntityType();
teiTrackedEntityType.setUid(CodeGenerator.generateUid());
TrackedEntityInstance trackedEntityInstance = new TrackedEntityInstance();
trackedEntityInstance.setUid(trackedEntityUid);
trackedEntityInstance.setTrackedEntityType(teiTrackedEntityType);
when(ctx.getTrackedEntityInstance(trackedEntityUid)).thenReturn(trackedEntityInstance);
reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
hasTrackerError(reporter, E4014, RELATIONSHIP, relationship.getUid());
assertThat(reporter.getReportList().get(0).getErrorMessage(), is("Relationship Type `to` constraint requires a Tracked Entity having type `" + constraintTrackedEntityType.getUid() + "` but `" + teiTrackedEntityType.getUid() + "` was found."));
}
Aggregations