use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAndProgramOrganisationUnitDontMatch.
@Test
void eventValidationFailsWhenEventAndProgramOrganisationUnitDontMatch() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
OrganisationUnit anotherOrgUnit = organisationUnit(CodeGenerator.generateUid());
Program program = programWithRegistration(PROGRAM_UID, anotherOrgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(program);
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(anotherOrgUnit.getUid())));
when(ctx.getProgramStage(PROGRAM_STAGE_ID)).thenReturn(programStage(PROGRAM_STAGE_ID, program));
when(ctx.getProgramInstance(ENROLLMENT_ID)).thenReturn(programInstance(ENROLLMENT_ID, program));
CategoryCombo defaultCC = defaultCategoryCombo();
program.setCategoryCombo(defaultCC);
CategoryOptionCombo defaultAOC = firstCategoryOptionCombo(defaultCC);
when(preheat.getDefault(CategoryOptionCombo.class)).thenReturn(defaultAOC);
Event event = Event.builder().event(CodeGenerator.generateUid()).program(PROGRAM_UID).programStage(PROGRAM_STAGE_ID).orgUnit(ORG_UNIT_ID).enrollment(ENROLLMENT_ID).build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1029));
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckMandatoryFieldsValidationHookTest method verifyEnrollmentValidationFailsOnMissingOrgUnit.
@Test
void verifyEnrollmentValidationFailsOnMissingOrgUnit() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(null).program(CodeGenerator.generateUid()).trackedEntity(CodeGenerator.generateUid()).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
assertMissingPropertyForEnrollment(reporter, enrollment.getUid(), "orgUnit");
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckMandatoryFieldsValidationHookTest method verifyEnrollmentValidationSuccess.
@Test
void verifyEnrollmentValidationSuccess() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(CodeGenerator.generateUid()).program(CodeGenerator.generateUid()).trackedEntity(CodeGenerator.generateUid()).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHookTest method verifyEnrollmentValidationFailsWhenIsSoftDeleted.
@Test
void verifyEnrollmentValidationFailsWhenIsSoftDeleted() {
// given
Enrollment enrollment = Enrollment.builder().enrollment(SOFT_DELETED_ENROLLMENT_UID).build();
// when
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
// then
hasTrackerError(reporter, E1113, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHookTest method verifyEnrollmentValidationSuccessWhenEnrollmentIsNotPresent.
@Test
void verifyEnrollmentValidationSuccessWhenEnrollmentIsNotPresent() {
// given
Enrollment enrollment = Enrollment.builder().enrollment(NOT_PRESENT_ENROLLMENT_UID).build();
// when
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
// then
assertFalse(reporter.hasErrors());
}
Aggregations