use of org.hisp.dhis.dxf2.Constants.PROGRAM_RULE_VARIABLE_NAME_INVALID_KEYWORDS in project dhis2-core by dhis2.
the class ProgramRuleVariableObjectBundleHookTest method shouldFailValidationInvalidName.
@Test
void shouldFailValidationInvalidName() {
when(programRuleVariable.getProgram()).thenReturn(program);
when(objectBundle.getImportMode()).thenReturn(ImportStrategy.CREATE_AND_UPDATE);
List<ErrorReport> errorReports;
for (String invalidKeyWord : PROGRAM_RULE_VARIABLE_NAME_INVALID_KEYWORDS) {
when(programRuleVariable.getName()).thenReturn("Word " + invalidKeyWord + " Word");
errorReports = programRuleVariableObjectBundleHook.validate(programRuleVariable, objectBundle);
assertEquals(1, errorReports.size());
assertTrue(errorReports.stream().anyMatch(e -> e.getErrorCode().equals(E4052)));
when(programRuleVariable.getName()).thenReturn(invalidKeyWord + " Word");
errorReports = programRuleVariableObjectBundleHook.validate(programRuleVariable, objectBundle);
assertEquals(1, errorReports.size());
assertTrue(errorReports.stream().anyMatch(e -> e.getErrorCode().equals(E4052)));
when(programRuleVariable.getName()).thenReturn("Word " + invalidKeyWord);
errorReports = programRuleVariableObjectBundleHook.validate(programRuleVariable, objectBundle);
assertEquals(1, errorReports.size());
assertTrue(errorReports.stream().anyMatch(e -> e.getErrorCode().equals(E4052)));
}
}
Aggregations