use of org.hisp.dhis.programrule.ProgramRuleVariable in project dhis2-core by dhis2.
the class ProgramRuleEngineTest method setupProgramRuleEngine.
private void setupProgramRuleEngine() {
programRuleA = createProgramRule('C', programA);
programRuleA.setCondition(expressionA);
programRuleService.addProgramRule(programRuleA);
programRuleA2 = createProgramRule('Z', programA);
programRuleA2.setCondition(calculatedDateExpression);
programRuleService.addProgramRule(programRuleA2);
programRuleC = createProgramRule('X', programA);
programRuleC.setCondition(expressionC);
programRuleService.addProgramRule(programRuleC);
programRuleE = createProgramRule('E', programB);
programRuleE.setCondition(expressionE);
programRuleService.addProgramRule(programRuleE);
programRuleS = createProgramRule('S', programS);
programRuleS.setCondition(expressionS);
programRuleService.addProgramRule(programRuleS);
ProgramRuleVariable programRuleVariableEmail = createProgramRuleVariableWithTEA('E', programB, attributeEmail);
programRuleVariableEmail.setName("attribute_email");
programRuleVariableService.addProgramRuleVariable(programRuleVariableEmail);
ProgramRuleVariable programRuleVariableA = createProgramRuleVariableWithDataElement('A', programA, dataElementA);
programRuleVariableService.addProgramRuleVariable(programRuleVariableA);
ProgramRuleVariable programRuleVariableB = createProgramRuleVariableWithDataElement('B', programA, dataElementB);
programRuleVariableService.addProgramRuleVariable(programRuleVariableB);
ProgramRuleVariable programRuleVariableDate = createProgramRuleVariableWithDataElement('X', programA, dataElementDate);
programRuleVariableDate.setName("DOB");
programRuleVariableService.addProgramRuleVariable(programRuleVariableDate);
ProgramRuleVariable programRuleVariableAge = createProgramRuleVariableWithDataElement('K', programA, dataElementAge);
programRuleVariableAge.setName("AGE");
programRuleVariableService.addProgramRuleVariable(programRuleVariableAge);
ProgramRuleVariable programRuleVariableD = createProgramRuleVariableWithTEA('D', programA, attributeB);
programRuleVariableService.addProgramRuleVariable(programRuleVariableD);
ProgramRuleVariable programRuleVariableS = createConstantProgramRuleVariable('S', programS);
programRuleVariableS.setSourceType(ProgramRuleVariableSourceType.TEI_ATTRIBUTE);
programRuleVariableS.setAttribute(attributeB);
programRuleVariableS.setValueType(attributeB.getValueType());
programRuleVariableService.addProgramRuleVariable(programRuleVariableS);
ProgramRuleVariable programRuleVariableC = createConstantProgramRuleVariable('C', programA);
programRuleVariableC.setSourceType(ProgramRuleVariableSourceType.TEI_ATTRIBUTE);
programRuleVariableC.setAttribute(attributeA);
programRuleVariableC.setValueType(attributeA.getValueType());
programRuleVariableService.addProgramRuleVariable(programRuleVariableC);
}
use of org.hisp.dhis.programrule.ProgramRuleVariable in project dhis2-core by dhis2.
the class ProgramRuleVariableObjectBundleHookTest method shouldFailUpdateExistingDifferentUid.
@Test
void shouldFailUpdateExistingDifferentUid() {
when(programRuleVariable.getProgram()).thenReturn(program);
when(objectBundle.getImportMode()).thenReturn(ImportStrategy.CREATE_AND_UPDATE);
ProgramRuleVariable existingProgramRuleVariable = new ProgramRuleVariable();
existingProgramRuleVariable.setName("word");
existingProgramRuleVariable.setUid("uid1");
when(query.getResultList()).thenReturn(Collections.singletonList(existingProgramRuleVariable));
when(programRuleVariable.getName()).thenReturn("word");
when(programRuleVariable.getUid()).thenReturn("uid2");
List<ErrorReport> errorReports = programRuleVariableObjectBundleHook.validate(programRuleVariable, objectBundle);
assertEquals(1, errorReports.size());
assertTrue(errorReports.stream().anyMatch(e -> e.getErrorCode().equals(E4051)));
}
use of org.hisp.dhis.programrule.ProgramRuleVariable 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)));
}
}
use of org.hisp.dhis.programrule.ProgramRuleVariable in project dhis2-core by dhis2.
the class ProgramRuleVariableObjectBundleHookTest method shouldNotFailUpdateExistingMoreThanOneSameUid.
@Test
void shouldNotFailUpdateExistingMoreThanOneSameUid() {
when(programRuleVariable.getProgram()).thenReturn(program);
when(objectBundle.getImportMode()).thenReturn(ImportStrategy.CREATE_AND_UPDATE);
ProgramRuleVariable existingProgramRuleVariable = new ProgramRuleVariable();
existingProgramRuleVariable.setName("word");
existingProgramRuleVariable.setUid("uid1");
ProgramRuleVariable anotherExistingProgramRuleVariable = new ProgramRuleVariable();
anotherExistingProgramRuleVariable.setName("word");
anotherExistingProgramRuleVariable.setUid("uid2");
when(query.getResultList()).thenReturn(ImmutableList.of(existingProgramRuleVariable, anotherExistingProgramRuleVariable));
when(programRuleVariable.getName()).thenReturn("word");
when(programRuleVariable.getUid()).thenReturn("uid1");
List<ErrorReport> errorReports = programRuleVariableObjectBundleHook.validate(programRuleVariable, objectBundle);
assertEquals(0, errorReports.size());
}
use of org.hisp.dhis.programrule.ProgramRuleVariable in project dhis2-core by dhis2.
the class ProgramRuleVariableObjectBundleHookTest method shouldNotFailUpdateExistingSameUid.
@Test
void shouldNotFailUpdateExistingSameUid() {
when(programRuleVariable.getProgram()).thenReturn(program);
when(objectBundle.getImportMode()).thenReturn(ImportStrategy.CREATE_AND_UPDATE);
ProgramRuleVariable existingProgramRuleVariable = new ProgramRuleVariable();
existingProgramRuleVariable.setName("word");
existingProgramRuleVariable.setUid("uid1");
when(query.getResultList()).thenReturn(Collections.singletonList(existingProgramRuleVariable));
when(programRuleVariable.getName()).thenReturn("word");
when(programRuleVariable.getUid()).thenReturn("uid1");
List<ErrorReport> errorReports = programRuleVariableObjectBundleHook.validate(programRuleVariable, objectBundle);
assertEquals(0, errorReports.size());
}
Aggregations