Skip to content

Commit

Permalink
Improve DMN path management on Legacy SceSim Editor (apache#2117)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesamer authored Jan 12, 2024
1 parent 411430b commit 723fe3d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,12 @@ public void onClose() {
scenarioBackgroundGridWidget.unregister();
}

public void showDocks() {
public void initializeDocks() {
abstractScenarioSimulationDocksHandler.addDocks();
abstractScenarioSimulationDocksHandler.setScesimEditorId(String.valueOf(scenarioPresenterId));
expandToolsDock();
registerTestToolsCallback();
resetDocks();
populateRightDocks(TestToolsPresenter.IDENTIFIER);
}

public void hideDocks() {
Expand Down Expand Up @@ -519,6 +518,7 @@ public void getModelSuccessCallbackMethod(DataManagementStrategy dataManagementS
scenarioMainGridWidget.setContent(model.getSimulation(), model.getSettings().getType());
scenarioBackgroundGridWidget.setContent(model.getBackground(), model.getSettings().getType());
// NOTE: keep here initialization of docks related with model
initializeDocks();
populateRightDocks(TestToolsPresenter.IDENTIFIER);
populateRightDocks(SettingsPresenter.IDENTIFIER);
CustomBusyPopup.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ settings=Settings
name=Name
type=Type
dmnPathErrorLabel=Impossible to find ''{0}'' file. Please select one.
dmnPathErrorDetailedLabel=Referred DMN file ''{0}'' is invalid or not present. Please provide a valid DMN file and update Settings dock in the right. Message: ''{1}''
dmnPathErrorDetailedLabel=ACTION REQUIRED: Referred DMN file ''{0}'' is no longer valid. Please provide a valid DMN file and update the DMN model in the Settings dock. Message: ''{1}''
missingSelectedType=Missing selected type
missingDmnPath=Missing DMN path
coverageReport=Coverage Report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,22 @@ public void onClose() {
}

@Test
public void showDocks_PlaceStatusOpen() {
presenterSpy.showDocks();
public void initializeDocks_PlaceStatusOpen() {
presenterSpy.initializeDocks();
verify(abstractScenarioSimulationDocksHandlerMock, times(1)).addDocks();
verify(abstractScenarioSimulationDocksHandlerMock, times(1)).setScesimEditorId(String.valueOf(presenterSpy.scenarioPresenterId));
verify(presenterSpy, times(1)).registerTestToolsCallback();
verify(presenterSpy, times(1)).resetDocks();
verify(presenterSpy, times(1)).populateRightDocks(TestToolsPresenter.IDENTIFIER);
}

@Test
public void showDocks_PlaceStatusClose() {
presenterSpy.showDocks();
public void initializeDocks_PlaceStatusClose() {
presenterSpy.initializeDocks();
verify(abstractScenarioSimulationDocksHandlerMock, times(1)).addDocks();
verify(abstractScenarioSimulationDocksHandlerMock, times(1)).setScesimEditorId(String.valueOf(presenterSpy.scenarioPresenterId));
verify(presenterSpy, times(1)).expandToolsDock();
verify(presenterSpy, times(1)).registerTestToolsCallback();
verify(presenterSpy, times(1)).resetDocks();
verify(presenterSpy, times(1)).populateRightDocks(TestToolsPresenter.IDENTIFIER);
}

@Test
Expand Down Expand Up @@ -536,6 +534,7 @@ public void populateRightDocksEmptyDataStrategy() {
public void getModelSuccessCallbackMethod() {
scenarioGridWidgetSpy.selectAndFocus();
presenterSpy.getModelSuccessCallbackMethod(dataManagementStrategyMock, modelLocal);
verify(presenterSpy, times(1)).initializeDocks();
verify(presenterSpy, times(1)).populateRightDocks(TestToolsPresenter.IDENTIFIER);
verify(presenterSpy, times(1)).populateRightDocks(SettingsPresenter.IDENTIFIER);
verify(scenarioGridWidgetSpy, times(1)).setContent(modelLocal.getSimulation(), settingsLocal.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ private void setErrorPage(final String errorMessage) {

private void ensureScenarioGridIsSet() {
scenarioSimulationEditorPresenter.getView().setScenarioGridWidgetAsContent();
scenarioSimulationEditorPresenter.showDocks();
scenarioSimulationEditorPresenter.getView().setScenarioTabBarVisibility(true);
}

Expand Down Expand Up @@ -418,9 +417,9 @@ protected void onModelSuccessCallbackMethod(ScenarioSimulationModel model) {
false);
dataManagementStrategy = new KogitoDMODataManagementStrategy(kogitoOracle);
} else {
dataManagementStrategy = new KogitoDMNDataManagementStrategy(scenarioSimulationEditorPresenter.getEventBus(),
dmnDataManager,
scenarioSimulationKogitoDMNMarshallerService);
dataManagementStrategy = new KogitoDMNDataManagementStrategy(dmnDataManager,
scenarioSimulationKogitoDMNMarshallerService,
scenarioSimulationEditorPresenter);
}
dataManagementStrategy.setModel(model);
scenarioSimulationEditorPresenter.getModelSuccessCallbackMethod(dataManagementStrategy, model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

package org.drools.workbench.screens.scenariosimulation.kogito.client.editor.strategies;

import com.google.gwt.event.shared.EventBus;
import org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext;
import org.drools.workbench.screens.scenariosimulation.client.editor.ScenarioSimulationEditorPresenter;
import org.drools.workbench.screens.scenariosimulation.client.editor.strategies.AbstractDMNDataManagementStrategy;
import org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget;
import org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent;
import org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants;
import org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsView;
import org.drools.workbench.screens.scenariosimulation.kogito.client.dmn.ScenarioSimulationKogitoDMNDataManager;
Expand All @@ -38,15 +37,18 @@

public class KogitoDMNDataManagementStrategy extends AbstractDMNDataManagementStrategy {

private ScenarioSimulationKogitoDMNDataManager dmnDataManager;
private ScenarioSimulationKogitoDMNMarshallerService dmnMarshallerService;
private final ScenarioSimulationKogitoDMNDataManager dmnDataManager;
private final ScenarioSimulationKogitoDMNMarshallerService dmnMarshallerService;
private final ScenarioSimulationEditorPresenter scenarioSimulationEditorPresenter;

public KogitoDMNDataManagementStrategy(EventBus eventBus,
ScenarioSimulationKogitoDMNDataManager dmnDataManager,
ScenarioSimulationKogitoDMNMarshallerService dmnMarshallerService) {
super(eventBus);

public KogitoDMNDataManagementStrategy(ScenarioSimulationKogitoDMNDataManager dmnDataManager,
ScenarioSimulationKogitoDMNMarshallerService scenarioSimulationKogitoDMNMarshallerService,
ScenarioSimulationEditorPresenter scenarioSimulationEditorPresenter) {
super(scenarioSimulationEditorPresenter.getEventBus());
this.dmnDataManager = dmnDataManager;
this.dmnMarshallerService = dmnMarshallerService;
this.dmnMarshallerService = scenarioSimulationKogitoDMNMarshallerService;
this.scenarioSimulationEditorPresenter = scenarioSimulationEditorPresenter;
}

@Override
Expand All @@ -71,10 +73,11 @@ private Callback<KogitoDMNModel> getDMNContentCallback(final TestToolsView.Prese

private ErrorCallback<Object> getDMNContentErrorCallback(String dmnFilePath) {
return (message, throwable) -> {
eventBus.fireEvent(new ScenarioNotificationEvent(ScenarioSimulationEditorConstants.INSTANCE.dmnPathErrorDetailedLabel(dmnFilePath,
message.toString()),
NotificationEvent.NotificationType.ERROR,
false));
scenarioSimulationEditorPresenter.sendNotification(
ScenarioSimulationEditorConstants.INSTANCE.dmnPathErrorDetailedLabel(dmnFilePath, message.toString()),
NotificationEvent.NotificationType.ERROR,
false);
scenarioSimulationEditorPresenter.expandSettingsDock();
return false;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ public void getModelSuccessCallbackMethodRule() {
verify(scenarioSimulationEditorPresenterMock, times(1)).getModelSuccessCallbackMethod(dataManagementStrategyCaptor.capture(), eq(scenarioSimulationModelMock));
assertTrue(dataManagementStrategyCaptor.getValue() instanceof KogitoDMODataManagementStrategy);
verify(scenarioSimulationViewMock, times(1)).setScenarioGridWidgetAsContent();
verify(scenarioSimulationEditorPresenterMock, times(1)).showDocks();
verify(scenarioSimulationViewMock, times(1)).setScenarioTabBarVisibility(true);
}

Expand All @@ -362,7 +361,6 @@ public void getModelSuccessCallbackMethodDMN() {
verify(scenarioSimulationEditorPresenterMock, times(1)).getModelSuccessCallbackMethod(dataManagementStrategyCaptor.capture(), eq(scenarioSimulationModelMock));
assertTrue(dataManagementStrategyCaptor.getValue() instanceof KogitoDMNDataManagementStrategy);
verify(scenarioSimulationViewMock, times(1)).setScenarioGridWidgetAsContent();
verify(scenarioSimulationEditorPresenterMock, times(1)).showDocks();
verify(scenarioSimulationViewMock, times(1)).setScenarioTabBarVisibility(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import com.google.gwt.event.shared.EventBus;
import com.google.gwtmockito.GwtMockitoTestRunner;
import org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext;
import org.drools.workbench.screens.scenariosimulation.client.editor.ScenarioSimulationEditorPresenter;
import org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget;
import org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent;
import org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenter;
import org.drools.workbench.screens.scenariosimulation.kogito.client.dmn.ScenarioSimulationKogitoDMNDataManager;
import org.drools.workbench.screens.scenariosimulation.kogito.client.dmn.model.KogitoDMNModel;
Expand All @@ -46,8 +46,7 @@
import org.uberfire.client.callbacks.Callback;
import org.uberfire.workbench.events.NotificationEvent;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
Expand All @@ -60,6 +59,8 @@ public class KogitoDMNDataManagementStrategyTest {
@Mock
private EventBus eventBusMock;
@Mock
private ScenarioSimulationEditorPresenter scenarioSimulationEditorPresenterMock;
@Mock
private ScenarioSimulationKogitoDMNDataManager kogitoDMNDataManagerMock;
@Mock
private ScenarioSimulationKogitoDMNMarshallerService dmnMarshallerServiceMock;
Expand All @@ -79,22 +80,21 @@ public class KogitoDMNDataManagementStrategyTest {
private ArgumentCaptor<Callback<KogitoDMNModel>> callbackArgumentCaptor;
@Captor
private ArgumentCaptor<ErrorCallback<Object>> errorCallbackArgumentCaptor;
@Captor
private ArgumentCaptor<ScenarioNotificationEvent> scenarioNotificationEventArgumentCaptor;

private KogitoDMNModel kogitoDMNModel;
private KogitoDMNDataManagementStrategy kogitoDMNDataManagementStrategySpy;

@Before
public void setup() {
kogitoDMNModel = new KogitoDMNModel(jsitDefinitionsMock, Collections.emptyMap());
kogitoDMNDataManagementStrategySpy = spy(new KogitoDMNDataManagementStrategy(eventBusMock, kogitoDMNDataManagerMock, dmnMarshallerServiceMock) {
kogitoDMNDataManagementStrategySpy = spy(new KogitoDMNDataManagementStrategy(kogitoDMNDataManagerMock, dmnMarshallerServiceMock, scenarioSimulationEditorPresenterMock) {
{
this.dmnFilePath = "path/dmnFile.dmn";
}
});
when(kogitoDMNDataManagementStrategySpy.getSuccessCallback(testToolsPresenterMock, scenarioSimulationContextMock, gridWidgetMock)).thenReturn(factModelTupleRemoteCallbackMock);
when(kogitoDMNDataManagerMock.getFactModelTuple(kogitoDMNModel)).thenReturn(factModelTupleMock);
when(scenarioSimulationEditorPresenterMock.getEventBus()).thenReturn(eventBusMock);
}

@Test
Expand All @@ -109,9 +109,8 @@ public void retrieveFactModelTuple() {
verify(factModelTupleRemoteCallbackMock, times(1)).callback(factModelTupleMock);

errorCallbackArgumentCaptor.getValue().error("Error Message", new Exception());
verify(eventBusMock, times(1)).fireEvent(scenarioNotificationEventArgumentCaptor.capture());
assertEquals(NotificationEvent.NotificationType.ERROR, scenarioNotificationEventArgumentCaptor.getValue().getNotificationType());
assertTrue(scenarioNotificationEventArgumentCaptor.getValue().getMessage().contains("Error Message"));
verify(scenarioSimulationEditorPresenterMock, times(1)).sendNotification(anyString(), eq(NotificationEvent.NotificationType.ERROR), eq(false));
verify(scenarioSimulationEditorPresenterMock, times(1)).expandSettingsDock();
}

}

0 comments on commit 723fe3d

Please sign in to comment.