Search in sources :

Example 16 with ScenarioWithIndex

use of org.drools.scenariosimulation.api.model.ScenarioWithIndex 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 17 with ScenarioWithIndex

use of org.drools.scenariosimulation.api.model.ScenarioWithIndex 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)

Example 18 with ScenarioWithIndex

use of org.drools.scenariosimulation.api.model.ScenarioWithIndex in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategy method createSimulation.

@Override
public Simulation createSimulation(Path context, String dmnFilePath) {
    final FactModelTuple factModelTuple = getFactModelTuple(context, dmnFilePath);
    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);
    AtomicInteger id = new AtomicInteger(1);
    final Collection<FactModelTree> visibleFactTrees = factModelTuple.getVisibleFacts().values();
    final Map<String, FactModelTree> hiddenValues = factModelTuple.getHiddenFacts();
    visibleFactTrees.stream().sorted((a, b) -> {
        Type aType = a.getType();
        Type bType = b.getType();
        int inputFirstOrder = Type.INPUT.equals(aType) ? -1 : 1;
        return aType.equals(bType) ? 0 : inputFirstOrder;
    }).forEach(factModelTree -> {
        FactIdentifier factIdentifier = FactIdentifier.create(factModelTree.getFactName(), factModelTree.getFactName(), factModelTree.getImportPrefix());
        FactMappingExtractor factMappingExtractor = new FactMappingExtractor(factIdentifier, scenarioWithIndex.getIndex(), id, convert(factModelTree.getType()), simulationDescriptor, scenarioWithIndex.getScesimData());
        addFactMapping(factMappingExtractor, factModelTree, new ArrayList<>(), hiddenValues);
    });
    addEmptyColumnsIfNeeded(toReturn, scenarioWithIndex);
    return toReturn;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) GIVEN(org.drools.scenariosimulation.api.model.FactMappingType.GIVEN) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Type(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) DMNTypeService(org.drools.workbench.screens.scenariosimulation.service.DMNTypeService) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Path(org.uberfire.backend.vfs.Path) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Collection(java.util.Collection) Settings(org.drools.scenariosimulation.api.model.Settings) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) ApplicationScoped(javax.enterprise.context.ApplicationScoped) EXPECT(org.drools.scenariosimulation.api.model.FactMappingType.EXPECT) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) Type(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Simulation(org.drools.scenariosimulation.api.model.Simulation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex)

Example 19 with ScenarioWithIndex

use of org.drools.scenariosimulation.api.model.ScenarioWithIndex in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategyTest method addEmptyColumnIfNeeded.

@Test
public void addEmptyColumnIfNeeded() {
    Simulation simulation = new Simulation();
    ScenarioWithIndex scenarioWithIndex = new ScenarioWithIndex(1, simulation.addData());
    ExpressionIdentifier givenExpressionIdentifier = ExpressionIdentifier.create("given1", GIVEN);
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.EMPTY, givenExpressionIdentifier);
    dmnSimulationCreationStrategy.addEmptyColumnsIfNeeded(simulation, scenarioWithIndex);
    assertEquals(2, simulationDescriptor.getFactMappings().size());
    assertTrue(simulationDescriptor.getFactMappings().stream().anyMatch(elem -> EXPECT.equals(elem.getExpressionIdentifier().getType())));
    simulation = new Simulation();
    scenarioWithIndex = new ScenarioWithIndex(1, simulation.addData());
    ExpressionIdentifier expectExpressionIdentifier = ExpressionIdentifier.create("expect1", EXPECT);
    simulationDescriptor = simulation.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.EMPTY, expectExpressionIdentifier);
    dmnSimulationCreationStrategy.addEmptyColumnsIfNeeded(simulation, scenarioWithIndex);
    assertEquals(2, simulationDescriptor.getFactMappings().size());
    assertTrue(simulationDescriptor.getFactMappings().stream().anyMatch(elem -> GIVEN.equals(elem.getExpressionIdentifier().getType())));
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Arrays(java.util.Arrays) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) GIVEN(org.drools.scenariosimulation.api.model.FactMappingType.GIVEN) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) DMNTypeService(org.drools.workbench.screens.scenariosimulation.service.DMNTypeService) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Mockito.doReturn(org.mockito.Mockito.doReturn) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Settings(org.drools.scenariosimulation.api.model.Settings) Matchers.any(org.mockito.Matchers.any) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Assert.assertFalse(org.junit.Assert.assertFalse) Simulation(org.drools.scenariosimulation.api.model.Simulation) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) EXPECT(org.drools.scenariosimulation.api.model.FactMappingType.EXPECT) SortedMap(java.util.SortedMap) Mockito.mock(org.mockito.Mockito.mock) DMNType(org.kie.dmn.api.core.DMNType) Mock(org.mockito.Mock) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) RunWith(org.junit.runner.RunWith) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) DECISION(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type.DECISION) Path(org.uberfire.backend.vfs.Path) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Before(org.junit.Before) OTHER(org.drools.scenariosimulation.api.model.FactMappingType.OTHER) Assert.assertNotNull(org.junit.Assert.assertNotNull) Background(org.drools.scenariosimulation.api.model.Background) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) TreeMap(java.util.TreeMap) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Simulation(org.drools.scenariosimulation.api.model.Simulation) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Test(org.junit.Test)

Example 20 with ScenarioWithIndex

use of org.drools.scenariosimulation.api.model.ScenarioWithIndex in project drools-wb by kiegroup.

the class CoverageScenarioListPresenterTest method commonAddScesimDataGroup.

private void commonAddScesimDataGroup(ScenarioSimulationModel.Type type, int scenarioIndex, String scenarioDescription, String expectedLabel) {
    Scenario scenario = new Scenario();
    scenario.setDescription(scenarioDescription);
    ScenarioWithIndex scenarioWithIndex = new ScenarioWithIndex(scenarioIndex, scenario);
    Map<String, Integer> resultCounter = new HashMap<>();
    coverageScenarioListPresenterSpy.addScesimDataGroup(scenarioWithIndex, resultCounter, type);
    verify(viewsProviderMock, times(1)).getCoverageScenarioListView();
    verify(coverageScenarioListViewMock, times(1)).setPresenter(eq(coverageScenarioListPresenterSpy));
    verify(coverageScenarioListViewMock, times(1)).setVisible(eq(false));
    verify(coverageScenarioListViewMock, times(1)).getScenarioElement();
    verify(coverageScenarioListViewMock, times(1)).setItemLabel(eq(expectedLabel));
    verify(scenarioElementMock, times(1)).appendChild(isA(HTMLUListElement.class));
}
Also used : HashMap(java.util.HashMap) HTMLUListElement(elemental2.dom.HTMLUListElement) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Aggregations

ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)20 Scenario (org.drools.scenariosimulation.api.model.Scenario)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)7 Path (org.uberfire.backend.vfs.Path)7 List (java.util.List)6 SimulationRunResult (org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult)6 Simulation (org.drools.scenariosimulation.api.model.Simulation)5 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)4 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 SimulationRunMetadata (org.drools.scenariosimulation.api.model.SimulationRunMetadata)4 ScenarioResultMetadata (org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Inject (javax.inject.Inject)3 AuditLogLine (org.drools.scenariosimulation.api.model.AuditLogLine)3 Background (org.drools.scenariosimulation.api.model.Background)3 BackgroundData (org.drools.scenariosimulation.api.model.BackgroundData)3 BackgroundDataWithIndex (org.drools.scenariosimulation.api.model.BackgroundDataWithIndex)3