RuleScenarioRunnerHelper extends AbstractRunnerHelper { @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; }    }
@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); } }