use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class EventDateValidationHookTest method testEventIsNotValidWhenCompletedAtIsNotPresentAndEventIsCompleted.
@Test
void testEventIsNotValidWhenCompletedAtIsNotPresentAndEventIsCompleted() {
// given
Event event = new Event();
event.setEvent(CodeGenerator.generateUid());
event.setProgram(PROGRAM_WITH_REGISTRATION_ID);
event.setOccurredAt(now());
event.setStatus(EventStatus.COMPLETED);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
this.hookToTest.validateEvent(reporter, event);
// then
hasTrackerError(reporter, E1042, EVENT, event.getUid());
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class EventNoteValidationHookTest method testNoteWithExistingUidAndNoTextIsIgnored.
@Test
void testNoteWithExistingUidAndNoTextIsIgnored() {
// Given
final Note note = rnd.nextObject(Note.class);
note.setValue(null);
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
event.setNotes(Collections.singletonList(note));
// When
this.hook.validateEvent(reporter, event);
// Then
assertFalse(reporter.hasErrors());
assertThat(event.getNotes(), hasSize(0));
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHookTest method verifyTrackedEntityValidationFailsWhenIsUpdateAndTEIIsNotPresent.
@Test
void verifyTrackedEntityValidationFailsWhenIsUpdateAndTEIIsNotPresent() {
// given
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(NOT_PRESENT_TEI_UID).build();
// when
when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.UPDATE);
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateTrackedEntity(reporter, trackedEntity);
// then
hasTrackerError(reporter, E1063, TRACKED_ENTITY, trackedEntity.getUid());
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHookTest method verifyEventValidationSuccessWhenIsUpdate.
@Test
void verifyEventValidationSuccessWhenIsUpdate() {
// given
Event event = Event.builder().event(EVENT_UID).build();
// when
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEvent(reporter, event);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHookTest method verifyTrackedEntityValidationSuccessWhenTeiIsNotPresent.
@Test
void verifyTrackedEntityValidationSuccessWhenTeiIsNotPresent() {
// given
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(NOT_PRESENT_TEI_UID).build();
// when
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateTrackedEntity(reporter, trackedEntity);
// then
assertFalse(reporter.hasErrors());
}
Aggregations