Search in sources :

Example 6 with Simulation

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

the class ScenarioGridTest method getSimulation.

private Simulation getSimulation() {
    Simulation toReturn = new Simulation();
    ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX);
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    Scenario scenario = toReturn.addData();
    int row = toReturn.getUnmodifiableData().indexOf(scenario);
    scenario.setDescription(null);
    // Add GIVEN Facts
    IntStream.range(2, 4).forEach(id -> {
        ExpressionIdentifier givenExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.GIVEN);
        simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, givenExpression);
        scenario.addMappingValue(FactIdentifier.EMPTY, givenExpression, null);
    });
    // Add EXPECT Facts
    IntStream.range(2, 4).forEach(id -> {
        // This is to have consistent labels/names even when adding columns at runtime
        id += 2;
        ExpressionIdentifier expectedExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.EXPECT);
        simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, expectedExpression);
        scenario.addMappingValue(FactIdentifier.EMPTY, expectedExpression, null);
    });
    return toReturn;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Simulation(org.drools.scenariosimulation.api.model.Simulation) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Example 7 with Simulation

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

the class RULESimulationSettingsCreationStrategy method createSimulation.

@Override
public Simulation createSimulation(Path context, String value) {
    Simulation toReturn = new Simulation();
    ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX);
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    ScenarioWithIndex scenarioWithIndex = createScesimDataWithIndex(toReturn, simulationDescriptor, ScenarioWithIndex::new);
    // Add GIVEN Fact
    createEmptyColumn(simulationDescriptor, scenarioWithIndex, 1, GIVEN, simulationDescriptor.getFactMappings().size());
    // Add EXPECT Fact
    createEmptyColumn(simulationDescriptor, scenarioWithIndex, 2, EXPECT, simulationDescriptor.getFactMappings().size());
    return toReturn;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Simulation(org.drools.scenariosimulation.api.model.Simulation) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex)

Example 8 with Simulation

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

the class ScenarioRunnerServiceImplTest method setup.

@Before
public void setup() {
    simulationLocal = new Simulation();
    backgroundLocal = new Background();
    settingsLocal = new Settings();
    settingsLocal.setType(Type.RULE);
    when(buildInfoServiceMock.getBuildInfo(any())).thenReturn(buildInfoMock);
    when(buildInfoMock.getKieContainer()).thenReturn(kieContainerMock);
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Settings(org.drools.scenariosimulation.api.model.Settings) Before(org.junit.Before)

Example 9 with Simulation

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

the class ScenarioSimulationServiceImplTest method setup.

@Before
public void setup() {
    Set<Package> testPackages = new HashSet<>();
    Package testPackage = new Package(path, path, path, path, path, "Test", "", "");
    testPackages.add(testPackage);
    when(kieModuleServiceMock.resolveModule(any())).thenReturn(kieModuleMock);
    when(kieModuleServiceMock.resolvePackages(Mockito.<KieModule>any())).thenReturn(testPackages);
    when(kieModuleServiceMock.newPackage(any(), any())).thenReturn(testPackage);
    when(kieModuleServiceMock.resolveDefaultPackage(any())).thenReturn(testPackage);
    when(kieModuleServiceMock.resolveModule(any())).thenReturn(kieModuleMock);
    when(kieModuleMock.getPom()).thenReturn(projectPomMock);
    when(projectPomMock.getGav()).thenReturn(gavMock);
    when(gavMock.getGroupId()).thenReturn("Test");
    when(projectPomMock.getDependencies()).thenReturn(dependenciesMock);
    when(dependenciesMock.iterator()).thenReturn(new Dependencies().iterator());
    when(ioServiceMock.exists(any())).thenReturn(false);
    when(packageMock.getPackageTestSrcPath()).thenReturn(path);
    when(scenarioSimulationBuilderMock.createSimulation(any(), any(), any())).thenReturn(new Simulation());
    when(scenarioSimulationBuilderMock.createBackground(any(), any(), any())).thenReturn(new Background());
    when(scenarioSimulationBuilderMock.createSettings(any(), any(), any())).thenReturn(new Settings());
    service.scenarioSimulationBuilder = scenarioSimulationBuilderMock;
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Package(org.guvnor.common.services.project.model.Package) Dependencies(org.guvnor.common.services.project.model.Dependencies) Settings(org.drools.scenariosimulation.api.model.Settings) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 10 with Simulation

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

the class ScenarioCsvImportExportTest method importData.

@Test
public void importData() throws IOException {
    Simulation originalSimulation = createDummySimulation(3, 1);
    assertEquals(1, originalSimulation.getUnmodifiableData().size());
    String rawCSV = "OTHER,OTHER,GIVEN,GIVEN,GIVEN\r\n" + "#,Scenario description,instance1,instance2,instance3\r\n" + "Index,Description,property1,property2,property3\r\n" + "1,My Scenario,value1,value2,";
    AbstractScesimModel retrieved = scenarioCsvImportExport.importData(rawCSV, originalSimulation);
    assertEquals(1, retrieved.getUnmodifiableData().size());
    assertEquals("value1", retrieved.getDataByIndex(0).getFactMappingValue(retrieved.getScesimModelDescriptor().getFactMappingByIndex(2)).get().getRawValue());
    assertEquals("value2", retrieved.getDataByIndex(0).getFactMappingValue(retrieved.getScesimModelDescriptor().getFactMappingByIndex(3)).get().getRawValue());
    assertNull(retrieved.getDataByIndex(0).getFactMappingValue(retrieved.getScesimModelDescriptor().getFactMappingByIndex(4)).get().getRawValue());
    assertThatThrownBy(() -> scenarioCsvImportExport.importData("", originalSimulation)).isInstanceOf(IllegalArgumentException.class).hasMessage("Malformed file, missing header");
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) Test(org.junit.Test)

Aggregations

Simulation (org.drools.scenariosimulation.api.model.Simulation)30 Settings (org.drools.scenariosimulation.api.model.Settings)13 Test (org.junit.Test)13 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)12 Background (org.drools.scenariosimulation.api.model.Background)11 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)11 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)9 Path (org.uberfire.backend.vfs.Path)9 List (java.util.List)8 Before (org.junit.Before)7 Scenario (org.drools.scenariosimulation.api.model.Scenario)6 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)6 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)4 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)4 Inject (javax.inject.Inject)3 FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)3 Matchers.anyString (org.mockito.Matchers.anyString)3