Search in sources :

Example 26 with Enrollment

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

the class PreCheckSecurityOwnershipValidationHookTest method verifyCaptureScopeIsCheckedForEnrollmentDeletion.

@Test
void verifyCaptureScopeIsCheckedForEnrollmentDeletion() {
    String enrollmentUid = CodeGenerator.generateUid();
    Enrollment enrollment = Enrollment.builder().enrollment(enrollmentUid).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
    when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.DELETE);
    when(ctx.getProgramInstance(enrollment.getEnrollment())).thenReturn(getEnrollment(enrollment.getEnrollment()));
    when(aclService.canDataWrite(user, program)).thenReturn(true);
    when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
    when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.validateEnrollment(reporter, enrollment);
    assertFalse(reporter.hasErrors());
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 27 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment 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 28 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment 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 29 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment 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)

Example 30 with Enrollment

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

the class EnrollmentGeoValidationHookTest method testProgramWithFeatureTypeDifferentFromGeometryFails.

@Test
void testProgramWithFeatureTypeDifferentFromGeometryFails() {
    // 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();
    program.setFeatureType(FeatureType.MULTI_POLYGON);
    when(validationContext.getProgram(PROGRAM)).thenReturn(program);
    this.hookToTest.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1012, 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

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