use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentNoteValidationHookTest method testNoteWithExistingUidWarnings.
@Test
void testNoteWithExistingUidWarnings() {
// Given
final Note note = rnd.nextObject(Note.class);
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
TrackerPreheat preheat = mock(TrackerPreheat.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
when(trackerBundle.getPreheat()).thenReturn(preheat);
when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
enrollment.setNotes(Collections.singletonList(note));
// When
this.hook.validateEnrollment(reporter, enrollment);
// Then
assertTrue(reporter.hasWarnings());
assertTrue(reporter.hasWarningReport(warn -> E1119.equals(warn.getWarningCode()) && ENROLLMENT.equals(warn.getTrackerType()) && enrollment.getUid().equals(warn.getUid())));
assertThat(enrollment.getNotes(), hasSize(0));
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyCaptureScopeIsCheckedForEnrollmentProgramWithoutRegistration.
@Test
void verifyCaptureScopeIsCheckedForEnrollmentProgramWithoutRegistration() {
program.setProgramType(ProgramType.WITHOUT_REGISTRATION);
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.CREATE_AND_UPDATE);
when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, program)).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForEnrollment.
@Test
void verifyValidationSuccessForEnrollment() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.CREATE_AND_UPDATE);
when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
when(aclService.canDataWrite(user, program)).thenReturn(true);
when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForEnrollmentWithoutEventsUsingDeleteStrategyAndUserNotInOrgUnitHierarchy.
@Test
void verifyValidationFailsForEnrollmentWithoutEventsUsingDeleteStrategyAndUserNotInOrgUnitHierarchy() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.DELETE);
when(ctx.programInstanceHasEvents(enrollment.getEnrollment())).thenReturn(false);
when(ctx.getProgramInstance(enrollment.getEnrollment())).thenReturn(getEnrollment(enrollment.getEnrollment()));
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(false);
when(aclService.canDataWrite(user, program)).thenReturn(true);
when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEnrollment(reporter, enrollment);
hasTrackerError(reporter, E1000, TrackerType.ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForEnrollmentWhenProgramInstanceHasNoOrgUnitAssigned.
@Test
void verifyValidationSuccessForEnrollmentWhenProgramInstanceHasNoOrgUnitAssigned() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.UPDATE);
ProgramInstance programInstance = getEnrollment(enrollment.getEnrollment());
programInstance.setOrganisationUnit(null);
when(ctx.getProgramInstance(enrollment.getEnrollment())).thenReturn(programInstance);
when(aclService.canDataWrite(user, program)).thenReturn(true);
when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
verify(organisationUnitService, times(0)).isInUserHierarchyCached(user, organisationUnit);
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.DELETE);
validatorToTest.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
verify(organisationUnitService, times(0)).isInUserHierarchyCached(user, organisationUnit);
}
Aggregations