use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForTrackerEventCreation.
@Test
void verifyValidationSuccessForTrackerEventCreation() {
Event event = Event.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).programStage(PS_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(event)).thenReturn(TrackerImportStrategy.CREATE);
when(ctx.getProgramStage(event.getProgramStage())).thenReturn(programStage);
when(ctx.getProgramInstance(event.getEnrollment())).thenReturn(getEnrollment(null));
when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
when(aclService.canDataRead(user, program)).thenReturn(true);
when(aclService.canDataWrite(user, programStage)).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class AssignedUserValidationHookTest method testEventWithNullEnabledUserAssignment.
@Test
void testEventWithNullEnabledUserAssignment() {
// given
Event event = new Event();
event.setEvent(CodeGenerator.generateUid());
event.setAssignedUser(USER_ID);
event.setProgramStage(PROGRAM_STAGE);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
ProgramStage programStage = new ProgramStage();
programStage.setEnableUserAssignment(null);
when(validationContext.getProgramStage(PROGRAM_STAGE)).thenReturn(programStage);
this.hookToTest.validateEvent(reporter, event);
// then
assertFalse(reporter.hasErrors());
assertTrue(reporter.hasWarnings());
assertTrue(reporter.hasWarningReport(r -> E1120.equals(r.getWarningCode()) && TrackerType.EVENT.equals(r.getTrackerType()) && event.getUid().equals(r.getUid())));
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class AssignedUserValidationHookTest method testEventWithUserNotPresentInPreheat.
@Test
void testEventWithUserNotPresentInPreheat() {
// given
Event event = new Event();
event.setEvent(CodeGenerator.generateUid());
event.setAssignedUser(USER_ID);
event.setProgramStage(PROGRAM_STAGE);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
TrackerBundle bundle = TrackerBundle.builder().build();
bundle.setPreheat(new TrackerPreheat());
when(validationContext.getBundle()).thenReturn(bundle);
this.hookToTest.validateEvent(reporter, event);
// then
hasTrackerError(reporter, E1118, TrackerType.EVENT, event.getUid());
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceTest method needsToRunExecutesHookIfReturnsTrue.
@Test
void needsToRunExecutesHookIfReturnsTrue() {
Event invalidEvent = event();
TrackerBundle bundle = newBundle().events(events(invalidEvent)).build();
ValidationHook hook1 = ValidationHook.builder().needsToRun(true).validateEvent((reporter, event) -> reporter.addErrorIf(() -> invalidEvent.equals(event), event, TrackerErrorCode.E1032)).build();
service = new DefaultTrackerValidationService(List.of(hook1), Collections.emptyList());
TrackerValidationReport report = service.validate(bundle);
assertTrue(report.hasErrors());
assertHasError(report, TrackerErrorCode.E1032, invalidEvent);
}
use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceTest method needsToRunPreventsHookExecutionOnImportStrategyDeleteByDefault.
@Test
void needsToRunPreventsHookExecutionOnImportStrategyDeleteByDefault() {
Event invalidEvent = event();
TrackerBundle bundle = newBundle().importStrategy(TrackerImportStrategy.DELETE).events(events(invalidEvent)).build();
// StrategyPreProcessor sets the ImportStrategy in the bundle for every
// dto
bundle.setStrategy(invalidEvent, TrackerImportStrategy.DELETE);
ValidationHook hook1 = ValidationHook.builder().validateEvent((reporter, event) -> reporter.addErrorIf(() -> invalidEvent.equals(event), event, TrackerErrorCode.E1032)).build();
service = new DefaultTrackerValidationService(List.of(hook1), Collections.emptyList());
TrackerValidationReport report = service.validate(bundle);
assertFalse(report.hasErrors());
}
Aggregations