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