Search in sources :

Example 51 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class DuplicateRelationshipsPreProcessorTest method test_on_identical_rels_relType_bi_1_is_removed.

/*
     * Verifies that:
     *
     * - given 2 identical relationships
     *
     * - and relationship type's bidirectional property = true
     *
     * - one is removed
     */
@Test
void test_on_identical_rels_relType_bi_1_is_removed() {
    String relType = REL_TYPE_BIDIRECTIONAL_UID;
    String fromTeiUid = CodeGenerator.generateUid();
    String toTeiUid = CodeGenerator.generateUid();
    Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).bidirectional(true).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
    Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).bidirectional(true).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
    TrackerBundle bundle = TrackerBundle.builder().preheat(this.preheat).relationships(Lists.newArrayList(relationship1, relationship2)).build();
    preProcessor.process(bundle);
    assertThat(bundle.getRelationships(), hasSize(1));
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 52 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class DuplicateRelationshipsPreProcessorTest method test_on_different_rels_none_is_removed.

/*
     * Verifies that:
     *
     * - given 2 non-identical relationships
     *
     * - none is removed
     */
@Test
void test_on_different_rels_none_is_removed() {
    String fromTeiUid = CodeGenerator.generateUid();
    String toTeiUid = CodeGenerator.generateUid();
    Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(REL_TYPE_NONBIDIRECTIONAL_UID).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
    Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(REL_TYPE_NONBIDIRECTIONAL_UID).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().enrollment(toTeiUid).build()).build();
    TrackerBundle bundle = TrackerBundle.builder().preheat(this.preheat).relationships(Lists.newArrayList(relationship1, relationship2)).build();
    preProcessor.process(bundle);
    assertThat(bundle.getRelationships(), hasSize(2));
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 53 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class DuplicateRelationshipsPreProcessorTest method test_on_identical_rels_but_inverted_type_bi_1_is_removed.

/*
     * Verifies that:
     *
     * - given 2 identical relationships having identical but "inverted" data
     *
     * - and relationship type's bidirectional property = true
     *
     * - none is removed
     */
@Test
void test_on_identical_rels_but_inverted_type_bi_1_is_removed() {
    String relType = REL_TYPE_BIDIRECTIONAL_UID;
    String fromTeiUid = CodeGenerator.generateUid();
    String toTeiUid = CodeGenerator.generateUid();
    Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
    Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).from(RelationshipItem.builder().trackedEntity(toTeiUid).build()).to(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).build();
    TrackerBundle bundle = TrackerBundle.builder().preheat(this.preheat).relationships(Lists.newArrayList(relationship1, relationship2)).build();
    preProcessor.process(bundle);
    assertThat(bundle.getRelationships(), hasSize(1));
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 54 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class EventProgramPreProcessorTest method testProgramEventIsEnhancedWithProgram.

@Test
void testProgramEventIsEnhancedWithProgram() {
    // Given
    TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(programEventWithProgramStage())).preheat(preheat).build();
    // When
    preProcessorToTest.process(bundle);
    // Then
    verify(preheat).put(TrackerIdentifier.UID, programWithoutRegistration());
    assertEquals(PROGRAM_WITHOUT_REGISTRATION, bundle.getEvents().get(0).getProgram());
}
Also used : TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 55 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class EventProgramPreProcessorTest method testTrackerEventIsNotEnhancedWithProgramStage.

@Test
void testTrackerEventIsNotEnhancedWithProgramStage() {
    // Given
    Event event = trackerEventWithProgram();
    TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).preheat(preheat).build();
    // When
    preProcessorToTest.process(bundle);
    // Then
    assertEquals(PROGRAM_WITH_REGISTRATION, bundle.getEvents().get(0).getProgram());
    assertNull(bundle.getEvents().get(0).getProgramStage());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)74 Test (org.junit.jupiter.api.Test)43 Event (org.hisp.dhis.tracker.domain.Event)29 User (org.hisp.dhis.user.User)21 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)19 List (java.util.List)17 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)15 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 Mockito.mock (org.mockito.Mockito.mock)14 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)13 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)12 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)12 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)12 Collections (java.util.Collections)11 ProgramStage (org.hisp.dhis.program.ProgramStage)11 Objects (java.util.Objects)10 Program (org.hisp.dhis.program.Program)10 ValidationMode (org.hisp.dhis.tracker.ValidationMode)10 Relationship (org.hisp.dhis.tracker.domain.Relationship)10