use of org.drools.scenariosimulation.api.model.FactMappingValue 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.api.model.FactMappingValue 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.api.model.FactMappingValue in project drools by kiegroup.
the class RuleScenarioRunnerHelperTest method createExtractorFunctionTest.
@Test
public void createExtractorFunctionTest() {
String personName = "Test";
FactMappingValue factMappingValue = new FactMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, personName);
Function<Object, ValueWrapper> extractorFunction = runnerHelper.createExtractorFunction(expressionEvaluator, factMappingValue, simulation.getScesimModelDescriptor());
Person person = new Person();
person.setFirstName(personName);
assertTrue(extractorFunction.apply(person).isValid());
person.setFirstName("OtherString");
assertFalse(extractorFunction.apply(person).isValid());
Function<Object, ValueWrapper> extractorFunction1 = runnerHelper.createExtractorFunction(expressionEvaluator, new FactMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, null), simulation.getScesimModelDescriptor());
ValueWrapper nullValue = extractorFunction1.apply(new Person());
assertTrue(nullValue.isValid());
assertNull(nullValue.getValue());
}
use of org.drools.scenariosimulation.api.model.FactMappingValue in project drools by kiegroup.
the class RuleScenarioRunnerHelperTest method getParamsForBeanTest.
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void getParamsForBeanTest() {
List<FactMappingValue> factMappingValues = new ArrayList<>();
FactMappingValue factMappingValue1 = spy(new FactMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, "NOT PARSABLE"));
FactMappingValue factMappingValue2 = spy(new FactMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, "NOT PARSABLE"));
FactMappingValue factMappingValue3 = spy(new FactMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, "1"));
factMappingValues.add(factMappingValue1);
factMappingValues.add(factMappingValue2);
factMappingValues.add(factMappingValue3);
assertThatThrownBy(() -> runnerHelper.getParamsForBean(simulation.getScesimModelDescriptor(), disputeFactIdentifier, factMappingValues, expressionEvaluatorFactory)).isInstanceOf(ScenarioException.class).hasMessage("Error in one or more input values");
factMappingValues.forEach(fmv -> verify(fmv, times(2)).getRawValue());
assertEquals(FactMappingValueStatus.FAILED_WITH_EXCEPTION, factMappingValue1.getStatus());
assertEquals(FactMappingValueStatus.FAILED_WITH_EXCEPTION, factMappingValue2.getStatus());
assertEquals(FactMappingValueStatus.SUCCESS, factMappingValue3.getStatus());
}
use of org.drools.scenariosimulation.api.model.FactMappingValue 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;
}
Aggregations