Search in sources :

Example 41 with FactModelTree

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

the class SetHeaderCellValueCommandTest method commonValidatePropertyHeader.

private void commonValidatePropertyHeader(boolean factModelPresent, boolean simplePropertyPresent) throws Exception {
    FactModelTree factModelTreeMock = mock(FactModelTree.class);
    doReturn(simplePropertyPresent).when((SetHeaderCellValueCommand) commandSpy).recursivelyFindIsPropertyType(eq(scenarioSimulationContextLocal), eq(factModelTreeMock), eq(MULTIPART_VALUE_ELEMENTS));
    if (factModelPresent) {
        Map<String, FactModelTree.PropertyTypeName> simplePropertiesMock = mock(SortedMap.class);
        when(factModelTreeMock.getSimpleProperties()).thenReturn(simplePropertiesMock);
        Map<String, String> expandablePropertiesMock = mock(SortedMap.class);
        when(factModelTreeMock.getExpandableProperties()).thenReturn(expandablePropertiesMock);
        when(dataObjectFieldsMapMock.get(anyString())).thenReturn(factModelTreeMock);
        doReturn(simplePropertyPresent).when(simplePropertiesMock).containsKey(eq(MULTIPART_VALUE_ELEMENTS.get(0)));
        doReturn(simplePropertyPresent).when(expandablePropertiesMock).containsKey(eq(MULTIPART_VALUE_ELEMENTS.get(0)));
    } else {
        when(dataObjectFieldsMapMock.get(anyString())).thenReturn(null);
    }
    boolean isPropertyType = factModelPresent && simplePropertyPresent;
    doNothing().when(scenarioGridModelMock).validatePropertyHeaderUpdate(eq(MULTIPART_VALUE), eq(COLUMN_INDEX), eq(isPropertyType));
    ((SetHeaderCellValueCommand) commandSpy).validatePropertyHeader(scenarioSimulationContextLocal, MULTIPART_VALUE, COLUMN_INDEX);
    verify(simulationDescriptorMock, times(1)).getFactMappingByIndex(eq(COLUMN_INDEX));
    verify(scenarioGridModelMock, times(1)).validatePropertyHeaderUpdate(eq(MULTIPART_VALUE), eq(COLUMN_INDEX), eq(isPropertyType));
    reset(simulationDescriptorMock);
    reset(scenarioGridModelMock);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 42 with FactModelTree

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

the class SetHeaderCellValueCommandTest method getMockedFactModelTree.

private FactModelTree getMockedFactModelTree(Map<String, FactModelTree.PropertyTypeName> simpleProperties, Map<String, String> expandableProperties) {
    FactModelTree toReturn = mock(FactModelTree.class);
    when(toReturn.getSimpleProperties()).thenReturn(simpleProperties);
    when(toReturn.getExpandableProperties()).thenReturn(expandableProperties);
    return toReturn;
}
Also used : FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)

Example 43 with FactModelTree

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

the class AbstractDMODataManagementStrategyTest method getFactModelTreeEnumClass.

@Test
public void getFactModelTreeEnumClass() {
    final ModelField[] modelFields = {};
    Map<String, String> superTypesMap = new HashMap<>();
    superTypesMap.put(FACT_NAME, Enum.class.getCanonicalName());
    final FactModelTree retrieved = abstractDMODataManagementStrategySpy.getFactModelTree(FACT_NAME, superTypesMap, modelFields);
    assertNotNull(retrieved);
    assertEquals(FACT_NAME, retrieved.getFactName());
    assertEquals(FULL_PACKAGE, retrieved.getFullPackage());
    assertTrue(retrieved.getSimpleProperties().containsKey(TestProperties.LOWER_CASE_VALUE));
    assertEquals(FULL_CLASS_NAME, retrieved.getSimpleProperties().get(TestProperties.LOWER_CASE_VALUE).getTypeName());
    assertEquals(FULL_CLASS_NAME, retrieved.getSimpleProperties().get(TestProperties.LOWER_CASE_VALUE).getPropertyTypeNameToVisualize());
    assertFalse(retrieved.getSimpleProperties().get(TestProperties.LOWER_CASE_VALUE).getBaseTypeName().isPresent());
    assertEquals(FULL_CLASS_NAME, retrieved.getSimpleProperties().get(TestProperties.LOWER_CASE_VALUE).getPropertyTypeNameToVisualize());
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) AbstractScenarioSimulationEditorTest(org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest) Test(org.junit.Test)

Example 44 with FactModelTree

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

the class TestToolsPresenterTest method getFactModelTree.

@Test
public void getFactModelTree() {
    testToolsPresenterSpy.setDataObjectFieldsMap(dataObjectFactTreeMap);
    String factName = getRandomFactModelTree(dataObjectFactTreeMap, 0);
    Optional<FactModelTree> retrieved = testToolsPresenterSpy.getFactModelTreeFromFactTypeMap(factName);
    assertNotNull(retrieved);
    assertTrue(retrieved.isPresent());
    assertEquals(dataObjectFactTreeMap.get(factName), retrieved.get());
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) Test(org.junit.Test)

Example 45 with FactModelTree

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

the class AbstractDataManagementStrategy method storeData.

/**
 * Store data in required target objects
 */
public void storeData(final FactModelTuple factModelTuple, final TestToolsView.Presenter testToolsPresenter, final ScenarioSimulationContext context, final GridWidget gridWidget) {
    // Instantiate a map of already assigned properties
    final Map<String, List<List<String>>> propertiesToHide = getPropertiesToHide(context.getAbstractScesimGridModelByGridWidget(gridWidget));
    final SortedMap<String, FactModelTree> visibleFacts = factModelTuple.getVisibleFacts();
    final Map<Boolean, List<Map.Entry<String, FactModelTree>>> partitionBy = visibleFacts.entrySet().stream().collect(Collectors.partitioningBy(stringFactModelTreeEntry -> stringFactModelTreeEntry.getValue().isSimple()));
    final SortedMap<String, FactModelTree> complexDataObjects = new TreeMap<>(partitionBy.get(false).stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    final SortedMap<String, FactModelTree> simpleDataObjects = new TreeMap<>(partitionBy.get(true).stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    // Update context
    SortedMap<String, FactModelTree> dataObjectFieldsMap = new TreeMap<>();
    dataObjectFieldsMap.putAll(visibleFacts);
    dataObjectFieldsMap.putAll(factModelTuple.getHiddenFacts());
    context.setDataObjectFieldsMap(dataObjectFieldsMap);
    // Update model
    // Avoid Collections.emptySortedMap() due to "The method emptySortedMap() is undefined for the type Collections" error
    SortedMap<String, FactModelTree> instanceFieldsMap = new TreeMap<>();
    SortedMap<String, FactModelTree> simpleJavaTypeInstanceFieldsMap = new TreeMap<>();
    if (GridWidget.SIMULATION.equals(gridWidget)) {
        instanceFieldsMap = getInstanceMap(complexDataObjects);
        simpleJavaTypeInstanceFieldsMap = getInstanceMap(simpleDataObjects);
        Set<String> dataObjectsInstancesName = new HashSet<>(visibleFacts.keySet());
        dataObjectsInstancesName.addAll(instanceFieldsMap.keySet());
        context.setDataObjectsInstancesName(dataObjectsInstancesName);
        Set<String> simpleJavaTypeInstancesName = new HashSet<>(simpleDataObjects.keySet());
        simpleJavaTypeInstancesName.addAll(simpleJavaTypeInstanceFieldsMap.keySet());
        context.getAbstractScesimGridModelByGridWidget(gridWidget).setSimpleJavaTypeInstancesName(simpleJavaTypeInstancesName);
    }
    // Update right panel
    TestToolsPresenterData testToolsPresenterData = new TestToolsPresenterData(complexDataObjects, simpleDataObjects, instanceFieldsMap, simpleJavaTypeInstanceFieldsMap, factModelTuple.getHiddenFacts(), propertiesToHide, gridWidget);
    testToolsPresenter.populateTestTools(testToolsPresenterData);
}
Also used : ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) Map(java.util.Map) AbstractScesimGridModel(org.drools.workbench.screens.scenariosimulation.client.models.AbstractScesimGridModel) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) TestToolsPresenterData(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenterData) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Collectors(java.util.stream.Collectors) TestToolsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsView) Objects(java.util.Objects) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) TreeMap(java.util.TreeMap) Collections(java.util.Collections) SortedMap(java.util.SortedMap) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) ArrayList(java.util.ArrayList) List(java.util.List) TestToolsPresenterData(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenterData) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) HashSet(java.util.HashSet)

Aggregations

FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)47 Test (org.junit.Test)19 TreeMap (java.util.TreeMap)16 Matchers.anyString (org.mockito.Matchers.anyString)14 HashMap (java.util.HashMap)10 DMNType (org.kie.dmn.api.core.DMNType)10 ArrayList (java.util.ArrayList)9 AbstractScenarioSimulationEditorTest (org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest)8 FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)7 List (java.util.List)6 Map (java.util.Map)6 SortedMap (java.util.SortedMap)6 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)6 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)3 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)3 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)3