Search in sources :

Example 16 with Settings

use of org.drools.scenariosimulation.api.model.Settings in project drools by kiegroup.

the class RuleScenarioRunnerHelperTest method setup.

@Before
public void setup() {
    when(kieContainerMock.getClassLoader()).thenReturn(classLoader);
    simulation = new Simulation();
    background = new Background();
    settings = new Settings();
    settings.setType(ScenarioSimulationModel.Type.RULE);
    personFactIdentifier = FactIdentifier.create("Fact 1", Person.class.getCanonicalName());
    firstNameGivenExpressionIdentifier = ExpressionIdentifier.create("First Name Given", FactMappingType.GIVEN);
    firstNameGivenFactMapping = simulation.getScesimModelDescriptor().addFactMapping(personFactIdentifier, firstNameGivenExpressionIdentifier);
    firstNameGivenFactMapping.addExpressionElement("Fact 1", String.class.getCanonicalName());
    firstNameGivenFactMapping.addExpressionElement("firstName", String.class.getCanonicalName());
    disputeFactIdentifier = FactIdentifier.create("Fact 2", Dispute.class.getCanonicalName());
    amountGivenExpressionIdentifier = ExpressionIdentifier.create("Amount Given", FactMappingType.GIVEN);
    amountNameGivenFactMapping = simulation.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, amountGivenExpressionIdentifier);
    amountNameGivenFactMapping.addExpressionElement("Fact 2", Double.class.getCanonicalName());
    amountNameGivenFactMapping.addExpressionElement("amount", Double.class.getCanonicalName());
    firstNameExpectedExpressionIdentifier = ExpressionIdentifier.create("First Name Expected", FactMappingType.EXPECT);
    firstNameExpectedFactMapping = simulation.getScesimModelDescriptor().addFactMapping(personFactIdentifier, firstNameExpectedExpressionIdentifier);
    firstNameExpectedFactMapping.addExpressionElement("Fact 1", String.class.getCanonicalName());
    firstNameExpectedFactMapping.addExpressionElement("firstName", String.class.getCanonicalName());
    amountExpectedExpressionIdentifier = ExpressionIdentifier.create("Amount Expected", FactMappingType.EXPECT);
    amountNameExpectedFactMapping = simulation.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, amountExpectedExpressionIdentifier);
    amountNameExpectedFactMapping.addExpressionElement("Fact 2", Double.class.getCanonicalName());
    amountNameExpectedFactMapping.addExpressionElement("amount", Double.class.getCanonicalName());
    expressionGivenExpressionIdentifier = ExpressionIdentifier.create("directMapping", FactMappingType.GIVEN);
    disputeExpressionGivenFactMapping = simulation.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, expressionGivenExpressionIdentifier);
    disputeExpressionGivenFactMapping.setFactMappingValueType(FactMappingValueType.EXPRESSION);
    disputeExpressionGivenFactMapping.addExpressionElement("Dispute", Dispute.class.getCanonicalName());
    scenario1 = simulation.addData();
    scenario1.setDescription(TEST_DESCRIPTION);
    scenario1.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, NAME);
    scenario1.addMappingValue(personFactIdentifier, firstNameExpectedExpressionIdentifier, NAME);
    scenario2 = simulation.addData();
    scenario2.setDescription(TEST_DESCRIPTION);
    scenario2.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, NAME);
    scenario2.addMappingValue(personFactIdentifier, firstNameExpectedExpressionIdentifier, NAME);
    scenario2.addMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, AMOUNT);
    amountNameExpectedFactMappingValue = scenario2.addMappingValue(disputeFactIdentifier, amountExpectedExpressionIdentifier, AMOUNT);
    backgroundFirstNameGivenFactMapping = background.getScesimModelDescriptor().addFactMapping(personFactIdentifier, firstNameGivenExpressionIdentifier);
    backgroundFirstNameGivenFactMapping.addExpressionElement("Person", String.class.getCanonicalName());
    backgroundFirstNameGivenFactMapping.addExpressionElement("firstName", String.class.getCanonicalName());
    backgroundAmountNameGivenFactMapping = background.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, amountGivenExpressionIdentifier);
    backgroundAmountNameGivenFactMapping.addExpressionElement("Dispute", Double.class.getCanonicalName());
    backgroundAmountNameGivenFactMapping.addExpressionElement("amount", Double.class.getCanonicalName());
    backgroundData1 = background.addData();
    backgroundData1.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, NAME);
    backgroundData1.addMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, AMOUNT);
    backgroundData2 = background.addData();
    backgroundData2.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, NAME);
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Dispute(org.drools.scenariosimulation.backend.model.Dispute) Settings(org.drools.scenariosimulation.api.model.Settings) Before(org.junit.Before)

Example 17 with Settings

use of org.drools.scenariosimulation.api.model.Settings in project drools by kiegroup.

the class DMNScenarioRunnerHelperTest method init.

@Before
public void init() {
    when(dmnScenarioExecutableBuilderMock.run()).thenReturn(mock(RequestContext.class));
    simulation = new Simulation();
    settings = new Settings();
    settings.setType(ScenarioSimulationModel.Type.DMN);
    settings.setDmnFilePath(DMN_FILE_PATH);
    personFactIdentifier = FactIdentifier.create("Fact 1", "Fact 1");
    firstNameGivenExpressionIdentifier = ExpressionIdentifier.create("First Name Given", FactMappingType.GIVEN);
    firstNameGivenFactMapping = simulation.getScesimModelDescriptor().addFactMapping(personFactIdentifier, firstNameGivenExpressionIdentifier);
    firstNameGivenFactMapping.addExpressionElement("Fact 1", String.class.getCanonicalName());
    firstNameGivenFactMapping.addExpressionElement("firstName", String.class.getCanonicalName());
    disputeFactIdentifier = FactIdentifier.create("Fact 2", "Fact 2");
    amountGivenExpressionIdentifier = ExpressionIdentifier.create("Amount Given", FactMappingType.GIVEN);
    amountNameGivenFactMapping = simulation.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, amountGivenExpressionIdentifier);
    amountNameGivenFactMapping.addExpressionElement("Fact 2", BigDecimal.class.getCanonicalName());
    amountNameGivenFactMapping.addExpressionElement("amount", BigDecimal.class.getCanonicalName());
    firstNameExpectedExpressionIdentifier = ExpressionIdentifier.create("First Name Expected", FactMappingType.EXPECT);
    firstNameExpectedFactMapping = simulation.getScesimModelDescriptor().addFactMapping(personFactIdentifier, firstNameExpectedExpressionIdentifier);
    firstNameExpectedFactMapping.addExpressionElement("Fact 1", String.class.getCanonicalName());
    firstNameExpectedFactMapping.addExpressionElement("firstName", String.class.getCanonicalName());
    amountExpectedExpressionIdentifier = ExpressionIdentifier.create("Amount Expected", FactMappingType.EXPECT);
    amountNameExpectedFactMapping = simulation.getScesimModelDescriptor().addFactMapping(disputeFactIdentifier, amountExpectedExpressionIdentifier);
    amountNameExpectedFactMapping.addExpressionElement("Fact 2", Double.class.getCanonicalName());
    amountNameExpectedFactMapping.addExpressionElement("amount", Double.class.getCanonicalName());
    scenario1 = simulation.addData();
    scenario1.setDescription(TEST_DESCRIPTION);
    scenario1.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, FEEL_EXPRESSION_NAME);
    firstNameExpectedValue = scenario1.addMappingValue(personFactIdentifier, firstNameExpectedExpressionIdentifier, FEEL_EXPRESSION_NAME);
    scenario2 = simulation.addData();
    scenario2.setDescription(TEST_DESCRIPTION);
    scenario2.addMappingValue(personFactIdentifier, firstNameGivenExpressionIdentifier, FEEL_EXPRESSION_NAME);
    scenario2.addMappingValue(personFactIdentifier, firstNameExpectedExpressionIdentifier, FEEL_EXPRESSION_NAME);
    scenario2.addMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, AMOUNT);
    amountNameExpectedFactMappingValue = scenario2.addMappingValue(disputeFactIdentifier, amountExpectedExpressionIdentifier, AMOUNT);
    when(requestContextMock.get(DMNScenarioExecutableBuilder.DMN_RESULT)).thenReturn(dmnResultMock);
    when(requestContextMock.get(DMNScenarioExecutableBuilder.DMN_MODEL)).thenReturn(dmnModelMock);
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) RequestContext(org.kie.api.runtime.RequestContext) Mockito.anyString(org.mockito.Mockito.anyString) Settings(org.drools.scenariosimulation.api.model.Settings) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Example 18 with Settings

use of org.drools.scenariosimulation.api.model.Settings 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();
}
Also used : ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) RuleScenarioExecutableBuilder(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioBeanUtil.fillBean(org.drools.scenariosimulation.backend.util.ScenarioBeanUtil.fillBean) Map(java.util.Map) COVERAGE_LISTENER(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder.COVERAGE_LISTENER) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) RuleScenarioExecutableBuilder.createBuilder(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder.createBuilder) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) ScenarioBeanWrapper(org.drools.scenariosimulation.backend.util.ScenarioBeanWrapper) CoverageAgendaListener(org.drools.scenariosimulation.backend.fluent.CoverageAgendaListener) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ScenarioBeanUtil(org.drools.scenariosimulation.backend.util.ScenarioBeanUtil) Set(java.util.Set) ConstantsHolder(org.drools.scenariosimulation.api.utils.ConstantsHolder) KieContainer(org.kie.api.runtime.KieContainer) Objects(java.util.Objects) Type(org.drools.scenariosimulation.api.model.ScenarioSimulationModel.Type) ExpressionEvaluatorFactory(org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorFactory) List(java.util.List) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator) Collectors.toList(java.util.stream.Collectors.toList) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) RULES_AVAILABLE(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder.RULES_AVAILABLE) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator) RuleScenarioExecutableBuilder(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder)

Example 19 with Settings

use of org.drools.scenariosimulation.api.model.Settings in project drools-wb by kiegroup.

the class ScenarioRunnerServiceImplTest method makeScenarioSimulationModel.

private ScenarioSimulationModel makeScenarioSimulationModel(boolean toSkip) {
    Simulation simulation = new Simulation();
    Settings settings = new Settings();
    settings.setType(Type.RULE);
    settings.setSkipFromBuild(toSkip);
    ScenarioSimulationModel scenarioSimulationModel = new ScenarioSimulationModel();
    scenarioSimulationModel.setSimulation(simulation);
    scenarioSimulationModel.setSettings(settings);
    scenarioSimulationModel.setBackground(new Background());
    return scenarioSimulationModel;
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Example 20 with Settings

use of org.drools.scenariosimulation.api.model.Settings in project drools-wb by kiegroup.

the class ScenarioSimulationServiceImplTest method runScenario.

@Test
public void runScenario() throws Exception {
    doReturn("test userMock").when(userMock).getIdentifier();
    final Path path = mock(Path.class);
    Simulation simulation = new Simulation();
    Settings settings = new Settings();
    Background background = new Background();
    service.runScenario(path, simulation.getScesimModelDescriptor(), simulation.getScenarioWithIndex(), settings, background);
    verify(scenarioRunnerServiceMock).runTest("test userMock", path, simulation.getScesimModelDescriptor(), simulation.getScenarioWithIndex(), settings, background);
}
Also used : Path(org.uberfire.backend.vfs.Path) Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Settings(org.drools.scenariosimulation.api.model.Settings) Test(org.junit.Test)

Aggregations

Settings (org.drools.scenariosimulation.api.model.Settings)29 Test (org.junit.Test)11 Before (org.junit.Before)10 Simulation (org.drools.scenariosimulation.api.model.Simulation)9 Background (org.drools.scenariosimulation.api.model.Background)7 Path (org.uberfire.backend.vfs.Path)6 AbstractScenarioSimulationTest (org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest)4 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)2 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)2 Scenario (org.drools.scenariosimulation.api.model.Scenario)2 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)2 ScenarioRunnerData (org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData)2 ScenarioSimulationViolation (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationViolation)2 UpdateSettingsDataCommand (org.drools.workbench.screens.scenariosimulation.client.commands.actualcommands.UpdateSettingsDataCommand)2 UpdateSettingsDataEvent (org.drools.workbench.screens.scenariosimulation.client.events.UpdateSettingsDataEvent)2 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)2