use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools by kiegroup.
the class RuleScenarioRunnerHelper method verifyConditions.
@Override
protected void verifyConditions(ScesimModelDescriptor scesimModelDescriptor, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, Map<String, Object> requestContext) {
for (InstanceGiven input : scenarioRunnerData.getGivens()) {
FactIdentifier factIdentifier = input.getFactIdentifier();
List<ScenarioExpect> assertionOnFact = scenarioRunnerData.getExpects().stream().filter(elem -> !elem.isNewFact()).filter(elem -> Objects.equals(elem.getFactIdentifier(), factIdentifier)).collect(toList());
// check if this fact has something to check
if (assertionOnFact.isEmpty()) {
continue;
}
getScenarioResultsFromGivenFacts(scesimModelDescriptor, assertionOnFact, input, expressionEvaluatorFactory).forEach(scenarioRunnerData::addResult);
}
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor 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.ScesimModelDescriptor in project drools-wb by kiegroup.
the class SimulationSettingsCreationStrategy method createBackground.
default Background createBackground(Path context, String dmnFilePath) {
Background toReturn = new Background();
ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
int index = toReturn.getUnmodifiableData().size() + 1;
BackgroundData backgroundData = toReturn.addData();
BackgroundDataWithIndex backgroundDataWithIndex = new BackgroundDataWithIndex(index, backgroundData);
// Add GIVEN Fact
createEmptyColumn(simulationDescriptor, backgroundDataWithIndex, 1, GIVEN, simulationDescriptor.getFactMappings().size());
return toReturn;
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class SimulationSettingsCreationStrategyTest method createEmptyColumn.
@Test
public void createEmptyColumn() {
ArgumentCaptor<ExpressionIdentifier> expressionIdentifierCaptor1 = ArgumentCaptor.forClass(ExpressionIdentifier.class);
ArgumentCaptor<ExpressionIdentifier> expressionIdentifierCaptor2 = ArgumentCaptor.forClass(ExpressionIdentifier.class);
int placeholderId = 1;
int columnIndex = 0;
SimulationSettingsCreationStrategy simulationSettingsCreationStrategy = new SimulationSettingsCreationStrategy() {
@Override
public Simulation createSimulation(Path context, String value) {
return null;
}
@Override
public Background createBackground(Path context, String dmnFilePath) {
return null;
}
@Override
public Settings createSettings(Path context, String value) {
return null;
}
};
ScesimModelDescriptor simulationDescriptorSpy = spy(new ScesimModelDescriptor());
Scenario scenarioSpy = spy(new Scenario());
ScenarioWithIndex scenarioWithIndex = new ScenarioWithIndex(1, scenarioSpy);
simulationSettingsCreationStrategy.createEmptyColumn(simulationDescriptorSpy, scenarioWithIndex, placeholderId, GIVEN, columnIndex);
verify(simulationDescriptorSpy, times(1)).addFactMapping(eq(columnIndex), eq(FactMapping.getInstancePlaceHolder(placeholderId)), eq(FactIdentifier.EMPTY), expressionIdentifierCaptor1.capture());
assertEquals(GIVEN, expressionIdentifierCaptor1.getValue().getType());
verify(scenarioSpy, times(1)).addMappingValue(eq(FactIdentifier.EMPTY), expressionIdentifierCaptor2.capture(), isNull());
assertEquals(GIVEN, expressionIdentifierCaptor2.getValue().getType());
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class ScenarioRunnerServiceImplTest method runTestWithScenarios.
@Test
public void runTestWithScenarios() {
when(buildInfoServiceMock.getBuildInfo(any())).thenReturn(buildInfoMock);
when(buildInfoMock.getKieContainer()).thenReturn(kieContainerMock);
ScesimModelDescriptor simulationDescriptor = new ScesimModelDescriptor();
List<ScenarioWithIndex> scenarios = new ArrayList<>();
SimulationRunResult test = scenarioRunnerService.runTest("test", mock(Path.class), simulationDescriptor, scenarios, settingsLocal, backgroundLocal);
assertNotNull(test.getTestResultMessage());
assertNotNull(test.getScenarioWithIndex());
assertNotNull(test.getSimulationRunMetadata());
}
Aggregations