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());
}
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));
}
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));
}
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));
}
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));
}
Aggregations