use of org.kie.dmn.feel.runtime.UnaryTestImpl in project drools by kiegroup.
the class FEELSchemaEnum method evaluateUnaryTests.
private static List<Object> evaluateUnaryTests(List<DMNUnaryTest> list) {
FEEL SimpleFEEL = FEEL.newInstance();
List<Object> utEvaluated = list.stream().map(UnaryTestImpl.class::cast).map(UnaryTestImpl::toString).map(SimpleFEEL::evaluate).collect(Collectors.toList());
return utEvaluated;
}
use of org.kie.dmn.feel.runtime.UnaryTestImpl in project drools-wb by kiegroup.
the class DMNScenarioValidationTest method validate.
@Test
public void validate() {
DMNScenarioValidation validationSpy = spy(new DMNScenarioValidation() {
@Override
protected DMNModel getDMNModel(KieContainer kieContainer, String dmnPath) {
return dmnModelMock;
}
});
// Test 0 - skip empty or not GIVEN/EXPECT columns
Simulation test0 = new Simulation();
test0.getScesimModelDescriptor().addFactMapping(FactIdentifier.DESCRIPTION, ExpressionIdentifier.create(VALUE, FactMappingType.OTHER));
test0.getScesimModelDescriptor().addFactMapping(FactIdentifier.EMPTY, ExpressionIdentifier.create(VALUE, FactMappingType.GIVEN));
List<FactMappingValidationError> errorsTest0 = validationSpy.validate(test0, settingsLocal, null);
checkResult(errorsTest0);
// Test 1 - simple type
Simulation test1 = new Simulation();
test1.getScesimModelDescriptor().addFactMapping(FactIdentifier.create("mySimpleType", "tMYSIMPLETYPE"), ExpressionIdentifier.create(VALUE, FactMappingType.GIVEN));
createDMNType("mySimpleType", "mySimpleType");
List<FactMappingValidationError> errorsTest1 = validationSpy.validate(test1, settingsLocal, null);
checkResult(errorsTest1);
// Test 2 - nested field
Simulation test2 = new Simulation();
// nameFM is valid
FactIdentifier myComplexFactIdentifier = FactIdentifier.create("myComplexType", "tMYCOMPLEXTYPE");
FactMapping nameFM = test2.getScesimModelDescriptor().addFactMapping(myComplexFactIdentifier, ExpressionIdentifier.create("name", FactMappingType.GIVEN));
nameFM.addExpressionElement("tMYCOMPLEXTYPE", "tMYCOMPLEXTYPE");
nameFM.addExpressionElement("name", "tNAME");
createDMNType("myComplexType", "myComplexType", "name");
// parentFM is valid
FactMapping parentFM = test2.getScesimModelDescriptor().addFactMapping(myComplexFactIdentifier, ExpressionIdentifier.create("parent", FactMappingType.EXPECT));
parentFM.addExpressionElement("tMYCOMPLEXTYPE", "tMYCOMPLEXTYPE");
parentFM.addExpressionElement("parent", "tPARENT");
createDMNType("myComplexType", "myComplexType", "parent");
List<FactMappingValidationError> errorsTest2 = validationSpy.validate(test2, settingsLocal, null);
checkResult(errorsTest2);
// parentFM is not valid anymore
parentFM.addExpressionElement("notExisting", "notExisting");
errorsTest2 = validationSpy.validate(test2, settingsLocal, null);
checkResult(errorsTest2, new ExpectedError("Impossible to find field 'notExisting' in type 'tPARENT'"));
// nameWrongTypeFM has a wrong type
FactMapping nameWrongTypeFM = test2.getScesimModelDescriptor().addFactMapping(myComplexFactIdentifier, ExpressionIdentifier.create("parent2", FactMappingType.EXPECT));
nameWrongTypeFM.addExpressionElement("tMYCOMPLEXTYPE", "tMYCOMPLEXTYPE");
nameWrongTypeFM.addExpressionElement("name", Integer.class.getCanonicalName());
errorsTest2 = validationSpy.validate(test2, settingsLocal, null);
checkResult(errorsTest2, new ExpectedError("Impossible to find field 'notExisting' in type 'tPARENT'"), new ExpectedError(ScenarioSimulationI18nServerMessage.SCENARIO_VALIDATION_FIELD_CHANGED_ERROR, Arrays.asList("java.lang.Integer", "tNAME")));
// color parameter - Constraint added for its type (string to tColor with allowed values)
FactMapping colorsAddedConstraintFM = test2.getScesimModelDescriptor().addFactMapping(myComplexFactIdentifier, ExpressionIdentifier.create("parent3", FactMappingType.GIVEN));
colorsAddedConstraintFM.addExpressionElement("tMYCOMPLEXTYPE", "tMYCOMPLEXTYPE");
colorsAddedConstraintFM.addExpressionElement("color", BuiltInType.STRING.getName());
createDMNType("myComplexType", "myComplexType", "color");
DMNType baseDMNType = initDMNType(BuiltInType.STRING);
when(mapOfMockDecisions.get("myComplexType").getResultType().getFields().get("color").getAllowedValues()).thenReturn(Arrays.asList(new UnaryTestImpl(null, "Value")));
when(mapOfMockDecisions.get("myComplexType").getResultType().getFields().get("color").getBaseType()).thenReturn(baseDMNType);
errorsTest2 = validationSpy.validate(test2, settingsLocal, null);
checkResult(errorsTest2, new ExpectedError("Impossible to find field 'notExisting' in type 'tPARENT'"), new ExpectedError(ScenarioSimulationI18nServerMessage.SCENARIO_VALIDATION_FIELD_CHANGED_ERROR, Arrays.asList("java.lang.Integer", "tNAME")), new ExpectedError(ScenarioSimulationI18nServerMessage.SCENARIO_VALIDATION_FIELD_ADDED_CONSTRAINT_ERROR, Collections.emptyList()));
// age parameter - Constraint removed for its type (tAge to numeric without allowed values)
FactMapping ageConstraintFM = test2.getScesimModelDescriptor().addFactMapping(myComplexFactIdentifier, ExpressionIdentifier.create("parent4", FactMappingType.GIVEN));
ageConstraintFM.addExpressionElement("tMYCOMPLEXTYPE", "tMYCOMPLEXTYPE");
ageConstraintFM.addExpressionElement("age", "age");
createDMNType("myComplexType", "myComplexType", "age");
errorsTest2 = validationSpy.validate(test2, settingsLocal, null);
checkResult(errorsTest2, new ExpectedError("Impossible to find field 'notExisting' in type 'tPARENT'"), new ExpectedError(ScenarioSimulationI18nServerMessage.SCENARIO_VALIDATION_FIELD_CHANGED_ERROR, Arrays.asList("java.lang.Integer", "tNAME")), new ExpectedError(ScenarioSimulationI18nServerMessage.SCENARIO_VALIDATION_FIELD_ADDED_CONSTRAINT_ERROR, Collections.emptyList()), new ExpectedError(ScenarioSimulationI18nServerMessage.SCENARIO_VALIDATION_FIELD_REMOVED_CONSTRAINT_ERROR, Collections.emptyList()));
// Test 3 - list
Simulation test3 = new Simulation();
// topLevelListFM is valid
FactMapping topLevelListFM = test3.getScesimModelDescriptor().addFactMapping(FactIdentifier.create("myList", List.class.getCanonicalName()), ExpressionIdentifier.create("name", FactMappingType.GIVEN));
topLevelListFM.addExpressionElement("tPERSON", List.class.getCanonicalName());
topLevelListFM.setGenericTypes(Collections.singletonList("tPERSON"));
createDMNType("myList", "person");
when(mapOfMockDecisions.get("myList").getResultType().isCollection()).thenReturn(true);
// addressesFM is valid
FactMapping addressesFM = test3.getScesimModelDescriptor().addFactMapping(FactIdentifier.create("myComplexObject", "tMYCOMPLEXOBJECT"), ExpressionIdentifier.create("addresses", FactMappingType.EXPECT));
addressesFM.addExpressionElement("tMYCOMPLEXOBJECT", "tMYCOMPLEXOBJECT");
addressesFM.addExpressionElement("addresses", List.class.getCanonicalName());
addressesFM.setGenericTypes(Collections.singletonList("tADDRESSES"));
createDMNType("myComplexObject", "myComplexObject", "addresses");
when(mapOfMockDecisions.get("myComplexObject").getResultType().getFields().get("addresses").isCollection()).thenReturn(true);
List<FactMappingValidationError> errorsTest3 = validationSpy.validate(test3, settingsLocal, null);
checkResult(errorsTest3);
// Test 4 - not existing node
Simulation test4 = new Simulation();
FactMapping factMappingNodeRemoved = test4.getScesimModelDescriptor().addFactMapping(FactIdentifier.create("mySimpleType", "tMYSIMPLETYPE"), ExpressionIdentifier.create(VALUE, FactMappingType.GIVEN));
factMappingNodeRemoved.addExpressionElement("tMYSIMPLETYPE", "tMYSIMPLETYPE");
when(dmnModelMock.getDecisionByName(anyString())).thenReturn(null);
List<FactMappingValidationError> errorsTest4 = validationSpy.validate(test4, settingsLocal, null);
checkResult(errorsTest4, new ExpectedError(ScenarioSimulationI18nServerMessage.SCENARIO_VALIDATION_NODE_CHANGED_ERROR, Arrays.asList("tMYSIMPLETYPE", "node not found")));
}
Aggregations