Search in sources :

Example 6 with TrackerValidationReport

use of org.hisp.dhis.tracker.report.TrackerValidationReport 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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArrayList(java.util.ArrayList) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AssertTrackerValidationReport.assertHasWarning(org.hisp.dhis.tracker.validation.hooks.AssertTrackerValidationReport.assertHasWarning) BiConsumer(java.util.function.BiConsumer) User(org.hisp.dhis.user.User) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Event(org.hisp.dhis.tracker.domain.Event) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ValidationMode(org.hisp.dhis.tracker.ValidationMode) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) AbstractTrackerDtoValidationHook(org.hisp.dhis.tracker.validation.hooks.AbstractTrackerDtoValidationHook) Mockito.verify(org.mockito.Mockito.verify) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Builder(lombok.Builder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) AssertTrackerValidationReport.assertHasError(org.hisp.dhis.tracker.validation.hooks.AssertTrackerValidationReport.assertHasError) CodeGenerator(org.hisp.dhis.common.CodeGenerator) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) AbstractTrackerDtoValidationHook(org.hisp.dhis.tracker.validation.hooks.AbstractTrackerDtoValidationHook) Test(org.junit.jupiter.api.Test)

Example 7 with TrackerValidationReport

use of org.hisp.dhis.tracker.report.TrackerValidationReport in project dhis2-core by dhis2.

the class DefaultTrackerValidationServiceTest method failFastModePreventsFurtherValidationAfterFirstErrorIsAdded.

@Test
void failFastModePreventsFurtherValidationAfterFirstErrorIsAdded() {
    Event validEvent = event();
    Event invalidEvent = event();
    TrackerBundle bundle = newBundle().validationMode(ValidationMode.FAIL_FAST).events(events(invalidEvent, validEvent)).build();
    ValidationHook hook1 = ValidationHook.builder().removeOnError(false).validateEvent((reporter, event) -> reporter.addErrorIf(() -> invalidEvent.equals(event), event, TrackerErrorCode.E1032)).build();
    TrackerValidationHook hook2 = mock(TrackerValidationHook.class);
    service = new DefaultTrackerValidationService(List.of(hook1, hook2), Collections.emptyList());
    TrackerValidationReport report = service.validate(bundle);
    assertTrue(report.hasErrors());
    assertHasError(report, TrackerErrorCode.E1032, invalidEvent);
    assertFalse(bundle.getEvents().contains(invalidEvent));
    assertTrue(bundle.getEvents().contains(validEvent));
    verifyNoInteractions(hook2);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArrayList(java.util.ArrayList) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AssertTrackerValidationReport.assertHasWarning(org.hisp.dhis.tracker.validation.hooks.AssertTrackerValidationReport.assertHasWarning) BiConsumer(java.util.function.BiConsumer) User(org.hisp.dhis.user.User) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Event(org.hisp.dhis.tracker.domain.Event) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ValidationMode(org.hisp.dhis.tracker.ValidationMode) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) AbstractTrackerDtoValidationHook(org.hisp.dhis.tracker.validation.hooks.AbstractTrackerDtoValidationHook) Mockito.verify(org.mockito.Mockito.verify) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Builder(lombok.Builder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) AssertTrackerValidationReport.assertHasError(org.hisp.dhis.tracker.validation.hooks.AssertTrackerValidationReport.assertHasError) CodeGenerator(org.hisp.dhis.common.CodeGenerator) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) AbstractTrackerDtoValidationHook(org.hisp.dhis.tracker.validation.hooks.AbstractTrackerDtoValidationHook) Test(org.junit.jupiter.api.Test)

Example 8 with TrackerValidationReport

use of org.hisp.dhis.tracker.report.TrackerValidationReport in project dhis2-core by dhis2.

the class TrackerImporterServiceTest method setUp.

@BeforeEach
public void setUp() {
    subject = new DefaultTrackerImportService(trackerBundleService, trackerValidationService, trackerPreprocessService, trackerUserService, notifier);
    final List<Event> events = rnd.objects(Event.class, 3).collect(Collectors.toList());
    params = TrackerImportParams.builder().events(events).enrollments(new ArrayList<>()).relationships(new ArrayList<>()).trackedEntities(new ArrayList<>()).userId("123").build();
    TrackerBundleReport trackerBundleReport = TrackerBundleReport.builder().build();
    when(trackerUserService.getUser(anyString())).thenReturn(getUser());
    when(trackerBundleService.commit(any(TrackerBundle.class))).thenReturn(trackerBundleReport);
    when(trackerValidationService.validate(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
    when(trackerValidationService.validateRuleEngine(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
    when(trackerPreprocessService.preprocess(any(TrackerBundle.class))).thenReturn(ParamsConverter.convert(params));
}
Also used : TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.tracker.domain.Event) DefaultTrackerImportService(org.hisp.dhis.tracker.DefaultTrackerImportService) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with TrackerValidationReport

use of org.hisp.dhis.tracker.report.TrackerValidationReport in project dhis2-core by dhis2.

the class DefaultTrackerImportService method validateBundle.

protected TrackerValidationReport validateBundle(TrackerImportParams params, TrackerBundle trackerBundle, TrackerTimingsStats opsTimer) {
    TrackerValidationReport validationReport = trackerValidationService.validate(trackerBundle);
    notifyOps(params, VALIDATION_OPS, opsTimer);
    return validationReport;
}
Also used : TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport)

Example 10 with TrackerValidationReport

use of org.hisp.dhis.tracker.report.TrackerValidationReport in project dhis2-core by dhis2.

the class DefaultTrackerImportService method validateRuleEngine.

protected TrackerValidationReport validateRuleEngine(TrackerBundle trackerBundle) {
    TrackerValidationReport ruleEngineValidationReport = new TrackerValidationReport();
    ruleEngineValidationReport.addValidationReport(trackerValidationService.validateRuleEngine(trackerBundle));
    return ruleEngineValidationReport;
}
Also used : TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport)

Aggregations

TrackerValidationReport (org.hisp.dhis.tracker.report.TrackerValidationReport)18 Test (org.junit.jupiter.api.Test)11 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)10 Event (org.hisp.dhis.tracker.domain.Event)10 User (org.hisp.dhis.user.User)10 ArrayList (java.util.ArrayList)9 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)9 Arrays (java.util.Arrays)8 Collections (java.util.Collections)8 List (java.util.List)8 Objects (java.util.Objects)8 BiConsumer (java.util.function.BiConsumer)8 Builder (lombok.Builder)8 CodeGenerator (org.hisp.dhis.common.CodeGenerator)8 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)8 ValidationMode (org.hisp.dhis.tracker.ValidationMode)8 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)8 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)8 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)8 AbstractTrackerDtoValidationHook (org.hisp.dhis.tracker.validation.hooks.AbstractTrackerDtoValidationHook)8