Search in sources :

Example 6 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategyTest method verifySimulationCreated.

private void verifySimulationCreated(boolean hasInput, boolean hasOutput) throws Exception {
    final Path pathMock = mock(Path.class);
    final String dmnFilePath = "test";
    FactModelTuple factModelTuple = getFactModelTuple(hasInput, hasOutput);
    doReturn(factModelTuple).when(dmnSimulationCreationStrategy).getFactModelTuple(any(), any());
    Simulation simulation = dmnSimulationCreationStrategy.createSimulation(pathMock, dmnFilePath);
    assertNotNull(simulation);
    List<FactMapping> factMappings = simulation.getScesimModelDescriptor().getFactMappings();
    if (hasInput) {
        assertTrue(factMappings.stream().anyMatch(elem -> GIVEN.equals(elem.getExpressionIdentifier().getType())));
    } else {
        assertEquals(1, factMappings.stream().filter(elem -> GIVEN.equals(elem.getExpressionIdentifier().getType())).count());
    }
    if (hasOutput) {
        assertTrue(factMappings.stream().anyMatch(elem -> EXPECT.equals(elem.getExpressionIdentifier().getType())));
    } else {
        assertEquals(1, factMappings.stream().filter(elem -> EXPECT.equals(elem.getExpressionIdentifier().getType())).count());
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) Arrays(java.util.Arrays) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) GIVEN(org.drools.scenariosimulation.api.model.FactMappingType.GIVEN) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) DMNTypeService(org.drools.workbench.screens.scenariosimulation.service.DMNTypeService) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Mockito.doReturn(org.mockito.Mockito.doReturn) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Settings(org.drools.scenariosimulation.api.model.Settings) Matchers.any(org.mockito.Matchers.any) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Assert.assertFalse(org.junit.Assert.assertFalse) Simulation(org.drools.scenariosimulation.api.model.Simulation) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) EXPECT(org.drools.scenariosimulation.api.model.FactMappingType.EXPECT) SortedMap(java.util.SortedMap) Mockito.mock(org.mockito.Mockito.mock) DMNType(org.kie.dmn.api.core.DMNType) Mock(org.mockito.Mock) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) RunWith(org.junit.runner.RunWith) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) DECISION(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type.DECISION) Path(org.uberfire.backend.vfs.Path) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Before(org.junit.Before) OTHER(org.drools.scenariosimulation.api.model.FactMappingType.OTHER) Assert.assertNotNull(org.junit.Assert.assertNotNull) Background(org.drools.scenariosimulation.api.model.Background) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) TreeMap(java.util.TreeMap) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) Matchers.anyString(org.mockito.Matchers.anyString)

Example 7 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class AbstractDataManagementStrategyTest method storeDataSimulation.

@Test
public void storeDataSimulation() {
    ScenarioSimulationContext scenarioSimulationContextSpy = spy(scenarioSimulationContextLocal);
    doReturn(simulationMock).when(scenarioSimulationContextSpy).getAbstractScesimModelByGridWidget(GridWidget.SIMULATION);
    final FactModelTuple factModelTuple = getFactTuple();
    abstractDataManagementStrategySpy.storeData(factModelTuple, testToolsPresenterMock, scenarioSimulationContextSpy, GridWidget.SIMULATION);
    verify(testToolsPresenterMock, times(1)).populateTestTools(testToolsPresenterDataArgumentCaptor.capture());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getDataObjectFieldsMap());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getHiddenFieldsMap());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getInstanceFieldsMap());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getPropertiesToHide());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getSimpleJavaInstanceFieldsMap());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getSimpleJavaTypeFieldsMap());
    assertEquals(GridWidget.SIMULATION, testToolsPresenterDataArgumentCaptor.getValue().getGridWidget());
    verify(scenarioSimulationContextSpy, times(1)).setDataObjectFieldsMap(isA(SortedMap.class));
    verify(scenarioSimulationContextSpy, times(1)).setDataObjectsInstancesName(isA(Set.class));
    verify(scenarioGridModelMock, times(1)).setSimpleJavaTypeInstancesName(isA(Set.class));
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) Set(java.util.Set) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) SortedMap(java.util.SortedMap) AbstractScenarioSimulationEditorTest(org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest) Test(org.junit.Test)

Example 8 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class DMNTypeServiceImpl method retrieveFactModelTuple.

@Override
public FactModelTuple retrieveFactModelTuple(Path path, String dmnPath) {
    DMNModel dmnModel = getDMNModel(path, dmnPath);
    SortedMap<String, FactModelTree> visibleFacts = new TreeMap<>();
    SortedMap<String, FactModelTree> hiddenFacts = new TreeMap<>();
    ErrorHolder errorHolder = new ErrorHolder();
    Map<String, String> importedModelsMap = dmnModel.getDefinitions().getImport().stream().collect(Collectors.toMap(Import::getNamespace, Import::getName));
    for (InputDataNode input : dmnModel.getInputs()) {
        final DMNType type = input.getType();
        final String importPrefix = importedModelsMap.getOrDefault(input.getModelNamespace(), null);
        final String name = importedModelsMap.containsKey(input.getModelNamespace()) ? importedModelsMap.get(input.getModelNamespace()) + "." + input.getName() : input.getName();
        checkTypeSupport(type, errorHolder, name);
        try {
            visibleFacts.put(name, createTopLevelFactModelTree(name, importPrefix, type, hiddenFacts, FactModelTree.Type.INPUT));
        } catch (WrongDMNTypeException e) {
            throw ExceptionUtilities.handleException(e);
        }
    }
    for (DecisionNode decision : dmnModel.getDecisions()) {
        DMNType type = decision.getResultType();
        final String importPrefix = importedModelsMap.getOrDefault(decision.getModelNamespace(), null);
        final String name = importedModelsMap.containsKey(decision.getModelNamespace()) ? importedModelsMap.get(decision.getModelNamespace()) + "." + decision.getName() : decision.getName();
        checkTypeSupport(type, errorHolder, name);
        try {
            visibleFacts.put(name, createTopLevelFactModelTree(name, importPrefix, type, hiddenFacts, FactModelTree.Type.DECISION));
        } catch (WrongDMNTypeException e) {
            throw ExceptionUtilities.handleException(e);
        }
    }
    FactModelTuple factModelTuple = new FactModelTuple(visibleFacts, hiddenFacts);
    errorHolder.getMultipleNestedCollection().forEach(factModelTuple::addMultipleNestedCollectionError);
    errorHolder.getMultipleNestedObject().forEach(factModelTuple::addMultipleNestedObjectError);
    return factModelTuple;
}
Also used : FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) WrongDMNTypeException(org.drools.workbench.screens.scenariosimulation.backend.server.exceptions.WrongDMNTypeException) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DMNModel(org.kie.dmn.api.core.DMNModel) DMNType(org.kie.dmn.api.core.DMNType)

Example 9 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class AbstractDMODataManagementStrategy method aggregatorCallbackMethod.

/**
 * Actual code of the <b>aggregatorCallback</b>; isolated for testing
 * @param testToolsPresenter
 * @param expectedElements
 * @param factTypeFieldsMap
 * @param context
 * @param result pass <code>null</code> if there is not any <i>complex</i> data object but only simple ones
 * @param simpleJavaTypes
 */
public void aggregatorCallbackMethod(final TestToolsView.Presenter testToolsPresenter, final int expectedElements, final SortedMap<String, FactModelTree> factTypeFieldsMap, final ScenarioSimulationContext context, final FactModelTree result, final List<String> simpleJavaTypes, final GridWidget gridWidget) {
    if (result != null) {
        factTypeFieldsMap.put(result.getFactName(), result);
    }
    if (factTypeFieldsMap.size() == expectedElements) {
        // This is used to invoke this callback only once, when all the expected "complex" objects has been managed
        factTypeFieldsMap.values().forEach(factModelTree -> populateFactModelTree(factModelTree, factTypeFieldsMap));
        SortedMap<String, FactModelTree> simpleJavaTypeFieldsMap = new TreeMap<>(simpleJavaTypes.stream().collect(Collectors.toMap(factType -> factType, factType -> {
            SimpleClassEntry classEntry = SIMPLE_CLASSES_MAP.get(factType);
            return getSimpleClassFactModelTree(classEntry.getSimpleName(), classEntry.getCanonicalName());
        })));
        SortedMap<String, FactModelTree> visibleFacts = new TreeMap<>(factTypeFieldsMap);
        visibleFacts.putAll(simpleJavaTypeFieldsMap);
        FactModelTuple factModelTuple = new FactModelTuple(visibleFacts, new TreeMap<>());
        factModelTreeHolder.setFactModelTuple(factModelTuple);
        storeData(factModelTuple, testToolsPresenter, context, gridWidget);
    }
}
Also used : FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 10 with FactModelTuple

use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple in project drools-wb by kiegroup.

the class DMNTypeServiceImplTest method retrieveFactModelTupleDmnList.

@Test
public void retrieveFactModelTupleDmnList() {
    setDmnModelLocal("dmn-list.dmn", "https://github.com/kiegroup/drools/kie-dmn/_CC8924B0-D729-4D70-9588-039B5824FFE9", "dmn-list");
    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));
}
Also used : Path(org.uberfire.backend.vfs.Path) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) Test(org.junit.Test)

Aggregations

FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)17 Test (org.junit.Test)9 TreeMap (java.util.TreeMap)8 FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)7 SortedMap (java.util.SortedMap)6 Path (org.uberfire.backend.vfs.Path)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 ScenarioSimulationContext (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext)5 HashMap (java.util.HashMap)4 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)4 Settings (org.drools.scenariosimulation.api.model.Settings)4 Simulation (org.drools.scenariosimulation.api.model.Simulation)4 VALUE (org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE)4 Before (org.junit.Before)4 DMNType (org.kie.dmn.api.core.DMNType)4 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)4 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)4