Search in sources :

Example 1 with E1120

use of org.hisp.dhis.tracker.report.TrackerErrorCode.E1120 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())));
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) AssertValidationErrorReporter.hasTrackerError(org.hisp.dhis.tracker.validation.hooks.AssertValidationErrorReporter.hasTrackerError) E1120(org.hisp.dhis.tracker.report.TrackerErrorCode.E1120) Mockito.when(org.mockito.Mockito.when) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) ProgramStage(org.hisp.dhis.program.ProgramStage) E1118(org.hisp.dhis.tracker.report.TrackerErrorCode.E1118) Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) User(org.hisp.dhis.user.User) CodeGenerator(org.hisp.dhis.common.CodeGenerator) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 2 with E1120

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

the class AssignedUserValidationHookTest method testEventWithNotEnabledUserAssignment.

@Test
void testEventWithNotEnabledUserAssignment() {
    // 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(false);
    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())));
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) AssertValidationErrorReporter.hasTrackerError(org.hisp.dhis.tracker.validation.hooks.AssertValidationErrorReporter.hasTrackerError) E1120(org.hisp.dhis.tracker.report.TrackerErrorCode.E1120) Mockito.when(org.mockito.Mockito.when) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) ProgramStage(org.hisp.dhis.program.ProgramStage) E1118(org.hisp.dhis.tracker.report.TrackerErrorCode.E1118) Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) User(org.hisp.dhis.user.User) CodeGenerator(org.hisp.dhis.common.CodeGenerator) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Aggregations

CodeGenerator (org.hisp.dhis.common.CodeGenerator)2 ProgramStage (org.hisp.dhis.program.ProgramStage)2 TrackerIdentifier (org.hisp.dhis.tracker.TrackerIdentifier)2 TrackerType (org.hisp.dhis.tracker.TrackerType)2 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)2 Event (org.hisp.dhis.tracker.domain.Event)2 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)2 E1118 (org.hisp.dhis.tracker.report.TrackerErrorCode.E1118)2 E1120 (org.hisp.dhis.tracker.report.TrackerErrorCode.E1120)2 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)2 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)2 AssertValidationErrorReporter.hasTrackerError (org.hisp.dhis.tracker.validation.hooks.AssertValidationErrorReporter.hasTrackerError)2 User (org.hisp.dhis.user.User)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 Mock (org.mockito.Mock)2 Mockito.when (org.mockito.Mockito.when)2