Search in sources :

Example 1 with CoverageAgendaListener

use of org.drools.scenariosimulation.backend.fluent.CoverageAgendaListener 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 2 with CoverageAgendaListener

use of org.drools.scenariosimulation.backend.fluent.CoverageAgendaListener 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)

Aggregations

CoverageAgendaListener (org.drools.scenariosimulation.backend.fluent.CoverageAgendaListener)2 ScenarioResultMetadata (org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AuditLogLine (org.drools.scenariosimulation.api.model.AuditLogLine)1 Scenario (org.drools.scenariosimulation.api.model.Scenario)1 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)1 TestUtils.commonCheckAuditLogLine (org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine)1 AbstractRuleCoverageTest (org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest)1 Test (org.junit.Test)1