use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentGeoValidationHookTest method testGeometryIsValid.
@Test
void testGeometryIsValid() {
// given
Enrollment enrollment = new Enrollment();
enrollment.setProgram(PROGRAM);
enrollment.setGeometry(new GeometryFactory().createPoint());
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
this.hookToTest.validateEnrollment(reporter, enrollment);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentGeoValidationHookTest method testProgramWithFeatureTypeNoneFailsGeometryValidation.
@Test
void testProgramWithFeatureTypeNoneFailsGeometryValidation() {
// 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.NONE);
when(validationContext.getProgram(PROGRAM)).thenReturn(program);
this.hookToTest.validateEnrollment(reporter, enrollment);
// then
hasTrackerError(reporter, E1012, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentInExistingValidationHookTest method setEnrollmentInPayload.
private void setEnrollmentInPayload(EnrollmentStatus enrollmentStatus) {
Enrollment enrollmentInBundle = new Enrollment();
enrollmentInBundle.setProgram(programUid);
enrollmentInBundle.setTrackedEntity(trackedEntity);
enrollmentInBundle.setEnrollment("another_enrollment");
enrollmentInBundle.setStatus(enrollmentStatus);
when(bundle.getEnrollments()).thenReturn(Collections.singletonList(enrollmentInBundle));
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatchAndTEIIsInPayload.
@Test
void verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatchAndTEIIsInPayload() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(programWithRegistration(PROGRAM_UID, orgUnit, trackedEntityType(TEI_TYPE_ID)));
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(null);
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).trackedEntityType(ANOTHER_TEI_TYPE_ID).build();
bundle.setTrackedEntities(Collections.singletonList(trackedEntity));
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).program(PROGRAM_UID).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).build();
hook.validateEnrollment(reporter, enrollment);
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1022));
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatch.
@Test
void verifyValidationFailsWhenEnrollmentAndProgramTeiTypeDontMatch() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(programWithRegistration(PROGRAM_UID, orgUnit, trackedEntityType(TEI_TYPE_ID)));
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
TrackedEntityType anotherTrackedEntityType = trackedEntityType(TEI_ID, 'B');
when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(trackedEntityInstance(TEI_ID, anotherTrackedEntityType, orgUnit));
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).program(PROGRAM_UID).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).build();
hook.validateEnrollment(reporter, enrollment);
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1022));
}
Aggregations