use of org.drools.scenariosimulation.api.model.ScenarioWithIndex in project drools-wb by kiegroup.
the class ScenarioSimulationEditorPresenter method refreshModelContent.
protected void refreshModelContent(SimulationRunResult newData) {
view.hideBusyIndicator();
if (this.model == null) {
return;
}
// refresh simulation data
Simulation simulation = this.model.getSimulation();
for (ScenarioWithIndex scenarioWithIndex : newData.getScenarioWithIndex()) {
int index = scenarioWithIndex.getIndex() - 1;
simulation.replaceData(index, scenarioWithIndex.getScesimData());
}
scenarioMainGridWidget.refreshContent(simulation);
context.getStatus().setSimulation(simulation);
// refresh background data
boolean hasBackgroundError = false;
Background background = this.model.getBackground();
for (BackgroundDataWithIndex backgroundDataWithIndex : newData.getBackgroundDataWithIndex()) {
int index = backgroundDataWithIndex.getIndex() - 1;
BackgroundData scesimData = backgroundDataWithIndex.getScesimData();
background.replaceData(index, scesimData);
hasBackgroundError |= scesimData.getUnmodifiableFactMappingValues().stream().anyMatch(elem -> !FactMappingValueStatus.SUCCESS.equals(elem.getStatus()));
}
scenarioBackgroundGridWidget.refreshContent(background);
context.getStatus().setBackground(background);
if (hasBackgroundError) {
sendNotification(ScenarioSimulationEditorConstants.INSTANCE.backgroundErrorNotification(), NotificationEvent.NotificationType.ERROR);
selectBackgroundTab();
}
dataManagementStrategy.setModel(model);
abstractScenarioSimulationDocksHandler.expandTestResultsDock();
scenarioSimulationEditorWrapper.onRefreshedModelContent(newData);
}
use of org.drools.scenariosimulation.api.model.ScenarioWithIndex in project drools-wb by kiegroup.
the class ScenarioSimulationEditorPresenterTest method onRunScenario.
@Test
public void onRunScenario() {
scenarioWithIndexLocal.add(new ScenarioWithIndex(1, new Scenario()));
scenarioWithIndexLocal.add(new ScenarioWithIndex(2, new Scenario()));
scenarioWithIndexLocal.add(new ScenarioWithIndex(3, new Scenario()));
when(simulationMock.getDataByIndex(anyInt())).thenReturn(mock(Scenario.class));
List<Integer> indexList = Arrays.asList(0, 2);
presenterSpy.onRunScenario(indexList);
verify(scenarioGridWidgetSpy, times(1)).resetErrors();
verify(backgroundGridWidgetSpy, times(1)).resetErrors();
verify(scenarioSimulationModelMock, times(1)).setSimulation(simulationMock);
verify(scenarioSimulationModelMock, times(1)).setBackground(backgroundMock);
verify(scenarioSimulationViewMock, times(1)).showBusyIndicator(anyString());
verify(scenarioSimulationEditorWrapperMock, times(1)).onRunScenario(any(), any(), any(), eq(settingsLocal), scenarioWithIndexCaptor.capture(), any());
List<ScenarioWithIndex> capturedValue = scenarioWithIndexCaptor.getValue();
assertEquals(2, capturedValue.size());
for (Integer requestedIndex : indexList) {
assertEquals(1, capturedValue.stream().filter(elem -> elem.getIndex() == (requestedIndex + 1)).count());
}
}
use of org.drools.scenariosimulation.api.model.ScenarioWithIndex in project drools-wb by kiegroup.
the class ScenarioSimulationEditorPresenterTest method refreshModelContent.
@Test
public void refreshModelContent() {
when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationMock);
List<ScenarioWithIndex> scenarioWithIndex = new ArrayList<>();
int scenarioNumber = 1;
int scenarioIndex = scenarioNumber - 1;
Scenario scenario = mock(Scenario.class);
scenarioWithIndex.add(new ScenarioWithIndex(scenarioNumber, scenario));
List<BackgroundDataWithIndex> backgroundDataWithIndex = new ArrayList<>();
BackgroundData backgroundData = mock(BackgroundData.class);
backgroundDataWithIndex.add(new BackgroundDataWithIndex(scenarioNumber, backgroundData));
TestResultMessage testResultMessage = mock(TestResultMessage.class);
SimulationRunResult testRunResult = new SimulationRunResult(scenarioWithIndex, backgroundDataWithIndex, new SimulationRunMetadata(), testResultMessage);
presenterSpy.refreshModelContent(testRunResult);
verify(scenarioSimulationViewMock, times(1)).hideBusyIndicator();
verify(simulationMock, times(1)).replaceData(eq(scenarioIndex), eq(scenario));
assertEquals(scenarioSimulationModelMock, presenterSpy.getModel());
verify(scenarioGridWidgetSpy, times(1)).refreshContent(eq(simulationMock));
assertEquals(scenarioSimulationContextLocal.getStatus().getSimulation(), simulationMock);
verify(backgroundMock, times(1)).replaceData(eq(scenarioIndex), eq(backgroundData));
verify(backgroundGridWidgetSpy, times(1)).refreshContent(eq(backgroundMock));
assertEquals(scenarioSimulationContextLocal.getStatus().getBackground(), backgroundMock);
assertEquals(scenarioSimulationModelMock, presenterSpy.getModel());
verify(abstractScenarioSimulationDocksHandlerMock, times(1)).expandTestResultsDock();
verify(dataManagementStrategyMock, times(1)).setModel(eq(scenarioSimulationModelMock));
verify(scenarioSimulationEditorWrapperMock, times(1)).onRefreshedModelContent(eq(testRunResult));
}
use of org.drools.scenariosimulation.api.model.ScenarioWithIndex in project drools by kiegroup.
the class SimulationRunMetadataBuilder method build.
public SimulationRunMetadata build() {
int available = 0;
Map<String, Integer> outputCounter = new HashMap<>();
Map<ScenarioWithIndex, Map<String, Integer>> scenarioCounter = new HashMap<>();
AuditLog auditLog = new AuditLog();
for (ScenarioResultMetadata scenarioResultMetadatum : scenarioResultMetadata) {
// this value is the same for all the scenarios
available = scenarioResultMetadatum.getAvailable().size();
scenarioResultMetadatum.getExecutedWithCounter().forEach((name, counter) -> outputCounter.compute(name, (key, number) -> number == null ? counter : number + counter));
}
for (ScenarioResultMetadata scenarioResultMetadatum : scenarioResultMetadata) {
scenarioCounter.put(scenarioResultMetadatum.getScenarioWithIndex(), scenarioResultMetadatum.getExecutedWithCounter());
auditLog.addAuditLogLines(scenarioResultMetadatum.getAuditLogLines());
}
return new SimulationRunMetadata(available, outputCounter.keySet().size(), outputCounter, scenarioCounter, auditLog);
}
use of org.drools.scenariosimulation.api.model.ScenarioWithIndex in project drools by kiegroup.
the class DMNScenarioRunnerHelperTest method commonExtractResultMetadata.
public void commonExtractResultMetadata(List<DMNMessage> messages) {
Set<DecisionNode> decisions = new HashSet<>();
IntStream.range(0, 5).forEach(index -> decisions.add(createDecisionMock("decision" + index)));
when(dmnModelMock.getDecisions()).thenReturn(decisions);
List<DMNDecisionResult> decisionResults = new ArrayList<>();
decisionResults.add(createDecisionResultMock("decision2", true, messages));
decisionResults.add(createDecisionResultMock("decision3", false, messages));
when(dmnResultMock.getDecisionResults()).thenReturn(decisionResults);
ScenarioWithIndex scenarioWithIndex = new ScenarioWithIndex(1, scenario1);
ScenarioResultMetadata scenarioResultMetadata = runnerHelper.extractResultMetadata(requestContextMock, scenarioWithIndex);
assertEquals(scenarioWithIndex, scenarioResultMetadata.getScenarioWithIndex());
assertEquals(5, scenarioResultMetadata.getAvailable().size());
assertTrue(scenarioResultMetadata.getAvailable().contains("decision1"));
assertEquals(1, scenarioResultMetadata.getExecuted().size());
assertTrue(scenarioResultMetadata.getExecuted().contains("decision2"));
assertFalse(scenarioResultMetadata.getExecuted().contains("decision3"));
final List<AuditLogLine> auditLogLines = scenarioResultMetadata.getAuditLogLines();
assertNotNull(auditLogLines);
if (messages == null) {
assertEquals(decisionResults.size(), auditLogLines.size());
for (int i = 0; i < decisionResults.size(); i++) {
commonCheckAuditLogLine(auditLogLines.get(i), decisionResults.get(i).getDecisionName(), decisionResults.get(i).getEvaluationStatus().name(), null);
}
} else {
List<String> expectedDecisions = Arrays.asList("decision2", "decision3");
List<String> expectedResults = Arrays.asList(DecisionEvaluationStatus.SUCCEEDED.toString(), DecisionEvaluationStatus.FAILED.toString());
int expectedLines = messages.size() * expectedDecisions.size();
assertEquals(expectedLines, auditLogLines.size());
for (int i = 0; i < auditLogLines.size(); i++) {
int messagesIndex = i < messages.size() ? i : i - messages.size();
String decisionName = i < messages.size() ? expectedDecisions.get(0) : expectedDecisions.get(1);
String expectedResultName = i < messages.size() ? expectedResults.get(0) : expectedResults.get(1);
commonCheckAuditLogLine(auditLogLines.get(i), decisionName, expectedResultName, messages.get(messagesIndex).getLevel().name() + ": " + messages.get(messagesIndex).getText());
}
}
}
Aggregations