Search in sources :

Example 26 with ValidationErrorReporter

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

the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForEventUsingUpdateStrategyAndUserWithoutAuthority.

@Test
void verifyValidationFailsForEventUsingUpdateStrategyAndUserWithoutAuthority() {
    String enrollmentUid = CodeGenerator.generateUid();
    Event event = Event.builder().event(CodeGenerator.generateUid()).enrollment(enrollmentUid).orgUnit(ORG_UNIT_ID).programStage(PS_ID).program(PROGRAM_ID).build();
    when(ctx.getStrategy(event)).thenReturn(TrackerImportStrategy.UPDATE);
    ProgramInstance programInstance = getEnrollment(enrollmentUid);
    ProgramStageInstance programStageInstance = getEvent();
    programStageInstance.setProgramInstance(programInstance);
    when(ctx.getProgramStageInstance(event.getEvent())).thenReturn(programStageInstance);
    when(ctx.getProgramInstance(event.getEnrollment())).thenReturn(programInstance);
    when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
    when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
    when(aclService.canDataRead(user, program)).thenReturn(true);
    when(aclService.canDataWrite(user, programStage)).thenReturn(true);
    when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.validateEvent(reporter, event);
    hasTrackerError(reporter, E1083, TrackerType.EVENT, event.getUid());
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 27 with ValidationErrorReporter

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

the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForTrackedEntity.

@Test
void verifyValidationSuccessForTrackedEntity() {
    TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntityType(TEI_TYPE_ID).build();
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
    when(ctx.getTrackedEntityType(TEI_TYPE_ID)).thenReturn(trackedEntityType);
    when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.CREATE_AND_UPDATE);
    when(organisationUnitService.isInUserSearchHierarchyCached(user, organisationUnit)).thenReturn(true);
    when(aclService.canDataWrite(user, trackedEntityType)).thenReturn(true);
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.validateTrackedEntity(reporter, trackedEntity);
    assertFalse(reporter.hasErrors());
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 28 with ValidationErrorReporter

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

the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForTrackedEntityUpdateWithUserNotInOrgUnitSearchHierarchy.

@Test
void verifyValidationFailsForTrackedEntityUpdateWithUserNotInOrgUnitSearchHierarchy() {
    TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).orgUnit(ORG_UNIT_ID).trackedEntityType(TEI_TYPE_ID).build();
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
    when(ctx.getTrackedEntityType(TEI_TYPE_ID)).thenReturn(trackedEntityType);
    when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.CREATE_AND_UPDATE);
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
    when(organisationUnitService.isInUserSearchHierarchyCached(user, organisationUnit)).thenReturn(false);
    when(aclService.canDataWrite(user, trackedEntityType)).thenReturn(true);
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.validateTrackedEntity(reporter, trackedEntity);
    hasTrackerError(reporter, E1003, TrackerType.TRACKED_ENTITY, trackedEntity.getUid());
}
Also used : TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 29 with ValidationErrorReporter

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

the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForTrackerEventUpdate.

@Test
void verifyValidationSuccessForTrackerEventUpdate() {
    Event event = Event.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).programStage(PS_ID).program(PROGRAM_ID).build();
    when(ctx.getStrategy(event)).thenReturn(TrackerImportStrategy.CREATE_AND_UPDATE);
    when(ctx.getProgramStage(event.getProgramStage())).thenReturn(programStage);
    when(ctx.getProgramInstance(event.getEnrollment())).thenReturn(getEnrollment(null));
    when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
    when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
    when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
    when(aclService.canDataRead(user, program)).thenReturn(true);
    when(aclService.canDataWrite(user, programStage)).thenReturn(true);
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 30 with ValidationErrorReporter

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

the class PreCheckSecurityOwnershipValidationHookTest method verifyCaptureScopeIsCheckedForEnrollmentProgramWithoutRegistration.

@Test
void verifyCaptureScopeIsCheckedForEnrollmentProgramWithoutRegistration() {
    program.setProgramType(ProgramType.WITHOUT_REGISTRATION);
    String enrollmentUid = CodeGenerator.generateUid();
    Enrollment enrollment = Enrollment.builder().enrollment(enrollmentUid).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
    when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.CREATE_AND_UPDATE);
    when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
    when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
    when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
    when(aclService.canDataWrite(user, program)).thenReturn(true);
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.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) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)206 Test (org.junit.jupiter.api.Test)192 Event (org.hisp.dhis.tracker.domain.Event)89 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)48 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)48 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)43 ProgramStage (org.hisp.dhis.program.ProgramStage)38 DataElement (org.hisp.dhis.dataelement.DataElement)25 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)25 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)24 Relationship (org.hisp.dhis.tracker.domain.Relationship)23 DataValue (org.hisp.dhis.tracker.domain.DataValue)21 Program (org.hisp.dhis.program.Program)19 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)17 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)16 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 RelationshipType (org.hisp.dhis.relationship.RelationshipType)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)11