use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class TrackerBundleParamsConverterTest method verifyUidIsAssignedWhenMissing.
@Test
void verifyUidIsAssignedWhenMissing() throws IOException {
List<Relationship> relationships1 = createRelationships(2, null);
List<Relationship> relationships2 = createRelationships(2, "rel2");
List<Event> events1 = createEvent(3, null, null);
List<Event> events2 = createEvent(7, null, null);
List<Enrollment> enrollments = new ArrayList<>();
Enrollment enrollment1 = createEnrollment(null, null, events1);
Enrollment enrollment2 = createEnrollment(null, null, events2);
enrollment1.setRelationships(relationships1);
enrollment2.setRelationships(relationships2);
enrollments.add(enrollment1);
enrollments.add(enrollment2);
TrackedEntity trackedEntity = createTrackedEntity(null, enrollments);
trackedEntity.setRelationships(relationships1);
TrackerBundleParams build = TrackerBundleParams.builder().trackedEntities(Collections.singletonList(trackedEntity)).build();
String jsonPayload = toJson(build);
TrackerBundleParams b2 = this.objectMapper.readValue(jsonPayload, TrackerBundleParams.class);
// TEI has uid
assertThat(b2.getTrackedEntities().get(0).getTrackedEntity(), is(notNullValue()));
// Also check parent uid is set
assertThat(b2.getEnrollments().get(0).getTrackedEntity(), is(b2.getTrackedEntities().get(0).getTrackedEntity()));
assertThat(b2.getEnrollments().get(0).getEnrollment(), is(notNullValue()));
// Also check parent uid is set
assertThat(b2.getEnrollments().get(1).getTrackedEntity(), is(b2.getTrackedEntities().get(0).getTrackedEntity()));
assertThat(b2.getEnrollments().get(1).getEnrollment(), is(notNullValue()));
assertThat(b2.getEvents().get(0).getEvent(), is(notNullValue()));
assertThat(b2.getEvents().get(1).getEvent(), is(notNullValue()));
assertThat(b2.getRelationships(), hasSize(4));
b2.getRelationships().stream().forEach(r -> assertThat(r.getRelationship(), is(notNullValue())));
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class TrackerBundleParamsConverterTest method verifyNestedTeiStructureHasNestedDataClearedAfterFlattening.
@Test
void verifyNestedTeiStructureHasNestedDataClearedAfterFlattening() throws IOException {
List<Relationship> relationships1 = createRelationships(2, "rel1");
List<Relationship> relationships2 = createRelationships(2, "rel2");
List<Event> events1 = createEvent(3, "ev1", "enr1");
List<Event> events2 = createEvent(7, "ev2", "enr2");
List<Enrollment> enrollments = new ArrayList<>();
Enrollment enrollment1 = createEnrollment("enr1", "teiABC", events1);
Enrollment enrollment2 = createEnrollment("enr2", "teiABC", events2);
enrollment1.setRelationships(relationships2);
enrollment2.setRelationships(relationships1);
enrollments.add(enrollment1);
enrollments.add(enrollment2);
TrackedEntity trackedEntity = createTrackedEntity("teiABC", enrollments);
trackedEntity.setRelationships(relationships1);
TrackerBundleParams build = TrackerBundleParams.builder().trackedEntities(Collections.singletonList(trackedEntity)).build();
String jsonPayload = toJson(build);
TrackerBundleParams b2 = this.objectMapper.readValue(jsonPayload, TrackerBundleParams.class);
assertThat(b2.getTrackedEntities().get(0).getEnrollments(), hasSize(0));
assertThat(b2.getTrackedEntities().get(0).getRelationships(), hasSize(0));
assertThat(b2.getEnrollments().get(0).getEvents(), hasSize(0));
assertThat(b2.getEnrollments().get(0).getRelationships(), hasSize(0));
assertThat(b2.getEvents().get(0).getRelationships(), hasSize(0));
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class TrackerBundleParamsConverterTest method createEnrollment.
private Enrollment createEnrollment(String uid, String parent, List<Event> events) {
Enrollment enrollment = rnd.nextObject(Enrollment.class);
enrollment.setGeometry(null);
enrollment.setEnrollment(uid);
enrollment.setTrackedEntity(parent);
enrollment.setEvents(events);
return enrollment;
}
Aggregations