Search in sources :

Example 1 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext in project drools-wb by kiegroup.

the class AbstractScenarioSimulationTest method setup.

@Before
public void setup() {
    settingsLocal = new Settings();
    backgroundLocal = new Background();
    scenarioWithIndexLocal = new ArrayList<>();
    scenarioGridWidgetSpy = spy(new ScenarioGridWidget() {

        {
            this.scenarioGridPanel = scenarioGridPanelMock;
        }
    });
    backgroundGridWidgetSpy = spy(new ScenarioGridWidget() {

        {
            this.scenarioGridPanel = backgroundGridPanelMock;
        }
    });
    when(simulationMock.getScesimModelDescriptor()).thenReturn(simulationDescriptorMock);
    when(simulationMock.getScenarioWithIndex()).thenReturn(scenarioWithIndexLocal);
    when(backgroundMock.getScesimModelDescriptor()).thenReturn(simulationDescriptorMock);
    when(simulationRunResultMock.getScenarioWithIndex()).thenReturn(scenarioWithIndexLocal);
    GridData.Range range = new GridData.Range(FIRST_INDEX_LEFT, FIRST_INDEX_RIGHT - 1);
    collectionEditorSingletonDOMElementFactoryTest = new CollectionEditorSingletonDOMElementFactory(scenarioGridPanelMock, scenarioGridLayerMock, scenarioGridMock, scenarioSimulationContextLocal, viewsProviderMock);
    scenarioCellTextAreaSingletonDOMElementFactorySpy = spy(new ScenarioCellTextAreaSingletonDOMElementFactory(scenarioGridPanelMock, scenarioGridLayerMock, scenarioGridMock));
    scenarioHeaderTextBoxSingletonDOMElementFactorySpy = spy(new ScenarioHeaderTextBoxSingletonDOMElementFactory(scenarioGridPanelMock, scenarioGridLayerMock, scenarioGridMock));
    scenarioExpressionCellTextAreaSingletonDOMElementFactorySpy = spy(new ScenarioExpressionCellTextAreaSingletonDOMElementFactory(scenarioGridPanelMock, scenarioGridLayerMock, scenarioGridMock));
    scenarioGridModelMock = spy(new ScenarioGridModel(false) {

        {
            this.abstractScesimModel = simulationMock;
            this.columns = gridColumns;
            this.rows = rowsMock;
            this.collectionEditorSingletonDOMElementFactory = collectionEditorSingletonDOMElementFactoryTest;
            this.scenarioCellTextAreaSingletonDOMElementFactory = scenarioCellTextAreaSingletonDOMElementFactorySpy;
            this.scenarioHeaderTextBoxSingletonDOMElementFactory = scenarioHeaderTextBoxSingletonDOMElementFactorySpy;
            this.scenarioExpressionCellTextAreaSingletonDOMElementFactory = scenarioExpressionCellTextAreaSingletonDOMElementFactorySpy;
            this.eventBus = eventBusMock;
        }

        @Override
        protected void commonAddColumn(int index, GridColumn<?> column) {
        // 
        }

        @Override
        protected void commonAddColumn(final int index, final GridColumn<?> column, ExpressionIdentifier ei) {
        // 
        }

        @Override
        protected void commonAddRow(int rowIndex) {
        // 
        }

        @Override
        public List<GridColumn<?>> getColumns() {
            return columns;
        }

        @Override
        public Range getInstanceLimits(int columnIndex) {
            return range;
        }

        @Override
        public int getFirstIndexLeftOfGroup(String groupName) {
            return FIRST_INDEX_LEFT;
        }

        @Override
        public int getFirstIndexRightOfGroup(String groupName) {
            return FIRST_INDEX_RIGHT;
        }

        @Override
        public GridColumn<?> getSelectedColumn() {
            return gridColumnMock;
        }

        @Override
        public void deleteColumn(final GridColumn<?> column) {
        // 
        }

        @Override
        public Range deleteRow(int rowIndex) {
            return range;
        }

        @Override
        public void insertRowGridOnly(final int rowIndex, final GridRow row, final Scenario scenario) {
        // 
        }

        @Override
        public void insertRow(int rowIndex, GridRow row) {
        }

        @Override
        public List<GridRow> getRows() {
            return rowsMock;
        }

        @Override
        public Range setCellValue(int rowIndex, int columnIndex, GridCellValue<?> value) {
            return range;
        }

        @Override
        public void validateInstanceHeaderUpdate(String instanceHeaderCellValue, int columnIndex, boolean isADataType) {
        // 
        }

        @Override
        public void validatePropertyHeaderUpdate(String propertyHeaderCellValue, int columnIndex, boolean isPropertyType) {
        // 
        }
    });
    when(scenarioGridMock.getEventBus()).thenReturn(eventBusMock);
    when(scenarioGridMock.getModel()).thenReturn(scenarioGridModelMock);
    when(scenarioGridMock.getLayer()).thenReturn(scenarioGridLayerMock);
    when(scenarioGridMock.getType()).thenReturn(ScenarioSimulationModel.Type.RULE);
    when(scenarioGridMock.getGridWidget()).thenReturn(GridWidget.SIMULATION);
    when(scenarioGridLayerMock.getScenarioGrid()).thenReturn(scenarioGridMock);
    when(scenarioGridPanelMock.getScenarioGridLayer()).thenReturn(scenarioGridLayerMock);
    when(scenarioGridPanelMock.getScenarioGrid()).thenReturn(scenarioGridMock);
    when(backgroundGridMock.getEventBus()).thenReturn(eventBusMock);
    when(backgroundGridMock.getModel()).thenReturn(backgroundGridModelMock);
    when(backgroundGridMock.getLayer()).thenReturn(backgroundGridLayerMock);
    when(backgroundGridMock.getType()).thenReturn(ScenarioSimulationModel.Type.RULE);
    when(backgroundGridMock.getGridWidget()).thenReturn(GridWidget.BACKGROUND);
    when(backgroundGridModelMock.getGridWidget()).thenReturn(GridWidget.BACKGROUND);
    when(backgroundGridLayerMock.getScenarioGrid()).thenReturn(backgroundGridMock);
    when(backgroundGridPanelMock.getScenarioGridLayer()).thenReturn(backgroundGridLayerMock);
    when(backgroundGridPanelMock.getScenarioGrid()).thenReturn(backgroundGridMock);
    final Point2D computedLocation = mock(Point2D.class);
    when(computedLocation.getX()).thenReturn(0.0);
    when(computedLocation.getY()).thenReturn(0.0);
    when(scenarioGridMock.getComputedLocation()).thenReturn(computedLocation);
    scenarioSimulationContextLocal = new ScenarioSimulationContext(scenarioGridWidgetSpy, backgroundGridWidgetSpy);
    scenarioSimulationContextLocal.setScenarioSimulationEditorPresenter(scenarioSimulationEditorPresenterMock);
    scenarioSimulationContextLocal.getStatus().setSimulation(simulationMock);
    scenarioSimulationContextLocal.getStatus().setBackground(backgroundMock);
    scenarioSimulationContextLocal.getStatus().setFullPackage(FULL_PACKAGE);
    scenarioSimulationContextLocal.setScenarioSimulationEditorPresenter(scenarioSimulationEditorPresenterMock);
    scenarioSimulationContextLocal.setDataObjectFieldsMap(dataObjectFieldsMapMock);
    when(backgroundGridWidgetSpy.getScenarioSimulationContext()).thenReturn(scenarioSimulationContextLocal);
    when(scenarioGridWidgetSpy.getScenarioSimulationContext()).thenReturn(scenarioSimulationContextLocal);
    when(scenarioSimulationEditorPresenterMock.getView()).thenReturn(scenarioSimulationViewMock);
    when(scenarioSimulationEditorPresenterMock.getModel()).thenReturn(scenarioSimulationModelMock);
    scenarioSimulationContextLocal.setScenarioSimulationEditorPresenter(scenarioSimulationEditorPresenterMock);
    when(scenarioSimulationEditorPresenterMock.getDataManagementStrategy()).thenReturn(dataManagementStrategyMock);
    when(scenarioSimulationEditorPresenterMock.getContext()).thenReturn(scenarioSimulationContextLocal);
    when(simulationMock.cloneModel()).thenReturn(clonedSimulationMock);
    when(backgroundMock.cloneModel()).thenReturn(clonedBackgroundMock);
    scenarioSimulationContextLocal.getStatus().setSimulation(simulationMock);
    when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationMock);
    when(scenarioSimulationModelMock.getBackground()).thenReturn(backgroundMock);
    when(scenarioSimulationModelMock.getSettings()).thenReturn(settingsLocal);
    when(scenarioCommandRegistryManagerMock.undo(scenarioSimulationContextLocal)).thenReturn(CommandResultBuilder.SUCCESS);
    when(scenarioCommandRegistryManagerMock.redo(scenarioSimulationContextLocal)).thenReturn(CommandResultBuilder.SUCCESS);
    appendRowCommandMock = spy(new AppendRowCommand(GridWidget.SIMULATION) {

        {
            this.restorableStatus = scenarioSimulationContextLocal.getStatus();
        }

        @Override
        public CommandResult<ScenarioSimulationViolation> execute(ScenarioSimulationContext context) {
            return CommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<ScenarioSimulationViolation> undo(ScenarioSimulationContext context) {
            return CommandResultBuilder.SUCCESS;
        }
    });
    when(informationHeaderMetaDataMock.getTitle()).thenReturn(MULTIPART_VALUE);
    when(informationHeaderMetaDataMock.getColumnGroup()).thenReturn(COLUMN_GROUP);
    when(propertyHeaderMetaDataMock.getMetadataType()).thenReturn(ScenarioHeaderMetaData.MetadataType.PROPERTY);
    when(propertyHeaderMetaDataMock.getTitle()).thenReturn(GRID_PROPERTY_TITLE);
    when(propertyHeaderMetaDataMock.getColumnGroup()).thenReturn(GRID_COLUMN_GROUP);
    when(propertyHeaderMetaDataMock.getColumnId()).thenReturn(GRID_COLUMN_ID);
    when(headerMetaDatasMock.get(anyInt())).thenReturn(informationHeaderMetaDataMock);
    when(gridColumnMock.getHeaderMetaData()).thenReturn(headerMetaDatasMock);
    when(gridColumnMock.getInformationHeaderMetaData()).thenReturn(informationHeaderMetaDataMock);
    when(gridColumnMock.getPropertyHeaderMetaData()).thenReturn(propertyHeaderMetaDataMock);
    when(gridColumnMock.getFactIdentifier()).thenReturn(factIdentifierMock);
    settingsLocal.setType(ScenarioSimulationModel.Type.RULE);
    IntStream.range(0, COLUMN_NUMBER).forEach(columnIndex -> {
        gridColumns.add(gridColumnMock);
        factMappingValuesLocal.add(factMappingValueMock);
        factIdentifierSet.add(factIdentifierMock);
        factMappingLocal.add(factMappingMock);
        when(simulationDescriptorMock.getFactMappingByIndex(columnIndex)).thenReturn(factMappingMock);
    });
    when(factIdentifierMock.getClassNameWithoutPackage()).thenReturn(CLASS_NAME);
    when(factIdentifierMock.getPackageWithoutClassName()).thenReturn(FULL_PACKAGE);
    when(factIdentifierMock.getClassName()).thenReturn(FULL_CLASS_NAME);
    when(factIdentifierMock.getName()).thenReturn(FACT_IDENTIFIER_NAME);
    when(simulationDescriptorMock.getFactIdentifiers()).thenReturn(factIdentifierSet);
    when(simulationDescriptorMock.getUnmodifiableFactMappings()).thenReturn(factMappingLocal);
    when(simulationDescriptorMock.getFactMappingsByFactName(anyString())).thenReturn(Stream.empty());
    when(scenarioGridModelMock.nextColumnCount()).thenReturn(factMappingValuesLocal.size());
    when(factMappingMock.getFactIdentifier()).thenReturn(factIdentifierMock);
    when(factMappingMock.getFactAlias()).thenReturn(FACT_ALIAS);
    when(factMappingMock.getGenericTypes()).thenReturn(new ArrayList<>());
    doReturn(factMappingMock).when(simulationDescriptorMock).addFactMapping(anyInt(), anyString(), anyObject(), anyObject());
    when(scenarioSimulationViewMock.getScenarioGridWidget()).thenReturn(scenarioGridWidgetSpy);
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) AppendRowCommand(org.drools.workbench.screens.scenariosimulation.client.commands.actualcommands.AppendRowCommand) Background(org.drools.scenariosimulation.api.model.Background) Matchers.anyString(org.mockito.Matchers.anyString) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) Scenario(org.drools.scenariosimulation.api.model.Scenario) ScenarioCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioCellTextAreaSingletonDOMElementFactory) ScenarioGridWidget(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridWidget) ScenarioExpressionCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioExpressionCellTextAreaSingletonDOMElementFactory) Point2D(com.ait.lienzo.client.core.types.Point2D) ScenarioGridModel(org.drools.workbench.screens.scenariosimulation.client.models.ScenarioGridModel) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioSimulationViolation(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationViolation) ScenarioHeaderTextBoxSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioHeaderTextBoxSingletonDOMElementFactory) Settings(org.drools.scenariosimulation.api.model.Settings) CollectionEditorSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.CollectionEditorSingletonDOMElementFactory) Before(org.junit.Before)

Example 2 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext in project drools-wb by kiegroup.

the class AbstractDMODataManagementStrategyTest method setup.

@Before
public void setup() {
    super.setup();
    factTypes = new ArrayList<>();
    visibleFactsLocal = new TreeMap<>();
    hiddenFactsLocal = new TreeMap<>();
    factModelTupleLocal = new FactModelTuple(visibleFactsLocal, hiddenFactsLocal);
    factModelTreeHolderlocal = new AbstractDataManagementStrategy.ResultHolder();
    factModelTreeHolderlocal.setFactModelTuple(factModelTupleLocal);
    abstractDMODataManagementStrategySpy = spy(new AbstractDMODataManagementStrategy() {

        @Override
        public void manageScenarioSimulationModelContent(ObservablePath currentPath, ScenarioSimulationModelContent toManage) {
        }

        @Override
        public boolean isADataType(String value) {
            return false;
        }

        @Override
        protected String getFQCNByFactName(String factName) {
            return FULL_CLASS_NAME;
        }

        @Override
        protected String getParametricFieldType(String factName, String propertyName) {
            return PARAMETRIC_FIELD_TYPE;
        }

        @Override
        protected List<String> getFactTypes() {
            return factTypes;
        }

        @Override
        protected void getSuperType(String factType, Callback<String> callback) {
        // Do Nothing
        }

        @Override
        protected boolean skipPopulateTestTools() {
            return false;
        }

        @Override
        protected void manageDataObjects(List<String> dataObjectsTypes, Map<String, String> superTypeMap, TestToolsView.Presenter testToolsPresenter, int expectedElements, SortedMap<String, FactModelTree> dataObjectsFieldsMap, ScenarioSimulationContext context, List<String> simpleJavaTypes, GridWidget gridWidget) {
        }

        {
            this.model = modelLocal;
            this.factModelTreeHolder = factModelTreeHolderlocal;
        }
    });
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) Callback(org.uberfire.client.callbacks.Callback) SortedMap(java.util.SortedMap) ArrayList(java.util.ArrayList) List(java.util.List) ScenarioSimulationModelContent(org.drools.workbench.screens.scenariosimulation.model.ScenarioSimulationModelContent) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) ObservablePath(org.uberfire.backend.vfs.ObservablePath) Before(org.junit.Before)

Example 3 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext 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 4 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext in project drools-wb by kiegroup.

the class ScenarioGridPanelProducer method init.

@PostConstruct
public void init() {
    scenarioSimulationContext = new ScenarioSimulationContext(simulationGridWidget, backgroundGridWidget);
    initializeGrid(simulationGridLayer, simulationGridPanel, new ScenarioGridModel(false), scenarioSimulationContext, 1, 0);
    initializeGrid(backgroundGridLayer, backgroundGridPanel, new BackgroundGridModel(false), scenarioSimulationContext, 0, 0);
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) ScenarioGridModel(org.drools.workbench.screens.scenariosimulation.client.models.ScenarioGridModel) BackgroundGridModel(org.drools.workbench.screens.scenariosimulation.client.models.BackgroundGridModel) PostConstruct(javax.annotation.PostConstruct)

Example 5 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext in project drools-wb by kiegroup.

the class ScenarioGridPanelProducerTest method init.

@Test
public void init() {
    assertNull(scenarioGridPanelProducer.scenarioSimulationContext);
    scenarioGridPanelProducer.init();
    ScenarioSimulationContext retrieved = scenarioGridPanelProducer.scenarioSimulationContext;
    assertNotNull(retrieved);
    verify(scenarioGridPanelProducer, times(1)).initializeGrid(eq(scenarioGridLayerMock), eq(scenarioGridPanelMock), isA(ScenarioGridModel.class), eq(retrieved), eq(1), eq(0));
    verify(scenarioGridPanelProducer, times(1)).initializeGrid(eq(backgroundGridLayerMock), eq(backgroundGridPanelMock), isA(BackgroundGridModel.class), eq(retrieved), eq(0), eq(0));
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) ScenarioGridModel(org.drools.workbench.screens.scenariosimulation.client.models.ScenarioGridModel) BackgroundGridModel(org.drools.workbench.screens.scenariosimulation.client.models.BackgroundGridModel) Test(org.junit.Test)

Aggregations

ScenarioSimulationContext (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext)10 FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)5 SortedMap (java.util.SortedMap)4 Set (java.util.Set)3 GridWidget (org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget)3 ScenarioGridModel (org.drools.workbench.screens.scenariosimulation.client.models.ScenarioGridModel)3 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)3 Before (org.junit.Before)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)2 Background (org.drools.scenariosimulation.api.model.Background)2 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)2 ScenarioSimulationViolation (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationViolation)2 AbstractScenarioSimulationEditorTest (org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest)2 BackgroundGridModel (org.drools.workbench.screens.scenariosimulation.client.models.BackgroundGridModel)2