use of org.drools.scenariosimulation.api.model.FactMapping in project drools by kiegroup.
the class DMNScenarioRunnerHelper method verifyConditions.
@Override
protected void verifyConditions(ScesimModelDescriptor scesimModelDescriptor, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, Map<String, Object> requestContext) {
DMNResult dmnResult = (DMNResult) requestContext.get(DMNScenarioExecutableBuilder.DMN_RESULT);
List<DMNMessage> dmnMessages = dmnResult.getMessages();
for (ScenarioExpect output : scenarioRunnerData.getExpects()) {
FactIdentifier factIdentifier = output.getFactIdentifier();
String decisionName = factIdentifier.getName();
DMNDecisionResult decisionResult = dmnResult.getDecisionResultByName(decisionName);
if (decisionResult == null) {
throw new ScenarioException("DMN execution has not generated a decision result with name " + decisionName);
}
for (FactMappingValue expectedResult : output.getExpectedResult()) {
ExpressionIdentifier expressionIdentifier = expectedResult.getExpressionIdentifier();
FactMapping factMapping = scesimModelDescriptor.getFactMapping(factIdentifier, expressionIdentifier).orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen"));
ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(expectedResult);
ScenarioResult scenarioResult = fillResult(expectedResult, () -> getSingleFactValueResult(factMapping, expectedResult, decisionResult, dmnMessages, expressionEvaluator), expressionEvaluator);
scenarioRunnerData.addResult(scenarioResult);
}
}
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools by kiegroup.
the class AbstractRunnerHelper method throwScenarioException.
private void throwScenarioException(FactMappingValue factMappingValue, ScesimModelDescriptor scesimModelDescriptor) {
FactMapping factMapping = scesimModelDescriptor.getFactMapping(factMappingValue.getFactIdentifier(), factMappingValue.getExpressionIdentifier()).orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen"));
String factName = String.join(".", factMapping.getExpressionElements().stream().map(ExpressionElement::getStep).collect(Collectors.toList()));
if (FactMappingValueStatus.FAILED_WITH_ERROR == factMappingValue.getStatus()) {
throw new ScenarioException(determineExceptionMessage(factMappingValue, factName), true);
} else if (FactMappingValueStatus.FAILED_WITH_EXCEPTION == factMappingValue.getStatus()) {
throw new ScenarioException(ScenarioSimulationServerMessages.getGenericScenarioExceptionMessage(factMappingValue.getExceptionMessage()));
} else {
throw new IllegalStateException("Illegal FactMappingValue status");
}
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class ScenarioCsvImportExportTest method createFactMapping.
private FactMapping createFactMapping(ScesimModelDescriptor simulationDescriptor, int number) {
FactMapping toReturn = simulationDescriptor.addFactMapping(FactIdentifier.create(instanceName + number, String.class.getCanonicalName()), ExpressionIdentifier.create(propertyName + number, FactMappingType.GIVEN));
toReturn.setExpressionAlias(propertyName + number);
return toReturn;
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategyTest method addToScenarioMultipleNested.
@Test
public void addToScenarioMultipleNested() {
FactMapping factMappingMock = mock(FactMapping.class);
DMNSimulationSettingsCreationStrategy.FactMappingExtractor factMappingExtractorMock = mock(DMNSimulationSettingsCreationStrategy.FactMappingExtractor.class);
when(factMappingExtractorMock.getFactMapping(any(), anyString(), any(), anyString())).thenReturn(factMappingMock);
Map<String, FactModelTree> hiddenFacts = new HashMap<>();
FactModelTree factModelTree = new FactModelTree("myFact", "", new HashMap<>(), Collections.emptyMap());
factModelTree.addExpandableProperty("nestedProperty", "tNested");
factModelTree.addExpandableProperty("nestedProperty2", "tNested2");
FactModelTree nested1 = new FactModelTree("tNested1", "", new HashMap<>(), Collections.emptyMap());
FactModelTree nested2 = new FactModelTree("tNested2", "", new HashMap<>(), Collections.emptyMap());
String propertyType = String.class.getCanonicalName();
String propertyName = "stingProperty";
nested1.addSimpleProperty(propertyName, new FactModelTree.PropertyTypeName(propertyType));
String propertyType2 = Boolean.class.getCanonicalName();
String propertyName2 = "booleanProperty";
nested2.addSimpleProperty(propertyName2, new FactModelTree.PropertyTypeName(propertyType2));
hiddenFacts.put("tNested", nested1);
hiddenFacts.put("tNested2", nested2);
dmnSimulationCreationStrategy.addFactMapping(factMappingExtractorMock, factModelTree, new ArrayList<>(), hiddenFacts);
verify(factMappingExtractorMock, times(1)).getFactMapping(eq(nested1), eq(propertyName), eq(Arrays.asList("myFact", "nestedProperty")), eq(propertyType));
verify(factMappingExtractorMock, times(1)).getFactMapping(eq(nested2), eq(propertyName2), eq(Arrays.asList("myFact", "nestedProperty2")), eq(propertyType2));
verify(factMappingExtractorMock, times(2)).getFactMapping(any(), any(), any(), any());
}
use of org.drools.scenariosimulation.api.model.FactMapping in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategyTest method addToScenarioRecursive.
@Test
public void addToScenarioRecursive() {
FactMapping factMappingMock = mock(FactMapping.class);
DMNSimulationSettingsCreationStrategy.FactMappingExtractor factMappingExtractorMock = mock(DMNSimulationSettingsCreationStrategy.FactMappingExtractor.class);
when(factMappingExtractorMock.getFactMapping(any(), anyString(), any(), anyString())).thenReturn(factMappingMock);
Map<String, FactModelTree> hiddenFacts = new HashMap<>();
FactModelTree factModelTree = new FactModelTree("myFact", "", new HashMap<>(), Collections.emptyMap());
factModelTree.addExpandableProperty("recursiveProperty", "recursive");
String propertyType = String.class.getCanonicalName();
String propertyName = "simpleProperty";
factModelTree.addSimpleProperty(propertyName, new FactModelTree.PropertyTypeName(propertyType));
hiddenFacts.put("recursive", factModelTree);
dmnSimulationCreationStrategy.addFactMapping(factMappingExtractorMock, factModelTree, new ArrayList<>(), hiddenFacts);
verify(factMappingExtractorMock, times(1)).getFactMapping(eq(factModelTree), eq(propertyName), eq(Arrays.asList("myFact", "recursiveProperty")), eq(propertyType));
verify(factMappingExtractorMock, times(2)).getFactMapping(any(), any(), any(), any());
}
Aggregations