Search in sources :

Example 61 with Enrollment

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

the class PreCheckExistenceValidationHookTest method verifyEnrollmentValidationFailsWhenIsCreateAndEnrollmentIsAlreadyPresent.

@Test
void verifyEnrollmentValidationFailsWhenIsCreateAndEnrollmentIsAlreadyPresent() {
    // given
    Enrollment enrollment = Enrollment.builder().enrollment(ENROLLMENT_UID).build();
    // when
    when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.CREATE);
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1080, ENROLLMENT, enrollment.getUid());
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 62 with Enrollment

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

the class EnrollmentDateValidationHookTest method testDatesShouldBeAllowedOnSameDayIfFutureDatesAreNotAllowed.

@Test
void testDatesShouldBeAllowedOnSameDayIfFutureDatesAreNotAllowed() {
    Enrollment enrollment = new Enrollment();
    enrollment.setProgram(CodeGenerator.generateUid());
    final Instant today = Instant.now().plus(Duration.ofMinutes(1));
    enrollment.setOccurredAt(today);
    enrollment.setEnrolledAt(today);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    when(validationContext.getProgram(enrollment.getProgram())).thenReturn(new 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 63 with Enrollment

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

the class EnrollmentDateValidationHookTest method testDatesMustNotBeInTheFuture.

@Test
void testDatesMustNotBeInTheFuture() {
    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);
    when(validationContext.getProgram(enrollment.getProgram())).thenReturn(new Program());
    this.hookToTest.validateEnrollment(reporter, enrollment);
    hasTrackerError(reporter, E1020, ENROLLMENT, enrollment.getUid());
    hasTrackerError(reporter, E1021, ENROLLMENT, enrollment.getUid());
}
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 64 with Enrollment

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

the class EnrollmentDateValidationHookTest method testMandatoryDatesMustBePresent.

@Test
void testMandatoryDatesMustBePresent() {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(CodeGenerator.generateUid());
    enrollment.setProgram(CodeGenerator.generateUid());
    enrollment.setOccurredAt(Instant.now());
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    when(validationContext.getProgram(enrollment.getProgram())).thenReturn(new Program());
    this.hookToTest.validateEnrollment(reporter, enrollment);
    hasTrackerError(reporter, E1025, 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 65 with Enrollment

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

the class EnrollmentGeoValidationHookTest method testEnrollmentWithNoProgramThrowsAnError.

@Test
void testEnrollmentWithNoProgramThrowsAnError() {
    // given
    Enrollment enrollment = new Enrollment();
    enrollment.setProgram(null);
    enrollment.setGeometry(new GeometryFactory().createPoint());
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    assertThrows(NullPointerException.class, () -> this.hookToTest.validateEnrollment(reporter, enrollment));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

Enrollment (org.hisp.dhis.tracker.domain.Enrollment)88 Test (org.junit.jupiter.api.Test)67 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)53 Event (org.hisp.dhis.tracker.domain.Event)25 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)24 Program (org.hisp.dhis.program.Program)21 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)17 List (java.util.List)16 Optional (java.util.Optional)15 ProgramInstance (org.hisp.dhis.program.ProgramInstance)15 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)15 Sets (com.google.common.collect.Sets)14 Collectors (java.util.stream.Collectors)14 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Mockito.when (org.mockito.Mockito.when)14