use of org.drools.scenariosimulation.api.model.FactIdentifier in project drools-wb by kiegroup.
the class AbstractSelectedColumnCommand method setInstanceHeader.
/**
* Sets the instance header for a <code>ScenarioSimulationContext</code>.
* @param context It contains the <b>Context</b> inside which the commands will be executed
* @param selectedColumn The selected <code>ScenarioGridColumn</code> where the command was launched
*/
protected void setInstanceHeader(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn, String alias, String fullClassName) {
int columnIndex = context.getAbstractScesimGridModelByGridWidget(gridWidget).getColumns().indexOf(selectedColumn);
final FactIdentifier factIdentifier = setEditableHeadersAndGetFactIdentifier(context, selectedColumn, alias, fullClassName);
setInstanceHeaderMetaData(selectedColumn, alias, factIdentifier);
final ScenarioHeaderMetaData propertyHeaderMetaData = selectedColumn.getPropertyHeaderMetaData();
setPropertyMetaData(propertyHeaderMetaData, getPropertyPlaceHolder(columnIndex), false, selectedColumn, ScenarioSimulationUtils.getPlaceHolder(selectedColumn.isInstanceAssigned(), selectedColumn.isPropertyAssigned(), factMappingValueType, fullClassName));
context.getAbstractScesimGridModelByGridWidget(gridWidget).updateColumnInstance(columnIndex, selectedColumn);
if (context.getScenarioSimulationEditorPresenter() != null) {
context.getScenarioSimulationEditorPresenter().reloadTestTools(false);
}
}
use of org.drools.scenariosimulation.api.model.FactIdentifier 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.FactIdentifier in project drools by kiegroup.
the class RuleScenarioRunnerHelper method verifyConditions.
@Override
protected void verifyConditions(ScesimModelDescriptor scesimModelDescriptor, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, Map<String, Object> requestContext) {
for (InstanceGiven input : scenarioRunnerData.getGivens()) {
FactIdentifier factIdentifier = input.getFactIdentifier();
List<ScenarioExpect> assertionOnFact = scenarioRunnerData.getExpects().stream().filter(elem -> !elem.isNewFact()).filter(elem -> Objects.equals(elem.getFactIdentifier(), factIdentifier)).collect(toList());
// check if this fact has something to check
if (assertionOnFact.isEmpty()) {
continue;
}
getScenarioResultsFromGivenFacts(scesimModelDescriptor, assertionOnFact, input, expressionEvaluatorFactory).forEach(scenarioRunnerData::addResult);
}
}
use of org.drools.scenariosimulation.api.model.FactIdentifier in project drools by kiegroup.
the class RuleScenarioRunnerHelperTest method groupByFactIdentifierAndFilterTest.
@Test
public void groupByFactIdentifierAndFilterTest() {
Map<FactIdentifier, List<FactMappingValue>> scenario1Given = runnerHelper.groupByFactIdentifierAndFilter(scenario1.getUnmodifiableFactMappingValues(), FactMappingType.GIVEN);
Map<FactIdentifier, List<FactMappingValue>> scenario1Expected = runnerHelper.groupByFactIdentifierAndFilter(scenario1.getUnmodifiableFactMappingValues(), FactMappingType.EXPECT);
Map<FactIdentifier, List<FactMappingValue>> scenario2Given = runnerHelper.groupByFactIdentifierAndFilter(scenario2.getUnmodifiableFactMappingValues(), FactMappingType.GIVEN);
Map<FactIdentifier, List<FactMappingValue>> scenario2Expected = runnerHelper.groupByFactIdentifierAndFilter(scenario2.getUnmodifiableFactMappingValues(), FactMappingType.EXPECT);
assertEquals(1, scenario1Given.keySet().size());
assertEquals(1, scenario1Expected.keySet().size());
assertEquals(2, scenario2Given.keySet().size());
assertEquals(2, scenario2Expected.keySet().size());
assertEquals(1, scenario1Given.get(personFactIdentifier).size());
assertEquals(1, scenario1Expected.get(personFactIdentifier).size());
assertEquals(1, scenario2Given.get(disputeFactIdentifier).size());
assertEquals(1, scenario2Expected.get(disputeFactIdentifier).size());
Scenario scenario = new Scenario();
scenario.addMappingValue(FactIdentifier.EMPTY, ExpressionIdentifier.DESCRIPTION, null);
assertEquals(0, runnerHelper.groupByFactIdentifierAndFilter(scenario.getUnmodifiableFactMappingValues(), FactMappingType.GIVEN).size());
}
use of org.drools.scenariosimulation.api.model.FactIdentifier in project drools by kiegroup.
the class AbstractRunnerHelper method extractGivenValues.
protected List<InstanceGiven> extractGivenValues(ScesimModelDescriptor scesimModelDescriptor, List<FactMappingValue> factMappingValues, ClassLoader classLoader, ExpressionEvaluatorFactory expressionEvaluatorFactory) {
List<InstanceGiven> instanceGiven = new ArrayList<>();
Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = groupByFactIdentifierAndFilter(factMappingValues, FactMappingType.GIVEN);
boolean hasError = false;
for (Map.Entry<FactIdentifier, List<FactMappingValue>> entry : groupByFactIdentifier.entrySet()) {
try {
FactIdentifier factIdentifier = entry.getKey();
// for each fact, create a map of path to fields and values to set
Map<List<String>, Object> paramsForBean = getParamsForBean(scesimModelDescriptor, factIdentifier, entry.getValue(), expressionEvaluatorFactory);
Object bean = createObject(getDirectMapping(paramsForBean), factIdentifier.getClassName(), paramsForBean, classLoader);
instanceGiven.add(new InstanceGiven(factIdentifier, bean));
} catch (Exception e) {
String errorMessage = e.getMessage() != null ? e.getMessage() : e.getClass().getCanonicalName();
logger.error("Error in GIVEN data " + entry.getKey() + ": " + errorMessage, e);
hasError = true;
}
}
if (hasError) {
throw new ScenarioException("Error in GIVEN data");
}
return instanceGiven;
}
Aggregations