Search in sources :

Example 16 with FactMappingValue

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"));
}
Also used : ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Test(org.junit.Test) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) Assert(org.junit.Assert) Function(java.util.function.Function) Collections.singletonList(java.util.Collections.singletonList) ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) Test(org.junit.Test)

Example 17 with FactMappingValue

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));
}
Also used : InsertElementsCommand(org.drools.core.command.runtime.rule.InsertElementsCommand) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) ExecutionResults(org.kie.api.runtime.ExecutionResults) FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) AgendaGroupSetFocusCommand(org.drools.core.command.runtime.rule.AgendaGroupSetFocusCommand) Test(org.junit.Test)

Example 18 with FactMappingValue

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());
}
Also used : ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) Person(org.drools.scenariosimulation.backend.model.Person) AbstractRuleCoverageTest(org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest) Test(org.junit.Test)

Example 19 with FactMappingValue

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());
}
Also used : FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ArrayList(java.util.ArrayList) AbstractRuleCoverageTest(org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest) Test(org.junit.Test)

Example 20 with FactMappingValue

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;
}
Also used : ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ArrayList(java.util.ArrayList) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator)

Aggregations

FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)24 Test (org.junit.Test)15 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)9 ArrayList (java.util.ArrayList)7 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)7 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)7 ExpressionEvaluator (org.drools.scenariosimulation.backend.expression.ExpressionEvaluator)7 ScenarioResult (org.drools.scenariosimulation.backend.runner.model.ScenarioResult)7 ScenarioExpect (org.drools.scenariosimulation.backend.runner.model.ScenarioExpect)6 ValueWrapper (org.drools.scenariosimulation.backend.runner.model.ValueWrapper)6 AbstractRuleCoverageTest (org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest)5 InstanceGiven (org.drools.scenariosimulation.backend.runner.model.InstanceGiven)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Background (org.drools.scenariosimulation.api.model.Background)4 ScenarioRunnerData (org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData)4 Collectors.toList (java.util.stream.Collectors.toList)3 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)3 ExpressionEvaluatorResult (org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorResult)3