Search in sources :

Example 1 with TrackerBundle

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

the class EventStatusPreProcessorTest method testVisitedStatusIsConvertedToActive.

@Test
void testVisitedStatusIsConvertedToActive() {
    // Given
    Event event = new Event();
    event.setStatus(EventStatus.VISITED);
    event.setProgramStage("programStageUid");
    TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setUid("programInstanceUid");
    Program program = new Program();
    program.setUid("programUid");
    ProgramStage programStage = new ProgramStage();
    programStage.setUid("programStageUid");
    programStage.setProgram(program);
    TrackerPreheat preheat = new TrackerPreheat();
    preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
    preheat.put(TrackerIdentifier.UID, programStage);
    bundle.setPreheat(preheat);
    // When
    preProcessorToTest.process(bundle);
    // Then
    assertEquals(EventStatus.ACTIVE, bundle.getEvents().get(0).getStatus());
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 2 with TrackerBundle

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

the class StrategyPreProcessorTest method testStrategyPreprocessForCreateAndUpdate.

@Test
void testStrategyPreprocessForCreateAndUpdate() {
    TrackerBundle bundle = TrackerBundle.builder().trackedEntities(Lists.newArrayList(trackedEntity, newTrackedEntity)).enrollments(Lists.newArrayList(enrollment, newEnrollment)).events(Lists.newArrayList(event, newEvent)).relationships(Lists.newArrayList(payloadRelationship, newPayloadRelationship)).importStrategy(TrackerImportStrategy.CREATE_AND_UPDATE).preheat(preheat).build();
    preProcessorToTest.process(bundle);
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.TRACKED_ENTITY).get(TEI_UID), Matchers.is(TrackerImportStrategy.UPDATE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.TRACKED_ENTITY).get(NEW_TEI_UID), Matchers.is(TrackerImportStrategy.CREATE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.ENROLLMENT).get(ENROLLMENT_UID), Matchers.is(TrackerImportStrategy.UPDATE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.ENROLLMENT).get(NEW_ENROLLMENT_UID), Matchers.is(TrackerImportStrategy.CREATE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(EVENT_UID), Matchers.is(TrackerImportStrategy.UPDATE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(NEW_EVENT_UID), Matchers.is(TrackerImportStrategy.CREATE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.RELATIONSHIP).get(RELATIONSHIP_UID), Matchers.is(TrackerImportStrategy.UPDATE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.RELATIONSHIP).get(NEW_RELATIONSHIP_UID), Matchers.is(TrackerImportStrategy.CREATE));
}
Also used : TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 3 with TrackerBundle

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

the class StrategyPreProcessorTest method testStrategyPreprocessForDelete.

@Test
void testStrategyPreprocessForDelete() {
    TrackerBundle bundle = TrackerBundle.builder().trackedEntities(Lists.newArrayList(trackedEntity, newTrackedEntity)).enrollments(Lists.newArrayList(enrollment, newEnrollment)).events(Lists.newArrayList(event, newEvent)).relationships(Lists.newArrayList(payloadRelationship, newPayloadRelationship)).importStrategy(TrackerImportStrategy.DELETE).preheat(preheat).build();
    preProcessorToTest.process(bundle);
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.TRACKED_ENTITY).get(TEI_UID), Matchers.is(TrackerImportStrategy.DELETE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.TRACKED_ENTITY).get(NEW_TEI_UID), Matchers.is(TrackerImportStrategy.DELETE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.ENROLLMENT).get(ENROLLMENT_UID), Matchers.is(TrackerImportStrategy.DELETE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.ENROLLMENT).get(NEW_ENROLLMENT_UID), Matchers.is(TrackerImportStrategy.DELETE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(EVENT_UID), Matchers.is(TrackerImportStrategy.DELETE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.EVENT).get(NEW_EVENT_UID), Matchers.is(TrackerImportStrategy.DELETE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.RELATIONSHIP).get(RELATIONSHIP_UID), Matchers.is(TrackerImportStrategy.DELETE));
    assertThat(bundle.getResolvedStrategyMap().get(TrackerType.RELATIONSHIP).get(NEW_RELATIONSHIP_UID), Matchers.is(TrackerImportStrategy.DELETE));
}
Also used : TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 4 with TrackerBundle

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

the class DuplicateRelationshipsPreProcessorTest method test_relationshipIsIgnored_on_null_relType.

@Test
void test_relationshipIsIgnored_on_null_relType() {
    String relType = CodeGenerator.generateUid();
    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(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(2));
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 5 with TrackerBundle

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

the class DuplicateRelationshipsPreProcessorTest method test_on_identical_but_inverted_rels_none_is_removed.

/*
     * Verifies that:
     *
     * - given 2 relationships having identical but "inverted" data
     *
     * - none is removed
     */
@Test
void test_on_identical_but_inverted_rels_none_is_removed() {
    String relType = REL_TYPE_NONBIDIRECTIONAL_UID;
    String fromTeiUid = CodeGenerator.generateUid();
    String toTeiUid = CodeGenerator.generateUid();
    Relationship relationship1 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).bidirectional(false).from(RelationshipItem.builder().trackedEntity(fromTeiUid).build()).to(RelationshipItem.builder().trackedEntity(toTeiUid).build()).build();
    Relationship relationship2 = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(relType).bidirectional(false).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(2));
}
Also used : Relationship(org.hisp.dhis.tracker.domain.Relationship) 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