Search in sources :

Example 41 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class AssignedUserValidationHookTest method testEventWithNullEnabledUserAssignment.

@Test
void testEventWithNullEnabledUserAssignment() {
    // given
    Event event = new Event();
    event.setEvent(CodeGenerator.generateUid());
    event.setAssignedUser(USER_ID);
    event.setProgramStage(PROGRAM_STAGE);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    ProgramStage programStage = new ProgramStage();
    programStage.setEnableUserAssignment(null);
    when(validationContext.getProgramStage(PROGRAM_STAGE)).thenReturn(programStage);
    this.hookToTest.validateEvent(reporter, event);
    // then
    assertFalse(reporter.hasErrors());
    assertTrue(reporter.hasWarnings());
    assertTrue(reporter.hasWarningReport(r -> E1120.equals(r.getWarningCode()) && TrackerType.EVENT.equals(r.getTrackerType()) && event.getUid().equals(r.getUid())));
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) AssertValidationErrorReporter.hasTrackerError(org.hisp.dhis.tracker.validation.hooks.AssertValidationErrorReporter.hasTrackerError) E1120(org.hisp.dhis.tracker.report.TrackerErrorCode.E1120) Mockito.when(org.mockito.Mockito.when) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) ProgramStage(org.hisp.dhis.program.ProgramStage) E1118(org.hisp.dhis.tracker.report.TrackerErrorCode.E1118) Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) User(org.hisp.dhis.user.User) CodeGenerator(org.hisp.dhis.common.CodeGenerator) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) 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 42 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class AssignedUserValidationHookTest method testEventWithUserNotPresentInPreheat.

@Test
void testEventWithUserNotPresentInPreheat() {
    // given
    Event event = new Event();
    event.setEvent(CodeGenerator.generateUid());
    event.setAssignedUser(USER_ID);
    event.setProgramStage(PROGRAM_STAGE);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    TrackerBundle bundle = TrackerBundle.builder().build();
    bundle.setPreheat(new TrackerPreheat());
    when(validationContext.getBundle()).thenReturn(bundle);
    this.hookToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1118, TrackerType.EVENT, event.getUid());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 43 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class EnrollmentDateValidationHookTest method testDatesCanBeInTheFuture.

@Test
void testDatesCanBeInTheFuture() {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(CodeGenerator.generateUid());
    enrollment.setProgram(CodeGenerator.generateUid());
    final Instant dateInTheFuture = Instant.now().plus(Duration.ofDays(2));
    enrollment.setOccurredAt(dateInTheFuture);
    enrollment.setEnrolledAt(dateInTheFuture);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    Program program = new Program();
    program.setSelectEnrollmentDatesInFuture(true);
    program.setSelectIncidentDatesInFuture(true);
    when(validationContext.getProgram(enrollment.getProgram())).thenReturn(program);
    this.hookToTest.validateEnrollment(reporter, enrollment);
    assertFalse(reporter.hasErrors());
}
Also used : Program(org.hisp.dhis.program.Program) Instant(java.time.Instant) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 44 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class EnrollmentDateValidationHookTest method testFailOnMissingOccurredAtDate.

@Test
void testFailOnMissingOccurredAtDate() {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(CodeGenerator.generateUid());
    enrollment.setProgram(CodeGenerator.generateUid());
    enrollment.setEnrolledAt(Instant.now());
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    Program program = new Program();
    program.setDisplayIncidentDate(true);
    when(validationContext.getProgram(enrollment.getProgram())).thenReturn(program);
    this.hookToTest.validateEnrollment(reporter, enrollment);
    hasTrackerError(reporter, E1023, ENROLLMENT, enrollment.getUid());
}
Also used : Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 45 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class EnrollmentGeoValidationHookTest method testProgramWithNullFeatureTypeFailsGeometryValidation.

@Test
void testProgramWithNullFeatureTypeFailsGeometryValidation() {
    // given
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(CodeGenerator.generateUid());
    enrollment.setProgram(PROGRAM);
    enrollment.setGeometry(new GeometryFactory().createPoint());
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    Program program = new Program();
    when(validationContext.getProgram(PROGRAM)).thenReturn(program);
    this.hookToTest.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1074, ENROLLMENT, enrollment.getUid());
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)206 Test (org.junit.jupiter.api.Test)192 Event (org.hisp.dhis.tracker.domain.Event)89 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)48 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)48 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)43 ProgramStage (org.hisp.dhis.program.ProgramStage)38 DataElement (org.hisp.dhis.dataelement.DataElement)25 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)25 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)24 Relationship (org.hisp.dhis.tracker.domain.Relationship)23 DataValue (org.hisp.dhis.tracker.domain.DataValue)21 Program (org.hisp.dhis.program.Program)19 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)17 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)16 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 RelationshipType (org.hisp.dhis.relationship.RelationshipType)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)11