use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenProgramIsRegistrationAndEnrollmentIsMissing.
@Test
void eventValidationFailsWhenProgramIsRegistrationAndEnrollmentIsMissing() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
Program program = programWithRegistration(PROGRAM_UID, orgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(program);
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
when(ctx.getProgramStage(PROGRAM_STAGE_ID)).thenReturn(programStage(PROGRAM_STAGE_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).build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1033));
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAndProgramStageProgramDontMatch.
@Test
void eventValidationFailsWhenEventAndProgramStageProgramDontMatch() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
Program program = programWithRegistration(PROGRAM_UID, orgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(program);
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
when(ctx.getProgramStage(PROGRAM_STAGE_ID)).thenReturn(programStage(PROGRAM_STAGE_ID, programWithRegistration(CodeGenerator.generateUid(), orgUnit)));
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).build();
hook.validateEvent(reporter, event);
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1089));
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAndEnrollmentProgramDontMatch.
@Test
void eventValidationFailsWhenEventAndEnrollmentProgramDontMatch() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
Program program = programWithRegistration(PROGRAM_UID, orgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(program);
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
when(ctx.getProgramStage(PROGRAM_STAGE_ID)).thenReturn(programStage(PROGRAM_STAGE_ID, program));
when(ctx.getProgramInstance(ENROLLMENT_ID)).thenReturn(programInstance(ENROLLMENT_ID, programWithRegistration(CodeGenerator.generateUid(), orgUnit)));
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.E1079));
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationSucceedsWhenAOCAndCOsAreNotSetAndProgramHasDefaultCC.
@Test
void eventValidationSucceedsWhenAOCAndCOsAreNotSetAndProgramHasDefaultCC() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
Program program = programWithRegistration(PROGRAM_UID, orgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(program);
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
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);
assertFalse(reporter.hasErrors());
assertEquals(defaultAOC, reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should be cached");
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationSucceedsWhenEventAOCAndEventCOsAreSetAndBothFound.
@Test
void eventValidationSucceedsWhenEventAOCAndEventCOsAreSetAndBothFound() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo cc = categoryCombo();
program.setCategoryCombo(cc);
CategoryOption co = cc.getCategoryOptions().get(0);
when(preheat.getCategoryOption(co.getUid())).thenReturn(co);
CategoryOptionCombo aoc = firstCategoryOptionCombo(cc);
when(preheat.getCategoryOptionCombo(aoc.getUid())).thenReturn(aoc);
Event event = eventBuilder().attributeOptionCombo(aoc.getUid()).attributeCategoryOptions(co.getUid()).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
assertEquals(aoc, reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should be cached");
}
Aggregations