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;
}
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;
}
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);
}
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;
}
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");
}
Aggregations