Search in sources :

Example 96 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter 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."));
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Relationship(org.hisp.dhis.tracker.domain.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ArrayList(java.util.ArrayList) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 97 with ValidationErrorReporter

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

Example 98 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class RelationshipsValidationHookTest method verifyValidationFailsOnInvalidToConstraint.

@Test
void verifyValidationFailsOnInvalidToConstraint() {
    RelationshipType relType = createRelTypeConstraint(TRACKED_ENTITY_INSTANCE, TRACKED_ENTITY_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 trackedEntity but a enrollment was found."));
}
Also used : 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 99 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class TrackedEntityAttributeValidationHookTest method shouldFailOptionSetNotValid.

@Test
void shouldFailOptionSetNotValid() {
    TrackedEntityAttribute trackedEntityAttribute = getTrackedEntityAttributeWithOptionSet();
    when(validationContext.getTrackedEntityAttribute(anyString())).thenReturn(trackedEntityAttribute);
    when(validationContext.getTrackedEntityType(anyString())).thenReturn(new TrackedEntityType());
    TrackedEntity trackedEntity = TrackedEntity.builder().attributes(Collections.singletonList(Attribute.builder().attribute("uid").value("wrongCode").build())).trackedEntityType("trackedEntityType").build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
    assertTrue(reporter.hasErrors());
    assertEquals(1, reporter.getReportList().size());
    assertEquals(1, reporter.getReportList().stream().filter(e -> e.getErrorCode() == TrackerErrorCode.E1125).count());
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 100 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class TrackedEntityAttributeValidationHookTest method shouldFailValidationWhenValueIsNullAndAttributeIsMandatory.

@Test
void shouldFailValidationWhenValueIsNullAndAttributeIsMandatory() {
    TrackedEntity trackedEntity = TrackedEntity.builder().attributes(Collections.singletonList(Attribute.builder().attribute("trackedEntityAttribute").build())).trackedEntityType("trackedEntityType").build();
    TrackedEntityTypeAttribute trackedEntityTypeAttribute = new TrackedEntityTypeAttribute();
    TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
    trackedEntityAttribute.setUid("trackedEntityAttribute");
    trackedEntityAttribute.setValueType(ValueType.TEXT);
    trackedEntityTypeAttribute.setTrackedEntityAttribute(trackedEntityAttribute);
    trackedEntityTypeAttribute.setMandatory(true);
    TrackedEntityType trackedEntityType = new TrackedEntityType();
    trackedEntityType.setTrackedEntityTypeAttributes(Collections.singletonList(trackedEntityTypeAttribute));
    when(validationContext.getTrackedEntityAttribute("trackedEntityAttribute")).thenReturn(trackedEntityAttribute);
    when(validationContext.getTrackedEntityType(anyString())).thenReturn(trackedEntityType);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
    assertTrue(reporter.hasErrors());
    assertEquals(1, reporter.getReportList().size());
    assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) 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