Search in sources :

Example 56 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAndProgramOrganisationUnitDontMatch.

@Test
void eventValidationFailsWhenEventAndProgramOrganisationUnitDontMatch() {
    OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
    OrganisationUnit anotherOrgUnit = organisationUnit(CodeGenerator.generateUid());
    Program program = programWithRegistration(PROGRAM_UID, anotherOrgUnit);
    when(ctx.getProgram(PROGRAM_UID)).thenReturn(program);
    when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(anotherOrgUnit.getUid())));
    when(ctx.getProgramStage(PROGRAM_STAGE_ID)).thenReturn(programStage(PROGRAM_STAGE_ID, program));
    when(ctx.getProgramInstance(ENROLLMENT_ID)).thenReturn(programInstance(ENROLLMENT_ID, program));
    CategoryCombo defaultCC = defaultCategoryCombo();
    program.setCategoryCombo(defaultCC);
    CategoryOptionCombo defaultAOC = firstCategoryOptionCombo(defaultCC);
    when(preheat.getDefault(CategoryOptionCombo.class)).thenReturn(defaultAOC);
    Event event = Event.builder().event(CodeGenerator.generateUid()).program(PROGRAM_UID).programStage(PROGRAM_STAGE_ID).orgUnit(ORG_UNIT_ID).enrollment(ENROLLMENT_ID).build();
    hook.validateEvent(reporter, event);
    assertEquals(1, reporter.getReportList().size());
    assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1029));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CategoryService(org.hisp.dhis.category.CategoryService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CategoryOption(org.hisp.dhis.category.CategoryOption) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) RelationshipConstraint(org.hisp.dhis.relationship.RelationshipConstraint) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ReferenceTrackerEntity(org.hisp.dhis.tracker.preheat.ReferenceTrackerEntity) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Category(org.hisp.dhis.category.Category) RelationshipItem(org.hisp.dhis.tracker.domain.RelationshipItem) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ProgramType(org.hisp.dhis.program.ProgramType) Optional(java.util.Optional) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DataDimensionType(org.hisp.dhis.common.DataDimensionType) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Relationship(org.hisp.dhis.tracker.domain.Relationship) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) TrackerIdentifierParams(org.hisp.dhis.tracker.TrackerIdentifierParams) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) RelationshipType(org.hisp.dhis.relationship.RelationshipType) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TRACKED_ENTITY_INSTANCE(org.hisp.dhis.relationship.RelationshipEntity.TRACKED_ENTITY_INSTANCE) RelationshipEntity(org.hisp.dhis.relationship.RelationshipEntity) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Event(org.hisp.dhis.tracker.domain.Event) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ProgramStage(org.hisp.dhis.program.ProgramStage) Mockito.verify(org.mockito.Mockito.verify) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Matchers.hasItem(org.hamcrest.Matchers.hasItem) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Collections(java.util.Collections) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Event(org.hisp.dhis.tracker.domain.Event) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 57 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class PreCheckMandatoryFieldsValidationHookTest method verifyEnrollmentValidationFailsOnMissingOrgUnit.

@Test
void verifyEnrollmentValidationFailsOnMissingOrgUnit() {
    Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(null).program(CodeGenerator.generateUid()).trackedEntity(CodeGenerator.generateUid()).build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    assertMissingPropertyForEnrollment(reporter, enrollment.getUid(), "orgUnit");
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 58 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class PreCheckMandatoryFieldsValidationHookTest method verifyEnrollmentValidationSuccess.

@Test
void verifyEnrollmentValidationSuccess() {
    Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(CodeGenerator.generateUid()).program(CodeGenerator.generateUid()).trackedEntity(CodeGenerator.generateUid()).build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    assertFalse(reporter.hasErrors());
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 59 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHookTest method verifyEnrollmentValidationFailsWhenIsSoftDeleted.

@Test
void verifyEnrollmentValidationFailsWhenIsSoftDeleted() {
    // given
    Enrollment enrollment = Enrollment.builder().enrollment(SOFT_DELETED_ENROLLMENT_UID).build();
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1113, ENROLLMENT, enrollment.getUid());
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 60 with Enrollment

use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHookTest method verifyEnrollmentValidationSuccessWhenEnrollmentIsNotPresent.

@Test
void verifyEnrollmentValidationSuccessWhenEnrollmentIsNotPresent() {
    // given
    Enrollment enrollment = Enrollment.builder().enrollment(NOT_PRESENT_ENROLLMENT_UID).build();
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    // then
    assertFalse(reporter.hasErrors());
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

Enrollment (org.hisp.dhis.tracker.domain.Enrollment)88 Test (org.junit.jupiter.api.Test)67 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)53 Event (org.hisp.dhis.tracker.domain.Event)25 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)24 Program (org.hisp.dhis.program.Program)21 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)17 List (java.util.List)16 Optional (java.util.Optional)15 ProgramInstance (org.hisp.dhis.program.ProgramInstance)15 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)15 Sets (com.google.common.collect.Sets)14 Collectors (java.util.stream.Collectors)14 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Mockito.when (org.mockito.Mockito.when)14