use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class ValidationServiceTest method testValidateWithCategoryOptions.
@Test
void testValidateWithCategoryOptions() {
CategoryOption optionA = new CategoryOption("CategoryOptionA");
CategoryOption optionB = new CategoryOption("CategoryOptionB");
categoryService.addCategoryOption(optionA);
categoryService.addCategoryOption(optionB);
Category categoryA = createCategory('A', optionA, optionB);
categoryService.addCategory(categoryA);
CategoryCombo categoryComboA = createCategoryCombo('A', categoryA);
categoryService.addCategoryCombo(categoryComboA);
CategoryOptionCombo optionComboA = createCategoryOptionCombo(categoryComboA, optionA);
CategoryOptionCombo optionComboB = createCategoryOptionCombo(categoryComboA, optionB);
categoryService.addCategoryOptionCombo(optionComboA);
categoryService.addCategoryOptionCombo(optionComboB);
useDataValue(dataElementD, periodA, sourceA, "3", optionComboA, optionCombo);
useDataValue(dataElementD, periodA, sourceA, "4", optionComboB, optionCombo);
Expression expressionZ = new Expression("#{" + dataElementD.getUid() + "." + optionComboA.getUid() + "} * 2" + " + #{" + dataElementD.getUid() + "." + optionComboB.getUid() + "}", "expressionZ", NEVER_SKIP);
Expression expressionV = new Expression("#{" + dataElementD.getUid() + "}", "expressionV", NEVER_SKIP);
ValidationRule validationRuleZ = createValidationRule("Z", equal_to, expressionV, expressionZ, ptMonthly);
// deD[all] = deD.optionComboA * 2 + deD.optionComboB
validationRuleService.saveValidationRule(validationRuleZ);
Collection<ValidationResult> results = validationService.validationAnalysis(validationService.newParamsBuilder(dataSetMonthly, sourceA, periodA).build());
Collection<ValidationResult> reference = new HashSet<>();
reference.add(new ValidationResult(validationRuleZ, periodA, sourceA, defaultCombo, 7.0, 10.0, dayInPeriodA));
assertResultsEquals(reference, results);
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class ProgramMapperTest method testCategoryComboIsSetForNonDefaultCategoryCombos.
@Test
void testCategoryComboIsSetForNonDefaultCategoryCombos() {
Program program = new Program();
CategoryCombo cc = createCategoryCombo('A');
assertFalse(cc.isDefault(), "tests rely on this CC NOT being the default one");
program.setCategoryCombo(cc);
Program mappedProgram = ProgramMapper.INSTANCE.map(program);
assertEquals(cc, mappedProgram.getCategoryCombo());
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenNoAOCAndNoCOsAreSetAndProgramHasNonDefaultCC.
@Test
void eventValidationFailsWhenNoAOCAndNoCOsAreSetAndProgramHasNonDefaultCC() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
program.setCategoryCombo(categoryCombo());
Event event = eventBuilder().build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1055));
assertNull(reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should not be cached");
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationSucceedsWhenEventAOCAndEventCOsAreSetAndProgramHasDefaultCC.
@Test
void eventValidationSucceedsWhenEventAOCAndEventCOsAreSetAndProgramHasDefaultCC() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo defaultCC = defaultCategoryCombo();
program.setCategoryCombo(defaultCC);
CategoryOptionCombo defaultAOC = firstCategoryOptionCombo(defaultCC);
when(preheat.getCategoryOptionCombo(defaultAOC.getUid())).thenReturn(defaultAOC);
CategoryOption defaultCO = defaultCC.getCategoryOptions().get(0);
program.setCategoryCombo(defaultCC);
when(preheat.getCategoryOption(defaultCO.getUid())).thenReturn(defaultCO);
Event event = eventBuilder().attributeOptionCombo(defaultAOC.getUid()).attributeCategoryOptions(defaultCO.getUid()).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.CategoryCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenOnlyCOsAreSetToCONotInProgramCC.
@Test
void eventValidationFailsWhenOnlyCOsAreSetToCONotInProgramCC() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo cc = categoryCombo();
program.setCategoryCombo(cc);
CategoryOption co = createCategoryOption('B');
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());
}
Aggregations