use of org.drools.scenariosimulation.backend.runner.model.ScenarioResult in project drools by kiegroup.
the class ConditionFilterTest method acceptTest.
@Test
public void acceptTest() {
Function<Object, ValueWrapper> alwaysMatchFunction = ValueWrapper::of;
FactMappingValue factMappingValue = new FactMappingValue(FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION, "Test");
ScenarioResult scenarioResult = new ScenarioResult(factMappingValue);
ConditionFilter conditionFilter = new ConditionFilter(singletonList(new FactCheckerHandle(String.class, alwaysMatchFunction, scenarioResult)));
Assert.assertFalse(conditionFilter.accept(1));
Assert.assertTrue(conditionFilter.accept("String"));
Function<Object, ValueWrapper> alwaysNotMatchFunction = object -> ValueWrapper.errorWithValidValue(null, null);
ConditionFilter conditionFilterFail = new ConditionFilter(singletonList(new FactCheckerHandle(String.class, alwaysNotMatchFunction, scenarioResult)));
Assert.assertFalse(conditionFilterFail.accept("String"));
}
use of org.drools.scenariosimulation.backend.runner.model.ScenarioResult in project drools by kiegroup.
the class RuleStatelessScenarioExecutableBuilderTest method generateCommands.
@Test
public void generateCommands() {
FactMappingValue emptyFMV = new FactMappingValue(FactIdentifier.EMPTY, ExpressionIdentifier.DESCRIPTION, null);
RuleStatelessScenarioExecutableBuilder builder = new RuleStatelessScenarioExecutableBuilder(null, null);
Command<ExecutionResults> batchCommand = builder.generateCommands(null);
assertTrue(verifyCommand(batchCommand, AddCoverageListenerCommand.class));
assertTrue(verifyCommand(batchCommand, FireAllRulesCommand.class));
assertFalse(verifyCommand(batchCommand, AgendaGroupSetFocusCommand.class));
assertFalse(verifyCommand(batchCommand, InsertElementsCommand.class));
assertFalse(verifyCommand(batchCommand, ValidateFactCommand.class));
builder.setActiveAgendaGroup("test");
batchCommand = builder.generateCommands(null);
assertTrue(verifyCommand(batchCommand, AddCoverageListenerCommand.class));
assertTrue(verifyCommand(batchCommand, FireAllRulesCommand.class));
assertTrue(verifyCommand(batchCommand, AgendaGroupSetFocusCommand.class));
assertFalse(verifyCommand(batchCommand, InsertElementsCommand.class));
assertFalse(verifyCommand(batchCommand, ValidateFactCommand.class));
builder.insert(new Object());
batchCommand = builder.generateCommands(null);
assertTrue(verifyCommand(batchCommand, AddCoverageListenerCommand.class));
assertTrue(verifyCommand(batchCommand, FireAllRulesCommand.class));
assertTrue(verifyCommand(batchCommand, AgendaGroupSetFocusCommand.class));
assertTrue(verifyCommand(batchCommand, InsertElementsCommand.class));
assertFalse(verifyCommand(batchCommand, ValidateFactCommand.class));
builder.addInternalCondition(String.class, obj -> null, new ScenarioResult(emptyFMV, null));
batchCommand = builder.generateCommands(null);
assertTrue(verifyCommand(batchCommand, AddCoverageListenerCommand.class));
assertTrue(verifyCommand(batchCommand, FireAllRulesCommand.class));
assertTrue(verifyCommand(batchCommand, AgendaGroupSetFocusCommand.class));
assertTrue(verifyCommand(batchCommand, InsertElementsCommand.class));
assertTrue(verifyCommand(batchCommand, ValidateFactCommand.class));
}
use of org.drools.scenariosimulation.backend.runner.model.ScenarioResult in project drools by kiegroup.
the class RuleScenarioRunnerHelper method getScenarioResultsFromGivenFacts.
protected List<ScenarioResult> getScenarioResultsFromGivenFacts(ScesimModelDescriptor scesimModelDescriptor, List<ScenarioExpect> scenarioOutputsPerFact, InstanceGiven input, ExpressionEvaluatorFactory expressionEvaluatorFactory) {
Object factInstance = input.getValue();
List<ScenarioResult> scenarioResults = new ArrayList<>();
for (ScenarioExpect scenarioExpect : scenarioOutputsPerFact) {
if (scenarioExpect.isNewFact()) {
continue;
}
for (FactMappingValue expectedResult : scenarioExpect.getExpectedResult()) {
ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(expectedResult);
ScenarioResult scenarioResult = fillResult(expectedResult, () -> createExtractorFunction(expressionEvaluator, expectedResult, scesimModelDescriptor).apply(factInstance), expressionEvaluator);
scenarioResults.add(scenarioResult);
}
}
return scenarioResults;
}
use of org.drools.scenariosimulation.backend.runner.model.ScenarioResult in project drools by kiegroup.
the class RuleScenarioRunnerHelper method executeScenario.
@Override
protected Map<String, Object> executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, ScesimModelDescriptor scesimModelDescriptor, Settings settings) {
if (!Type.RULE.equals(settings.getType())) {
throw new ScenarioException("Impossible to run a not-RULE simulation with RULE runner");
}
RuleScenarioExecutableBuilder ruleScenarioExecutableBuilder = createBuilderWrapper(kieContainer, settings);
if (settings.getRuleFlowGroup() != null) {
ruleScenarioExecutableBuilder.setActiveRuleFlowGroup(settings.getRuleFlowGroup());
}
loadInputData(scenarioRunnerData.getBackgrounds(), ruleScenarioExecutableBuilder);
loadInputData(scenarioRunnerData.getGivens(), ruleScenarioExecutableBuilder);
// all new facts should be verified internally to the working memory
scenarioRunnerData.getExpects().stream().filter(ScenarioExpect::isNewFact).flatMap(output -> output.getExpectedResult().stream().map(ScenarioResult::new)).forEach(scenarioResult -> {
Class<?> clazz = ScenarioBeanUtil.loadClass(scenarioResult.getFactIdentifier().getClassName(), kieContainer.getClassLoader());
ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(scenarioResult.getFactMappingValue());
scenarioRunnerData.addResult(scenarioResult);
ruleScenarioExecutableBuilder.addInternalCondition(clazz, createExtractorFunction(expressionEvaluator, scenarioResult.getFactMappingValue(), scesimModelDescriptor), scenarioResult);
});
return ruleScenarioExecutableBuilder.run();
}
Aggregations