Search in sources :

Example 86 with Event

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

the class PreCheckExistenceValidationHookTest method verifyEventValidationFailsWhenIsSoftDeleted.

@Test
void verifyEventValidationFailsWhenIsSoftDeleted() {
    // given
    Event event = Event.builder().event(SOFT_DELETED_EVENT_UID).build();
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1082, 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)

Example 87 with Event

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

the class PreCheckMetaValidationHookTest method verifyEventValidationFailsWhenOrgUnitIsNotPresentInDb.

@Test
void verifyEventValidationFailsWhenOrgUnitIsNotPresentInDb() {
    // given
    Event event = validEvent();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    // when
    when(ctx.getProgram(PROGRAM_UID)).thenReturn(new Program());
    when(ctx.getProgramStage(PROGRAM_STAGE_UID)).thenReturn(new ProgramStage());
    validatorToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1011, EVENT, event.getUid());
}
Also used : Program(org.hisp.dhis.program.Program) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 88 with Event

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

the class PreCheckMetaValidationHookTest method verifyEventValidationFailsWhenProgramStageIsNotPresentInDb.

@Test
void verifyEventValidationFailsWhenProgramStageIsNotPresentInDb() {
    // given
    Event event = validEvent();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    // when
    when(ctx.getOrganisationUnit(ORG_UNIT_UID)).thenReturn(new OrganisationUnit());
    when(ctx.getProgram(PROGRAM_UID)).thenReturn(new Program());
    validatorToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1013, EVENT, event.getUid());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 89 with Event

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

the class PreCheckMetaValidationHookTest method verifyEventValidationFailsWhenProgramIsNotPresentInDb.

@Test
void verifyEventValidationFailsWhenProgramIsNotPresentInDb() {
    // given
    Event event = validEvent();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    // when
    when(ctx.getOrganisationUnit(ORG_UNIT_UID)).thenReturn(new OrganisationUnit());
    when(ctx.getProgramStage(PROGRAM_STAGE_UID)).thenReturn(new ProgramStage());
    validatorToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1010, EVENT, event.getUid());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 90 with Event

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

the class EventDateValidationHookTest method testEventIsNotValidWhenDateBelongsToExpiredPeriod.

@Test
void testEventIsNotValidWhenDateBelongsToExpiredPeriod() {
    // given
    Event event = new Event();
    event.setEvent(CodeGenerator.generateUid());
    event.setProgram(PROGRAM_WITH_REGISTRATION_ID);
    event.setOccurredAt(sevenDaysAgo());
    event.setStatus(EventStatus.ACTIVE);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    this.hookToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1047, 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)

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