use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class TrackerBundleParamsConverterTest method verifyNestedTeiStructureIsFlattenedDuringDeserialization.
@Test
void verifyNestedTeiStructureIsFlattenedDuringDeserialization() 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(), hasSize(1));
assertThat(b2.getEnrollments(), hasSize(2));
assertThat(b2.getEvents(), hasSize(10));
assertThat(b2.getRelationships(), hasSize(4));
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class TrackerBundleTest method testBasicSetup2.
@Test
void testBasicSetup2() {
TrackerBundle trackerBundle = TrackerBundle.builder().atomicMode(AtomicMode.ALL).validationMode(ValidationMode.SKIP).trackedEntities(Arrays.asList(new TrackedEntity(), new TrackedEntity())).enrollments(Arrays.asList(new Enrollment(), new Enrollment())).events(Arrays.asList(new Event(), new Event())).build();
assertEquals(AtomicMode.ALL, trackerBundle.getAtomicMode());
assertSame(trackerBundle.getValidationMode(), ValidationMode.SKIP);
assertEquals(2, trackerBundle.getTrackedEntities().size());
assertEquals(2, trackerBundle.getEnrollments().size());
assertEquals(2, trackerBundle.getEvents().size());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class LastUpdateImportTest method shouldUpdateTeiIfEnrollmentIsUpdated.
@Test
void shouldUpdateTeiIfEnrollmentIsUpdated() throws IOException {
TrackerImportParams trackerImportParams = fromJson("tracker/single_enrollment.json", user.getUid());
Date lastUpdateBefore = trackedEntityInstanceService.getTrackedEntityInstance(trackedEntity.getTrackedEntity()).getLastUpdated();
Enrollment enrollment = trackerImportParams.getEnrollments().get(0);
enrollment.setStatus(EnrollmentStatus.COMPLETED);
trackerImportParams.setImportStrategy(TrackerImportStrategy.UPDATE);
TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
manager.clear();
assertTrue(manager.get(TrackedEntityInstance.class, trackedEntity.getTrackedEntity()).getLastUpdated().getTime() > lastUpdateBefore.getTime());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckUpdatableFieldsValidationHookTest method verifyEnrollmentValidationSuccess.
@Test
void verifyEnrollmentValidationSuccess() {
// given
Enrollment enrollment = validEnrollment();
// when
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckUpdatableFieldsValidationHookTest method verifyEnrollmentValidationFailsWhenUpdateTrackedEntity.
@Test
void verifyEnrollmentValidationFailsWhenUpdateTrackedEntity() {
// given
Enrollment enrollment = validEnrollment();
enrollment.setTrackedEntity("NewTrackedEntityId");
// when
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
// then
hasTrackerError(reporter, E1127, ENROLLMENT, enrollment.getUid());
assertThat(reporter.getReportList().get(0).getErrorMessage(), containsString("trackedEntity"));
}
Aggregations