Search in sources :

Example 11 with Scenario

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());
    }
}
Also used : ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test)

Example 12 with Scenario

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));
}
Also used : SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) BackgroundDataWithIndex(org.drools.scenariosimulation.api.model.BackgroundDataWithIndex) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) ArrayList(java.util.ArrayList) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test)

Example 13 with Scenario

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);
}
Also used : Scenario(org.drools.scenariosimulation.api.model.Scenario)

Example 14 with Scenario

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);
    }
}
Also used : AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) TestUtils.commonCheckAuditLogLine(org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Scenario(org.drools.scenariosimulation.api.model.Scenario) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) CoverageAgendaListener(org.drools.scenariosimulation.backend.fluent.CoverageAgendaListener) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) AbstractRuleCoverageTest(org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest) Test(org.junit.Test)

Example 15 with Scenario

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);
}
Also used : AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) TestUtils.commonCheckAuditLogLine(org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine) AuditLog(org.drools.scenariosimulation.api.model.AuditLog) Scenario(org.drools.scenariosimulation.api.model.Scenario) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DMNMessage(org.kie.dmn.api.core.DMNMessage) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) TestUtils.getRandomlyGeneratedDMNMessageList(org.drools.scenariosimulation.backend.TestUtils.getRandomlyGeneratedDMNMessageList) ArrayList(java.util.ArrayList) List(java.util.List) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Test(org.junit.Test)

Aggregations

Scenario (org.drools.scenariosimulation.api.model.Scenario)19 Test (org.junit.Test)10 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)9 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)6 Simulation (org.drools.scenariosimulation.api.model.Simulation)6 ArrayList (java.util.ArrayList)4 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)4 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)3 SimulationRunMetadata (org.drools.scenariosimulation.api.model.SimulationRunMetadata)3 SimulationRunResult (org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult)3 Matchers.anyString (org.mockito.Matchers.anyString)3 HashMap (java.util.HashMap)2 List (java.util.List)2 AuditLogLine (org.drools.scenariosimulation.api.model.AuditLogLine)2 Background (org.drools.scenariosimulation.api.model.Background)2 Settings (org.drools.scenariosimulation.api.model.Settings)2 TestUtils.commonCheckAuditLogLine (org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine)2 AbstractRuleCoverageTest (org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest)2 ScenarioResultMetadata (org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata)2 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)2