use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEventValidationSuccess.
@Test
void verifyEventValidationSuccess() {
// given
Note note = Note.builder().note(CodeGenerator.generateUid()).build();
Event event = Event.builder().event(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEvent(reporter, event);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEventWithNoteWithInvalidUidFails.
@Test
void verifyEventWithNoteWithInvalidUidFails() {
// given
Note note = Note.builder().note(INVALID_UID).build();
Event event = Event.builder().event(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEvent(reporter, event);
// then
hasTrackerError(reporter, E1048, EVENT, event.getUid());
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter 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.report.ValidationErrorReporter 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.report.ValidationErrorReporter 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."));
}
Aggregations