Search in sources :

Example 91 with ValidationErrorReporter

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());
}
Also used : Note(org.hisp.dhis.tracker.domain.Note) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 92 with ValidationErrorReporter

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());
}
Also used : Note(org.hisp.dhis.tracker.domain.Note) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 93 with ValidationErrorReporter

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."));
}
Also used : RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) Relationship(org.hisp.dhis.tracker.domain.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 94 with ValidationErrorReporter

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());
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 95 with ValidationErrorReporter

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."));
}
Also used : RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) Relationship(org.hisp.dhis.tracker.domain.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)206 Test (org.junit.jupiter.api.Test)192 Event (org.hisp.dhis.tracker.domain.Event)89 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)48 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)48 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)43 ProgramStage (org.hisp.dhis.program.ProgramStage)38 DataElement (org.hisp.dhis.dataelement.DataElement)25 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)25 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)24 Relationship (org.hisp.dhis.tracker.domain.Relationship)23 DataValue (org.hisp.dhis.tracker.domain.DataValue)21 Program (org.hisp.dhis.program.Program)19 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)17 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)16 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 RelationshipType (org.hisp.dhis.relationship.RelationshipType)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)11