Search in sources :

Example 1 with ScenarioResultMetadata

use of org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata in project drools by kiegroup.

the class DMNScenarioRunnerHelper method extractResultMetadata.

@Override
protected ScenarioResultMetadata extractResultMetadata(Map<String, Object> requestContext, ScenarioWithIndex scenarioWithIndex) {
    DMNModel dmnModel = (DMNModel) requestContext.get(DMNScenarioExecutableBuilder.DMN_MODEL);
    DMNResult dmnResult = (DMNResult) requestContext.get(DMNScenarioExecutableBuilder.DMN_RESULT);
    ScenarioResultMetadata scenarioResultMetadata = new ScenarioResultMetadata(scenarioWithIndex);
    for (DecisionNode decision : dmnModel.getDecisions()) {
        scenarioResultMetadata.addAvailable(decision.getName());
    }
    final AtomicInteger counter = new AtomicInteger(0);
    for (DMNDecisionResult decisionResult : dmnResult.getDecisionResults()) {
        if (SUCCEEDED.equals(decisionResult.getEvaluationStatus())) {
            scenarioResultMetadata.addExecuted(decisionResult.getDecisionName());
        }
        if (decisionResult.getMessages().isEmpty()) {
            scenarioResultMetadata.addAuditMessage(counter.addAndGet(1), decisionResult.getDecisionName(), decisionResult.getEvaluationStatus().name());
        } else {
            decisionResult.getMessages().forEach(dmnMessage -> scenarioResultMetadata.addAuditMessage(counter.addAndGet(1), decisionResult.getDecisionName(), decisionResult.getEvaluationStatus().name(), dmnMessage.getLevel().name() + ": " + dmnMessage.getText()));
        }
    }
    return scenarioResultMetadata;
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 2 with ScenarioResultMetadata

use of org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata in project drools by kiegroup.

the class RuleScenarioRunnerHelper method extractResultMetadata.

@SuppressWarnings("unchecked")
@Override
protected ScenarioResultMetadata extractResultMetadata(Map<String, Object> requestContext, ScenarioWithIndex scenarioWithIndex) {
    CoverageAgendaListener coverageAgendaListener = (CoverageAgendaListener) requestContext.get(COVERAGE_LISTENER);
    Map<String, Integer> ruleExecuted = coverageAgendaListener.getRuleExecuted();
    Set<String> availableRules = (Set<String>) requestContext.get(RULES_AVAILABLE);
    ScenarioResultMetadata scenarioResultMetadata = new ScenarioResultMetadata(scenarioWithIndex);
    scenarioResultMetadata.addAllAvailable(availableRules);
    scenarioResultMetadata.addAllExecuted(ruleExecuted);
    final AtomicInteger counter = new AtomicInteger(0);
    coverageAgendaListener.getAuditsMessages().forEach(auditMessage -> scenarioResultMetadata.addAuditMessage(counter.addAndGet(1), auditMessage, ConstantsHolder.EXECUTED));
    return scenarioResultMetadata;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Set(java.util.Set) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoverageAgendaListener(org.drools.scenariosimulation.backend.fluent.CoverageAgendaListener)

Example 3 with ScenarioResultMetadata

use of org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata 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());
        }
    }
}
Also used : AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) TestUtils.commonCheckAuditLogLine(org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine) ArrayList(java.util.ArrayList) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Mockito.anyString(org.mockito.Mockito.anyString) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) HashSet(java.util.HashSet)

Example 4 with ScenarioResultMetadata

use of org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata 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 5 with ScenarioResultMetadata

use of org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata 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

ScenarioResultMetadata (org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata)6 ArrayList (java.util.ArrayList)4 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AuditLogLine (org.drools.scenariosimulation.api.model.AuditLogLine)3 TestUtils.commonCheckAuditLogLine (org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine)3 List (java.util.List)2 AuditLog (org.drools.scenariosimulation.api.model.AuditLog)2 Scenario (org.drools.scenariosimulation.api.model.Scenario)2 SimulationRunMetadata (org.drools.scenariosimulation.api.model.SimulationRunMetadata)2 CoverageAgendaListener (org.drools.scenariosimulation.backend.fluent.CoverageAgendaListener)2 Test (org.junit.Test)2 DMNDecisionResult (org.kie.dmn.api.core.DMNDecisionResult)2 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 TestUtils.getRandomlyGeneratedDMNMessageList (org.drools.scenariosimulation.backend.TestUtils.getRandomlyGeneratedDMNMessageList)1