ScenarioSimulationEditorPresenter { protected void refreshModelContent(SimulationRunResult newData) { view.hideBusyIndicator(); if (this.model == null) { return; } Simulation simulation = this.model.getSimulation(); for (ScenarioWithIndex scenarioWithIndex : newData.getScenarioWithIndex()) { int index = scenarioWithIndex.getIndex() - 1; simulation.replaceData(index, scenarioWithIndex.getScesimData()); } scenarioMainGridWidget.refreshContent(simulation); context.getStatus().setSimulation(simulation); boolean hasBackgroundError = false; Background background = this.model.getBackground(); for (BackgroundDataWithIndex backgroundDataWithIndex : newData.getBackgroundDataWithIndex()) { int index = backgroundDataWithIndex.getIndex() - 1; BackgroundData scesimData = backgroundDataWithIndex.getScesimData(); background.replaceData(index, scesimData); hasBackgroundError |= scesimData.getUnmodifiableFactMappingValues().stream().anyMatch(elem -> !FactMappingValueStatus.SUCCESS.equals(elem.getStatus())); } scenarioBackgroundGridWidget.refreshContent(background); context.getStatus().setBackground(background); if (hasBackgroundError) { sendNotification(ScenarioSimulationEditorConstants.INSTANCE.backgroundErrorNotification(), NotificationEvent.NotificationType.ERROR); selectBackgroundTab(); } dataManagementStrategy.setModel(model); abstractScenarioSimulationDocksHandler.expandTestResultsDock(); scenarioSimulationEditorWrapper.onRefreshedModelContent(newData); } ScenarioSimulationEditorPresenter(); @Inject  ScenarioSimulationEditorPresenter(final AbstractScenarioSimulationProducer abstractScenarioSimulationProducer,
                                             final ScenarioSimulationResourceType type,
                                             final PlaceManager placeManager,
                                             final AbstractScenarioSimulationDocksHandler abstractScenarioSimulationDocksHandler,
                                             final TextFileExport textFileExport,
                                             final ConfirmPopupPresenter confirmPopupPresenter); void setWrapper(ScenarioSimulationEditorWrapper scenarioSimulationEditorWrapper); void setPath(ObservablePath path); ObservablePath getPath(); void setPackageName(String packageName); void onClose(); void showDocks(PlaceStatus status); void hideDocks(); void onUberfireDocksInteractionEvent(@Observes final UberfireDocksInteractionEvent uberfireDocksInteractionEvent); void expandToolsDock(); ScenarioSimulationView getView(); ScenarioSimulationModel getModel(); Command getPopulateTestToolsCommand(); void reloadTestTools(boolean disable); void onRunScenario(); void onRunScenario(List<Integer> indexOfScenarioToRun); void onUndo(); void onRedo(); void setUndoButtonEnabledStatus(boolean enabled); void setRedoButtonEnabledStatus(boolean enabled); void setItemMenuEnabled(boolean enabled); void addDownloadMenuItem(FileMenuBuilder fileMenuBuilder, Supplier<Path> pathSupplier); DataManagementStrategy getDataManagementStrategy(); void onImport(String fileContents, GridWidget gridWidget); EventBus getEventBus(); ScenarioSimulationContext getContext(); void sendNotification(String text, NotificationEvent.NotificationType type); void sendNotification(String text, NotificationEvent.NotificationType type, boolean autoHide); void makeMenuBar(FileMenuBuilder fileMenuBuilder); void addCommonActions(final FileMenuBuilder fileMenuBuilder, MenuItem versionMenuItem, MenuItem alertsButtonMenuItem); void loadContent(); boolean isDirty(); void onEditTabSelected(); void onBackgroundTabSelected(); void onOverviewSelected(); void onImportsTabSelected(); void validateSimulation(); void selectSimulationTab(); void selectBackgroundTab(); RemoteCallback<String> getExportCallBack(); ErrorCallback<Boolean> getValidationFailedCallback(); void populateRightDocks(String identifier); void getModelSuccessCallbackMethod(DataManagementStrategy dataManagementStrategy, ScenarioSimulationModel model); ScenarioSimulationResourceType getType(); void setTestTools(TestToolsView.Presenter presenter); void setCheatSheet(CheatSheetView.Presenter presenter); void setSettings(SettingsView.Presenter presenter); String getJsonModel(ScenarioSimulationModel model); static final String IDENTIFIER; }
@Test public void refreshModelContent() { when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationMock); List<ScenarioWithIndex> scenarioWithIndex = new ArrayList<>(); int scenarioNumber = 1; int scenarioIndex = scenarioNumber - 1; Scenario scenario = mock(Scenario.class); scenarioWithIndex.add(new ScenarioWithIndex(scenarioNumber, scenario)); List<BackgroundDataWithIndex> backgroundDataWithIndex = new ArrayList<>(); BackgroundData backgroundData = mock(BackgroundData.class); backgroundDataWithIndex.add(new BackgroundDataWithIndex(scenarioNumber, backgroundData)); TestResultMessage testResultMessage = mock(TestResultMessage.class); SimulationRunResult testRunResult = new SimulationRunResult(scenarioWithIndex, backgroundDataWithIndex, new SimulationRunMetadata(), testResultMessage); presenterSpy.refreshModelContent(testRunResult); verify(scenarioSimulationViewMock, times(1)).hideBusyIndicator(); verify(simulationMock, times(1)).replaceData(eq(scenarioIndex), eq(scenario)); assertEquals(scenarioSimulationModelMock, presenterSpy.getModel()); verify(scenarioGridWidgetSpy, times(1)).refreshContent(eq(simulationMock)); assertEquals(scenarioSimulationContextLocal.getStatus().getSimulation(), simulationMock); verify(backgroundMock, times(1)).replaceData(eq(scenarioIndex), eq(backgroundData)); verify(backgroundGridWidgetSpy, times(1)).refreshContent(eq(backgroundMock)); assertEquals(scenarioSimulationContextLocal.getStatus().getBackground(), backgroundMock); assertEquals(scenarioSimulationModelMock, presenterSpy.getModel()); verify(abstractScenarioSimulationDocksHandlerMock, times(1)).expandTestResultsDock(); verify(dataManagementStrategyMock, times(1)).setModel(eq(scenarioSimulationModelMock)); verify(scenarioSimulationEditorWrapperMock, times(1)).onRefreshedModelContent(eq(testRunResult)); }