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