use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceTest method failFastModePreventsFurtherValidationAfterFirstErrorIsAdded.
@Test
void failFastModePreventsFurtherValidationAfterFirstErrorIsAdded() {
Event validEvent = event();
Event invalidEvent = event();
TrackerBundle bundle = newBundle().validationMode(ValidationMode.FAIL_FAST).events(events(invalidEvent, validEvent)).build();
ValidationHook hook1 = ValidationHook.builder().removeOnError(false).validateEvent((reporter, event) -> reporter.addErrorIf(() -> invalidEvent.equals(event), event, TrackerErrorCode.E1032)).build();
TrackerValidationHook hook2 = mock(TrackerValidationHook.class);
service = new DefaultTrackerValidationService(List.of(hook1, hook2), Collections.emptyList());
TrackerValidationReport report = service.validate(bundle);
assertTrue(report.hasErrors());
assertHasError(report, TrackerErrorCode.E1032, invalidEvent);
assertFalse(bundle.getEvents().contains(invalidEvent));
assertTrue(bundle.getEvents().contains(validEvent));
verifyNoInteractions(hook2);
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class TrackerBundleParamsConverterTest method createEvent.
private List<Event> createEvent(int size, String uid, String parent) {
List<Event> events = new ArrayList<>();
for (int i = 0; i < size; i++) {
Event event = rnd.nextObject(Event.class);
event.setGeometry(null);
event.setEvent(uid + i);
event.setEnrollment(parent);
events.add(event);
}
return events;
}
use of org.hisp.dhis.tracker.domain.Event 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.Event in project dhis2-core by dhis2.
the class TrackerCsvEventServiceTest method testReadEventsFromFileWithHeader.
@Test
void testReadEventsFromFileWithHeader() throws IOException, ParseException {
File event = new File("src/test/resources/controller/tracker/csv/event.csv");
InputStream inputStream = Files.asByteSource(event).openStream();
List<Event> events = serviceToTest.readEvents(inputStream, true);
assertFalse(events.isEmpty());
assertEquals(1, events.size());
assertEquals("eventId", events.get(0).getEvent());
assertEquals("programId", events.get(0).getProgram());
assertEquals("programStageId", events.get(0).getProgramStage());
assertEquals("orgUnitId", events.get(0).getOrgUnit());
assertEquals("2018-11-01T00:00:00Z", events.get(0).getOccurredAt().toString());
assertEquals(EventStatus.ACTIVE, events.get(0).getStatus());
assertNull(events.get(0).getEnrollment());
assertNull(events.get(0).getCreatedAt());
assertNull(events.get(0).getCreatedAtClient());
assertNull(events.get(0).getUpdatedAt());
assertNull(events.get(0).getUpdatedAtClient());
assertNull(events.get(0).getScheduledAt());
assertNull(events.get(0).getCompletedAt());
assertNull(events.get(0).getCompletedBy());
assertNull(events.get(0).getStoredBy());
assertNull(events.get(0).getAttributeOptionCombo());
assertNull(events.get(0).getAttributeCategoryOptions());
assertNull(events.get(0).getAssignedUser());
assertTrue(events.get(0).getDataValues().isEmpty());
assertTrue(events.get(0).getRelationships().isEmpty());
assertTrue(events.get(0).getNotes().isEmpty());
}
use of org.hisp.dhis.tracker.domain.Event 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());
}
Aggregations