Search in sources :

Example 26 with Relationship

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

Example 27 with Relationship

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())));
}
Also used : E1080(org.hisp.dhis.tracker.report.TrackerErrorCode.E1080) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) E1082(org.hisp.dhis.tracker.report.TrackerErrorCode.E1082) E1081(org.hisp.dhis.tracker.report.TrackerErrorCode.E1081) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Mock(org.mockito.Mock) TRACKED_ENTITY(org.hisp.dhis.tracker.TrackerType.TRACKED_ENTITY) E4015(org.hisp.dhis.tracker.report.TrackerErrorCode.E4015) E1002(org.hisp.dhis.tracker.report.TrackerErrorCode.E1002) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Relationship(org.hisp.dhis.tracker.domain.Relationship) E1063(org.hisp.dhis.tracker.report.TrackerErrorCode.E1063) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) EVENT(org.hisp.dhis.tracker.TrackerType.EVENT) E1114(org.hisp.dhis.tracker.report.TrackerErrorCode.E1114) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) E1113(org.hisp.dhis.tracker.report.TrackerErrorCode.E1113) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramInstance(org.hisp.dhis.program.ProgramInstance) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Event(org.hisp.dhis.tracker.domain.Event) Matchers.empty(org.hamcrest.Matchers.empty) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) AssertValidationErrorReporter.hasTrackerError(org.hisp.dhis.tracker.validation.hooks.AssertValidationErrorReporter.hasTrackerError) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ENROLLMENT(org.hisp.dhis.tracker.TrackerType.ENROLLMENT) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) E1032(org.hisp.dhis.tracker.report.TrackerErrorCode.E1032) Mockito.when(org.mockito.Mockito.when) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) E1030(org.hisp.dhis.tracker.report.TrackerErrorCode.E1030) Test(org.junit.jupiter.api.Test) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) Relationship(org.hisp.dhis.tracker.domain.Relationship) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 28 with Relationship

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

Example 29 with Relationship

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."));
}
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 30 with Relationship

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"));
}
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)

Aggregations

Relationship (org.hisp.dhis.tracker.domain.Relationship)38 Test (org.junit.jupiter.api.Test)34 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)23 RelationshipType (org.hisp.dhis.relationship.RelationshipType)14 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)9 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)7 ArrayList (java.util.ArrayList)6 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)6 Event (org.hisp.dhis.tracker.domain.Event)6 RelationshipConstraint (org.hisp.dhis.relationship.RelationshipConstraint)4 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)4 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)3 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)3 Collectors (java.util.stream.Collectors)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 CodeGenerator (org.hisp.dhis.common.CodeGenerator)2 ProgramInstance (org.hisp.dhis.program.ProgramInstance)2 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)2 ReferenceTrackerEntity (org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity)2 TrackerErrorReport (org.hisp.dhis.tracker.report.TrackerErrorReport)2