Search in sources :

Example 16 with Scenario

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

the class ScenarioSimulationEditorPresenterTest method cleanReadOnlyColumn.

@Test
public void cleanReadOnlyColumn() {
    Simulation simulation = new Simulation();
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    FactMapping test1 = simulationDescriptor.addFactMapping(FactIdentifier.create("test1", String.class.getCanonicalName()), ExpressionIdentifier.create("", FactMappingType.GIVEN));
    FactMapping test2 = simulationDescriptor.addFactMapping(FactIdentifier.create("test2", String.class.getCanonicalName()), ExpressionIdentifier.create("", FactMappingType.GIVEN));
    test1.addExpressionElement("test", String.class.getCanonicalName());
    Scenario scenario = simulation.addData();
    scenario.addMappingValue(test1.getFactIdentifier(), test1.getExpressionIdentifier(), LOWER_CASE_VALUE);
    scenario.addMappingValue(test2.getFactIdentifier(), test2.getExpressionIdentifier(), LOWER_CASE_VALUE);
    presenterSpy.cleanReadOnlyColumn(simulation);
    assertNotNull(scenario.getFactMappingValue(test1.getFactIdentifier(), test1.getExpressionIdentifier()).get().getRawValue());
    assertNull(scenario.getFactMappingValue(test2.getFactIdentifier(), test2.getExpressionIdentifier()).get().getRawValue());
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) Matchers.anyString(org.mockito.Matchers.anyString) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test)

Example 17 with Scenario

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

the class ScenarioCsvImportExportTest method createDummySimulation.

private Simulation createDummySimulation(int numberOfColumn, int numberOfRow) {
    Simulation simulation = new Simulation();
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.INDEX, ExpressionIdentifier.INDEX).setExpressionAlias("Index");
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION).setExpressionAlias("Description");
    for (int col = 0; col < numberOfColumn; col += 1) {
        createFactMapping(simulationDescriptor, col);
    }
    for (int row = 0; row < numberOfRow; row += 1) {
        Scenario scenario = simulation.addData();
        scenario.addMappingValue(FactIdentifier.INDEX, ExpressionIdentifier.INDEX, row);
        scenario.setDescription("My scenario " + row);
        for (int col = 2; col < numberOfColumn + 2; col += 1) {
            FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(col);
            scenario.addMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier(), "value_" + row + "_" + (col - 2));
        }
    }
    return simulation;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Example 18 with Scenario

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

the class TestUtils method getSimulation.

public static Simulation getSimulation(int numberOfColumns, int numberOfRows) {
    Simulation simulation = new Simulation();
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    // generate simulationDescriptor
    IntStream.range(0, numberOfColumns).forEach(columnIndex -> {
        simulationDescriptor.addFactMapping(FactIdentifier.create(getFactName(columnIndex), String.class.getCanonicalName()), ExpressionIdentifier.create(getColName(columnIndex), FactMappingType.EXPECT));
    });
    // generate scenarios
    IntStream.range(0, numberOfRows).forEach(rowIndex -> {
        final Scenario scenario = simulation.addData();
        scenario.setDescription(getRowName(rowIndex));
        IntStream.range(0, numberOfColumns).forEach(columnIndex -> {
            scenario.addMappingValue(FactIdentifier.create(getFactName(columnIndex), String.class.getCanonicalName()), ExpressionIdentifier.create(getColName(columnIndex), FactMappingType.EXPECT), getCellValue(columnIndex, rowIndex));
        });
    });
    return simulation;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Simulation(org.drools.scenariosimulation.api.model.Simulation) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Example 19 with Scenario

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

the class CoverageScenarioListPresenterTest method commonAddScesimDataGroup.

private void commonAddScesimDataGroup(ScenarioSimulationModel.Type type, int scenarioIndex, String scenarioDescription, String expectedLabel) {
    Scenario scenario = new Scenario();
    scenario.setDescription(scenarioDescription);
    ScenarioWithIndex scenarioWithIndex = new ScenarioWithIndex(scenarioIndex, scenario);
    Map<String, Integer> resultCounter = new HashMap<>();
    coverageScenarioListPresenterSpy.addScesimDataGroup(scenarioWithIndex, resultCounter, type);
    verify(viewsProviderMock, times(1)).getCoverageScenarioListView();
    verify(coverageScenarioListViewMock, times(1)).setPresenter(eq(coverageScenarioListPresenterSpy));
    verify(coverageScenarioListViewMock, times(1)).setVisible(eq(false));
    verify(coverageScenarioListViewMock, times(1)).getScenarioElement();
    verify(coverageScenarioListViewMock, times(1)).setItemLabel(eq(expectedLabel));
    verify(scenarioElementMock, times(1)).appendChild(isA(HTMLUListElement.class));
}
Also used : HashMap(java.util.HashMap) HTMLUListElement(elemental2.dom.HTMLUListElement) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Aggregations

Scenario (org.drools.scenariosimulation.api.model.Scenario)19 Test (org.junit.Test)10 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)9 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)6 Simulation (org.drools.scenariosimulation.api.model.Simulation)6 ArrayList (java.util.ArrayList)4 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)4 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)3 SimulationRunMetadata (org.drools.scenariosimulation.api.model.SimulationRunMetadata)3 SimulationRunResult (org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult)3 Matchers.anyString (org.mockito.Matchers.anyString)3 HashMap (java.util.HashMap)2 List (java.util.List)2 AuditLogLine (org.drools.scenariosimulation.api.model.AuditLogLine)2 Background (org.drools.scenariosimulation.api.model.Background)2 Settings (org.drools.scenariosimulation.api.model.Settings)2 TestUtils.commonCheckAuditLogLine (org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine)2 AbstractRuleCoverageTest (org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest)2 ScenarioResultMetadata (org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata)2 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)2