use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method categoryCombo.
private CategoryCombo categoryCombo(char uniqueIdentifier) {
CategoryOption co1 = createCategoryOption(uniqueIdentifier);
CategoryOption co2 = createCategoryOption(uniqueIdentifier);
Category ca = createCategory(uniqueIdentifier, co1, co2);
CategoryCombo cc = createCategoryCombo(uniqueIdentifier, ca);
cc.setDataDimensionType(DataDimensionType.ATTRIBUTE);
CategoryOptionCombo aoc1 = createCategoryOptionCombo(cc, co1);
CategoryOptionCombo aoc2 = createCategoryOptionCombo(cc, co2);
cc.setOptionCombos(Sets.newHashSet(aoc1, aoc2));
return cc;
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAOCAndEventCOsAreSetAndCOIsNotFound.
@Test
void eventValidationFailsWhenEventAOCAndEventCOsAreSetAndCOIsNotFound() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo cc = categoryCombo();
program.setCategoryCombo(cc);
CategoryOptionCombo aoc = firstCategoryOptionCombo(cc);
when(preheat.getCategoryOptionCombo(aoc.getUid())).thenReturn(aoc);
String UNKNOWN_CO_ID = CodeGenerator.generateUid();
when(preheat.getCategoryOption(UNKNOWN_CO_ID)).thenReturn(null);
Event event = eventBuilder().attributeOptionCombo(aoc.getUid()).attributeCategoryOptions(UNKNOWN_CO_ID).build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1116));
assertNull(reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should not be cached");
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenOnlyCOsAreSetToCONotInCCAndEventProgramHasDefaultCC.
@Test
void eventValidationFailsWhenOnlyCOsAreSetToCONotInCCAndEventProgramHasDefaultCC() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo defaultCC = defaultCategoryCombo();
program.setCategoryCombo(defaultCC);
CategoryOptionCombo defaultAOC = firstCategoryOptionCombo(defaultCC);
when(preheat.getDefault(CategoryOptionCombo.class)).thenReturn(defaultAOC);
CategoryCombo cc = categoryCombo();
CategoryOption co = cc.getCategoryOptions().get(0);
when(preheat.getCategoryOption(co.getUid())).thenReturn(co);
Event event = eventBuilder().attributeCategoryOptions(co.getUid()).build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1117 && r.getErrorMessage().contains(program.getCategoryCombo().getUid()) && r.getErrorMessage().contains(co.getUid())));
assertNull(reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should not be cached");
verify(preheat, times(0)).put(any(), (IdentifiableObject) any());
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenOnlyAOCIsSetToAOCNotInProgramCC.
@Test
void eventValidationFailsWhenOnlyAOCIsSetToAOCNotInProgramCC() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
program.setCategoryCombo(categoryCombo('A'));
CategoryOptionCombo aoc = firstCategoryOptionCombo(categoryCombo('B'));
when(preheat.getCategoryOptionCombo(aoc.getUid())).thenReturn(aoc);
Event event = eventBuilder().attributeOptionCombo(aoc.getUid()).build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1054 && r.getErrorMessage().contains(aoc.getUid()) && r.getErrorMessage().contains(program.getCategoryCombo().getUid())));
assertNull(reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should not be cached");
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationSucceedsWhenOnlyCOsAreSetAndEventProgramHasDefaultCC.
@Test
void eventValidationSucceedsWhenOnlyCOsAreSetAndEventProgramHasDefaultCC() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo defaultCC = defaultCategoryCombo();
program.setCategoryCombo(defaultCC);
CategoryOption defaultCO = defaultCC.getCategoryOptions().get(0);
when(preheat.getCategoryOption(defaultCO.getUid())).thenReturn(defaultCO);
CategoryOptionCombo defaultAOC = firstCategoryOptionCombo(defaultCC);
when(preheat.getDefault(CategoryOptionCombo.class)).thenReturn(defaultAOC);
Event event = eventBuilder().attributeCategoryOptions(defaultCO.getUid()).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
assertEquals(defaultAOC, reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should be cached");
verify(preheat, times(0)).put(any(), eq(defaultAOC));
}
Aggregations