use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAOCAndEventCOsAreSetAndInProgramCCButNotAllCOsInAOCAreGiven.
@Test
void eventValidationFailsWhenEventAOCAndEventCOsAreSetAndInProgramCCButNotAllCOsInAOCAreGiven() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo cc = categoryComboWithTwoCategories();
program.setCategoryCombo(cc);
CategoryOptionCombo aoc = firstCategoryOptionCombo(cc);
when(preheat.getCategoryOptionCombo(aoc.getUid())).thenReturn(aoc);
CategoryOption co1 = (CategoryOption) aoc.getCategoryOptions().toArray()[0];
when(preheat.getCategoryOption(co1.getUid())).thenReturn(co1);
Event event = eventBuilder().attributeOptionCombo(aoc.getUid()).attributeCategoryOptions(co1.getUid()).build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1053 && r.getErrorMessage().contains(co1.getUid()) && r.getErrorMessage().contains(aoc.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.CategoryOption in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenOnlyCOsAreSetButAOCCannotBeFound.
@Test
void eventValidationFailsWhenOnlyCOsAreSetButAOCCannotBeFound() {
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);
when(categoryService.getCategoryOptionCombo(cc, Sets.newHashSet(co))).thenReturn(null);
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.CategoryOption in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAOCAndEventCOsAreSetAndCOIsNotInProgramCC.
@Test
void eventValidationFailsWhenEventAOCAndEventCOsAreSetAndCOIsNotInProgramCC() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo cc = categoryCombo();
program.setCategoryCombo(cc);
CategoryOptionCombo aoc = firstCategoryOptionCombo(cc);
when(preheat.getCategoryOptionCombo(aoc.getUid())).thenReturn(aoc);
CategoryOption eventCO = createCategoryOption('C');
when(preheat.getCategoryOption(eventCO.getUid())).thenReturn(eventCO);
Event event = eventBuilder().attributeOptionCombo(aoc.getUid()).attributeCategoryOptions(eventCO.getUid()).build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1053 && r.getErrorMessage().contains(eventCO.getUid()) && r.getErrorMessage().contains(aoc.getUid())));
assertNull(reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should not be cached");
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DhisConvenienceTest method createCategory.
/**
* @param categoryUniqueIdentifier A unique character to identify the
* category.
* @param categoryOptions the category options.
* @return Category
*/
public static Category createCategory(char categoryUniqueIdentifier, CategoryOption... categoryOptions) {
Category category = new Category("Category" + categoryUniqueIdentifier, DataDimensionType.DISAGGREGATION);
category.setAutoFields();
category.setShortName(category.getName());
for (CategoryOption categoryOption : categoryOptions) {
category.addCategoryOption(categoryOption);
}
return category;
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DhisConvenienceTest method createCategoryOptionGroup.
/**
* @param uniqueIdentifier A unique character to identify the category
* option group.
* @param categoryOptions the category options.
* @return CategoryOptionGroup
*/
public static CategoryOptionGroup createCategoryOptionGroup(char uniqueIdentifier, CategoryOption... categoryOptions) {
CategoryOptionGroup categoryOptionGroup = new CategoryOptionGroup("CategoryOptionGroup" + uniqueIdentifier);
categoryOptionGroup.setShortName("ShortName" + uniqueIdentifier);
categoryOptionGroup.setAutoFields();
categoryOptionGroup.setMembers(new HashSet<>());
for (CategoryOption categoryOption : categoryOptions) {
categoryOptionGroup.addCategoryOption(categoryOption);
}
return categoryOptionGroup;
}
Aggregations