use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceTest method childEntitiesOfInvalidParentsAreStillValidated.
@Test
void childEntitiesOfInvalidParentsAreStillValidated() {
// Test shows
// the children of a tracked entity will still be validated even if it
// as a parent is invalid
TrackedEntity invalidTrackedEntity = trackedEntity();
Enrollment invalidEnrollment = enrollment();
invalidTrackedEntity.setEnrollments(enrollments(invalidEnrollment));
Event invalidEvent = event();
invalidEnrollment.setEvents(events(invalidEvent));
TrackerBundle bundle = newBundle().validationMode(ValidationMode.FULL).trackedEntities(trackedEntities(invalidTrackedEntity)).enrollments(invalidTrackedEntity.getEnrollments()).events(invalidEnrollment.getEvents()).build();
ValidationHook hook = ValidationHook.builder().validateTrackedEntity((reporter, te) -> reporter.addErrorIf(() -> invalidTrackedEntity.equals(te), te, TrackerErrorCode.E1090)).validateEnrollment((reporter, enrollment) -> reporter.addErrorIf(() -> invalidEnrollment.equals(enrollment), enrollment, TrackerErrorCode.E1069)).validateEvent((reporter, event) -> reporter.addErrorIf(() -> invalidEvent.equals(event), event, TrackerErrorCode.E1032)).build();
service = new DefaultTrackerValidationService(List.of(hook), Collections.emptyList());
TrackerValidationReport report = service.validate(bundle);
assertTrue(report.hasErrors());
assertEquals(3, report.getErrors().size());
assertHasError(report, TrackerErrorCode.E1090, invalidTrackedEntity);
assertHasError(report, TrackerErrorCode.E1069, invalidEnrollment);
assertHasError(report, TrackerErrorCode.E1032, invalidEvent);
assertTrue(bundle.getTrackedEntities().isEmpty());
assertTrue(bundle.getEnrollments().isEmpty());
assertTrue(bundle.getEvents().isEmpty());
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceTest method shouldNotValidateMissingUser.
@Test
void shouldNotValidateMissingUser() {
TrackerBundle bundle = newBundle().validationMode(ValidationMode.SKIP).user(null).build();
TrackerValidationHook hook1 = mock(TrackerValidationHook.class);
service = new DefaultTrackerValidationService(List.of(hook1), Collections.emptyList());
service.validate(bundle);
verifyNoInteractions(hook1);
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceConfigOrderTest method hooksAreExecutedInTrackerValidationConfigOrder.
@Test
void hooksAreExecutedInTrackerValidationConfigOrder() {
// Test that hooks declared in TrackerValidationConfig validationHooks()
// are injected
// into the TrackerValidationService. This is important since order
// matters in the current implementation.
// Note that FAIL_FAST shows that although the event is also invalid due
// to not having an orgUnit and more it
// fails due to the first failed check which is the
// PreCheckUidValidationHook
Event event = new Event();
event.setEvent("invalidUid");
TrackerBundle bundle = TrackerBundle.builder().importMode(TrackerBundleMode.VALIDATE).validationMode(ValidationMode.FAIL_FAST).skipRuleEngine(true).events(Collections.singletonList(event)).build();
TrackerValidationReport report = trackerValidationService.validate(bundle);
assertTrue(report.hasErrors());
assertEquals(1, report.getErrors().size());
assertEquals(E1048, report.getErrors().get(0).getErrorCode());
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class EnrollmentAttributeValidationHookTest method setUp.
@BeforeEach
public void setUp() {
trackedEntityAttribute = new TrackedEntityAttribute("name", "description", ValueType.TEXT, false, false);
trackedEntityAttribute.setUid(trackedAttribute);
trackedEntityAttribute1 = new TrackedEntityAttribute("name1", "description1", ValueType.TEXT, false, false);
trackedEntityAttribute1.setUid(trackedAttribute1);
when(validationContext.getProgram(anyString())).thenReturn(program);
when(enrollment.getProgram()).thenReturn("program");
when(validationContext.getTrackedEntityAttribute(trackedAttribute)).thenReturn(trackedEntityAttribute);
when(validationContext.getTrackedEntityAttribute(trackedAttribute1)).thenReturn(trackedEntityAttribute1);
String uid = CodeGenerator.generateUid();
when(enrollment.getUid()).thenReturn(uid);
when(enrollment.getEnrollment()).thenReturn(uid);
when(enrollment.getTrackerType()).thenCallRealMethod();
enrollment.setTrackedEntity(trackedEntity);
TrackerBundle bundle = TrackerBundle.builder().build();
bundle.setPreheat(preheat);
when(validationContext.getBundle()).thenReturn(bundle);
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class ValidationErrorReporterTest method hasErrorReportNotFound.
@Test
void hasErrorReportNotFound() {
ValidationErrorReporter reporter = ValidationErrorReporter.emptyReporter();
TrackerBundle bundle = mock(TrackerBundle.class);
TrackerErrorReport error = TrackerErrorReport.builder().errorCode(TrackerErrorCode.E1000).trackerType(TrackerType.EVENT).build(bundle);
reporter.getReportList().add(error);
assertFalse(reporter.hasErrorReport(r -> TrackerType.TRACKED_ENTITY.equals(r.getTrackerType())));
}
Aggregations