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;
}
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;
}
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());
}
}
}
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);
}
}
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);
}
Aggregations