Search in sources :

Example 61 with Event

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArrayList(java.util.ArrayList) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AssertTrackerValidationReport.assertHasWarning(org.hisp.dhis.tracker.validation.hooks.AssertTrackerValidationReport.assertHasWarning) BiConsumer(java.util.function.BiConsumer) User(org.hisp.dhis.user.User) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Event(org.hisp.dhis.tracker.domain.Event) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ValidationMode(org.hisp.dhis.tracker.ValidationMode) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) AbstractTrackerDtoValidationHook(org.hisp.dhis.tracker.validation.hooks.AbstractTrackerDtoValidationHook) Mockito.verify(org.mockito.Mockito.verify) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Builder(lombok.Builder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) AssertTrackerValidationReport.assertHasError(org.hisp.dhis.tracker.validation.hooks.AssertTrackerValidationReport.assertHasError) CodeGenerator(org.hisp.dhis.common.CodeGenerator) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) AbstractTrackerDtoValidationHook(org.hisp.dhis.tracker.validation.hooks.AbstractTrackerDtoValidationHook) Test(org.junit.jupiter.api.Test)

Example 62 with Event

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;
}
Also used : ArrayList(java.util.ArrayList) Event(org.hisp.dhis.tracker.domain.Event)

Example 63 with Event

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));
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Relationship(org.hisp.dhis.tracker.domain.Relationship) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.tracker.domain.Event) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Test(org.junit.jupiter.api.Test)

Example 64 with Event

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());
}
Also used : InputStream(java.io.InputStream) Event(org.hisp.dhis.tracker.domain.Event) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 65 with Event

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());
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Event(org.hisp.dhis.tracker.domain.Event) Test(org.junit.jupiter.api.Test)

Aggregations

Event (org.hisp.dhis.tracker.domain.Event)192 Test (org.junit.jupiter.api.Test)153 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)114 ProgramStage (org.hisp.dhis.program.ProgramStage)68 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)64 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)53 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)43 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)41 Mockito.when (org.mockito.Mockito.when)38 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)37 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)36 DataElement (org.hisp.dhis.dataelement.DataElement)35 Program (org.hisp.dhis.program.Program)35 ProgramInstance (org.hisp.dhis.program.ProgramInstance)35 DataValue (org.hisp.dhis.tracker.domain.DataValue)35 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)35 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)34 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)33 CodeGenerator (org.hisp.dhis.common.CodeGenerator)32 BeforeEach (org.junit.jupiter.api.BeforeEach)32