use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.
the class DMNTypeServiceImplTest method retrieveFactModelTupleDmnListComposite.
@Test
public void retrieveFactModelTupleDmnListComposite() {
setDmnModelLocal("dmn-list-composite.dmn", "https://github.com/kiegroup/drools/kie-dmn/_25BF2679-3109-488F-9AD1-DDBCCEBBE5F1", "dmn-list-composite");
FactModelTuple factModelTuple = dmnTypeServiceImpl.retrieveFactModelTuple(mock(Path.class), null);
// VisibleFacts should match inputs and decisions on given model
int expectedVisibleFacts = dmnModelLocal.getInputs().size() + dmnModelLocal.getDecisions().size();
assertEquals(expectedVisibleFacts, factModelTuple.getVisibleFacts().size());
Map<String, String> importedModelsMap = dmnModelLocal.getDefinitions().getImport().stream().collect(Collectors.toMap(Import::getNamespace, Import::getName));
// Verify each inputDataNode has been correctly mapped
dmnModelLocal.getInputs().forEach(inputDataNode -> verifyFactModelTree(factModelTuple, inputDataNode, factModelTuple.getHiddenFacts(), importedModelsMap));
// Verify each decisionNode has been correctly mapped
dmnModelLocal.getDecisions().forEach(decisionNode -> verifyFactModelTree(factModelTuple, decisionNode, factModelTuple.getHiddenFacts(), importedModelsMap));
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.
the class DMNTypeServiceImplTest method retrieveFactModelTupleUsingImportedTrafficViolation.
@Test
public void retrieveFactModelTupleUsingImportedTrafficViolation() {
setDmnModelLocal("Using Imported.dmn", "https://kiegroup.org/dmn/_7120AA2F-BEB6-4CB1-BCC7-427A17AEF71D", "Using Imported", "Traffic Violation.dmn");
FactModelTuple factModelTuple = dmnTypeServiceImpl.retrieveFactModelTuple(mock(Path.class), null);
// VisibleFacts should match inputs and decisions on given model
int expectedVisibleFacts = dmnModelLocal.getInputs().size() + dmnModelLocal.getDecisions().size();
assertEquals(expectedVisibleFacts, factModelTuple.getVisibleFacts().size());
Map<String, String> importedModelsMap = dmnModelLocal.getDefinitions().getImport().stream().collect(Collectors.toMap(Import::getNamespace, Import::getName));
// Verify each inputDataNode has been correctly mapped
dmnModelLocal.getInputs().forEach(inputDataNode -> verifyFactModelTree(factModelTuple, inputDataNode, factModelTuple.getHiddenFacts(), importedModelsMap));
// Verify each decisionNode has been correctly mapped
dmnModelLocal.getDecisions().forEach(decisionNode -> verifyFactModelTree(factModelTuple, decisionNode, factModelTuple.getHiddenFacts(), importedModelsMap));
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategyTest method createSimulation.
@Test
public void createSimulation() throws Exception {
FactModelTuple factModelTuple = getFactModelTuple();
final Path pathMock = mock(Path.class);
final String dmnFilePath = "test";
doReturn(factModelTuple).when(dmnSimulationCreationStrategy).getFactModelTuple(any(), any());
final Simulation retrieved = dmnSimulationCreationStrategy.createSimulation(pathMock, dmnFilePath);
assertNotNull(retrieved);
verify(dmnTypeServiceMock, never()).initializeNameAndNamespace(any(Settings.class), eq(pathMock), eq(dmnFilePath));
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple 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.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.
the class AbstractDMNDataManagementStrategyTest method setup.
@Before
public void setup() {
super.setup();
factModelTupleLocal = new FactModelTuple(visibleFactsLocal, hiddenFactsLocal);
factModelTreeHolderlocal = new AbstractDataManagementStrategy.ResultHolder();
factModelTreeHolderlocal.setFactModelTuple(factModelTupleLocal);
when(dmnTypeServiceMock.retrieveFactModelTuple(any(), anyString())).thenReturn(factModelTupleLocal);
modelLocal.getSettings().setDmnFilePath(DMN_FILE_PATH);
abstractDMNDataManagementStrategySpy = spy(new AbstractDMNDataManagementStrategy(mock(EventBus.class)) {
@Override
protected void retrieveFactModelTuple(TestToolsView.Presenter testToolsPresenter, ScenarioSimulationContext context, GridWidget gridWidget) {
}
{
this.currentPath = mock(Path.class);
this.model = modelLocal;
this.factModelTreeHolder = factModelTreeHolderlocal;
this.dmnFilePath = DMN_FILE_PATH;
}
});
}
Aggregations