Search in sources :

Example 91 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class EventDateValidationHookTest method testEventIsNotValidWhenOccurredDateIsNotPresentAndEventIsActive.

@Test
void testEventIsNotValidWhenOccurredDateIsNotPresentAndEventIsActive() {
    // given
    Event event = new Event();
    event.setEvent(CodeGenerator.generateUid());
    event.setProgram(PROGRAM_WITH_REGISTRATION_ID);
    event.setStatus(EventStatus.ACTIVE);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    this.hookToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1031, EVENT, event.getUid());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 92 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class EventDateValidationHookTest method testEventIsNotValidWhenOccurredDateIsNotPresentAndProgramIsWithoutRegistration.

@Test
void testEventIsNotValidWhenOccurredDateIsNotPresentAndProgramIsWithoutRegistration() {
    // given
    Event event = new Event();
    event.setEvent(CodeGenerator.generateUid());
    event.setProgram(PROGRAM_WITHOUT_REGISTRATION_ID);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    this.hookToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1031, EVENT, event.getUid());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 93 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class EventDateValidationHookTest method testEventIsNotValidWhenCompletedAtIsNotPresentAndEventIsCompleted.

@Test
void testEventIsNotValidWhenCompletedAtIsNotPresentAndEventIsCompleted() {
    // given
    Event event = new Event();
    event.setEvent(CodeGenerator.generateUid());
    event.setProgram(PROGRAM_WITH_REGISTRATION_ID);
    event.setOccurredAt(now());
    event.setStatus(EventStatus.COMPLETED);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    this.hookToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1042, EVENT, event.getUid());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 94 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHookTest method verifyEventValidationSuccessWhenIsUpdate.

@Test
void verifyEventValidationSuccessWhenIsUpdate() {
    // given
    Event event = Event.builder().event(EVENT_UID).build();
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEvent(reporter, event);
    // then
    assertFalse(reporter.hasErrors());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 95 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHookTest method verifyEventValidationFailsWhenIsCreateAndEventIsAlreadyPresent.

@Test
void verifyEventValidationFailsWhenIsCreateAndEventIsAlreadyPresent() {
    // given
    Event event = Event.builder().event(EVENT_UID).build();
    // when
    when(ctx.getStrategy(event)).thenReturn(TrackerImportStrategy.CREATE);
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1030, EVENT, event.getUid());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) 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