use of org.drools.scenariosimulation.api.model.Scenario 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.Scenario 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.Scenario in project drools by kiegroup.
the class AbstractRunnerHelper method run.
public void run(KieContainer kieContainer, ScesimModelDescriptor scesimModelDescriptor, ScenarioWithIndex scenarioWithIndex, ExpressionEvaluatorFactory expressionEvaluatorFactory, ClassLoader classLoader, ScenarioRunnerData scenarioRunnerData, Settings settings, Background background) {
Scenario scenario = scenarioWithIndex.getScesimData();
extractBackgroundValues(background, classLoader, expressionEvaluatorFactory).forEach(scenarioRunnerData::addBackground);
extractGivenValues(scesimModelDescriptor, scenario.getUnmodifiableFactMappingValues(), classLoader, expressionEvaluatorFactory).forEach(scenarioRunnerData::addGiven);
extractExpectedValues(scenario.getUnmodifiableFactMappingValues()).forEach(scenarioRunnerData::addExpect);
Map<String, Object> requestContext = executeScenario(kieContainer, scenarioRunnerData, expressionEvaluatorFactory, scesimModelDescriptor, settings);
scenarioRunnerData.setMetadata(extractResultMetadata(requestContext, scenarioWithIndex));
verifyConditions(scesimModelDescriptor, scenarioRunnerData, expressionEvaluatorFactory, requestContext);
validateAssertion(scenarioRunnerData.getResults(), scesimModelDescriptor);
}
use of org.drools.scenariosimulation.api.model.Scenario in project drools by kiegroup.
the class RuleScenarioRunnerHelperTest method extractResultMetadata.
@Test
public void extractResultMetadata() {
Map<String, Integer> coverageData = new LinkedHashMap<>();
coverageData.put("rule1", 2);
coverageData.put("rule2", 2);
CoverageAgendaListener coverageAgendaListenerMock = createCoverageAgendaListenerWithData(coverageData);
ScenarioWithIndex scenarioWithIndexMock = mock(ScenarioWithIndex.class);
Scenario scenarioMock = mock(Scenario.class);
when(scenarioMock.getDescription()).thenReturn("DESCRIPTION");
when(scenarioWithIndexMock.getScesimData()).thenReturn(scenarioMock);
Map<String, Object> requestContext = new LinkedHashMap<>();
requestContext.put(COVERAGE_LISTENER, coverageAgendaListenerMock);
requestContext.put(RULES_AVAILABLE, coverageData.keySet());
ScenarioResultMetadata scenarioResultMetadata = runnerHelper.extractResultMetadata(requestContext, scenarioWithIndexMock);
assertEquals(scenarioWithIndexMock, scenarioResultMetadata.getScenarioWithIndex());
assertEquals(2, scenarioResultMetadata.getAvailable().size());
assertEquals(2, scenarioResultMetadata.getExecuted().size());
assertEquals((Integer) 2, scenarioResultMetadata.getExecutedWithCounter().get("rule1"));
assertEquals((Integer) 2, scenarioResultMetadata.getExecutedWithCounter().get("rule2"));
List<String> expectedMessages = new ArrayList<>();
commonAddMessageString(Arrays.asList("rule1", "rule2"), expectedMessages);
final List<AuditLogLine> auditLogLines = scenarioResultMetadata.getAuditLogLines();
assertEquals(expectedMessages.size(), auditLogLines.size());
for (int i = 0; i < expectedMessages.size(); i++) {
commonCheckAuditLogLine(auditLogLines.get(i), expectedMessages.get(i), ConstantsHolder.EXECUTED, null);
}
}
use of org.drools.scenariosimulation.api.model.Scenario in project drools by kiegroup.
the class SimulationRunMetadataBuilderTest method build.
@Test
public void build() {
ScenarioWithIndex scenarioWithIndex1 = new ScenarioWithIndex(1, new Scenario());
ScenarioResultMetadata result1 = new ScenarioResultMetadata(scenarioWithIndex1);
result1.addExecuted("d1");
result1.addExecuted("d2");
result1.addAvailable("d1");
result1.addAvailable("d2");
result1.addAvailable("d3");
List<DMNMessage> messagesResult1decision1 = getRandomlyGeneratedDMNMessageList();
List<DMNMessage> messagesResult1decision2 = getRandomlyGeneratedDMNMessageList();
Map<Integer, List<String>> expectedResult1Decision1 = fillAuditMessagesForDecision(result1, messagesResult1decision1, "d1");
Map<Integer, List<String>> expectedResult1Decision2 = fillAuditMessagesForDecision(result1, messagesResult1decision2, "d2");
ScenarioResultMetadata result2 = new ScenarioResultMetadata(new ScenarioWithIndex(2, new Scenario()));
List<String> expectedDecisionsResult2 = Arrays.asList("d1", "d3");
result2.addExecuted(expectedDecisionsResult2.get(0));
result2.addExecuted(expectedDecisionsResult2.get(1));
result2.addAvailable("d1");
result2.addAvailable("d2");
result2.addAvailable("d3");
List<DMNMessage> messagesResult2decision1 = getRandomlyGeneratedDMNMessageList();
List<DMNMessage> messagesResult2decision3 = getRandomlyGeneratedDMNMessageList();
Map<Integer, List<String>> expectedResult2Decision1 = fillAuditMessagesForDecision(result1, messagesResult2decision1, "d1");
Map<Integer, List<String>> expectedResult2Decision3 = fillAuditMessagesForDecision(result1, messagesResult2decision3, "d3");
SimulationRunMetadataBuilder builder = SimulationRunMetadataBuilder.create();
builder.addScenarioResultMetadata(result1);
builder.addScenarioResultMetadata(result2);
SimulationRunMetadata build = builder.build();
assertEquals(3, build.getAvailable());
assertEquals(3, build.getExecuted());
assertEquals(100, build.getCoveragePercentage(), 0.1);
assertEquals(2, build.getOutputCounter().get("d1"), 0.1);
assertEquals(1, build.getOutputCounter().get("d2"), 0.1);
assertEquals(2, build.getScenarioCounter().get(scenarioWithIndex1).size(), 0.1);
AuditLog retrieved = build.getAuditLog();
assertNotNull(retrieved);
final List<AuditLogLine> auditLogLines = retrieved.getAuditLogLines();
assertNotNull(auditLogLines);
assertEquals(auditLogLines.size(), messagesResult1decision1.size() + messagesResult1decision2.size() + messagesResult2decision1.size() + messagesResult2decision3.size());
checkAuditLogLine(auditLogLines, expectedResult1Decision1, expectedResult1Decision2, expectedResult2Decision1, expectedResult2Decision3);
}
Aggregations