Skip to content

Commit

Permalink
DROOLS-5291 & DROOLS-5223: Managing empty and invalid scesim file (ki…
Browse files Browse the repository at this point in the history
…egroup#1385)

* DROOLS-5223

* DROOLS-5223: Managing malformed SCESIM file

* DROOLS-5223: Managing malformed SCESIM file

* DROOLS-5223: Test

* DROOLS-5223: Test

* DROOLS-5223: Test

* DROOLS-5223: Test

* DROOLS-5223: Changes required during CR

* DROOLS-5223: Changes required during CR

* DROOLS-5223: Changes required during CR
  • Loading branch information
yesamer committed Jun 19, 2020
1 parent 03f9c72 commit a9542c9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
Expand Up @@ -17,7 +17,12 @@

import javax.enterprise.event.Event;

import org.drools.scenariosimulation.api.model.Background;
import org.drools.scenariosimulation.api.model.ScenarioSimulationModel;
import org.drools.scenariosimulation.api.model.Settings;
import org.drools.scenariosimulation.api.model.Simulation;
import org.drools.workbench.screens.scenariosimulation.model.ScenarioSimulationModelContent;
import org.drools.workbench.screens.scenariosimulation.service.DMNTypeService;
import org.guvnor.common.services.backend.config.SafeSessionInfo;
import org.guvnor.common.services.shared.metadata.model.Overview;
import org.junit.Before;
Expand All @@ -37,8 +42,13 @@

import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
Expand All @@ -59,29 +69,46 @@ public class ScenarioSimulationServiceImplLoadContentTest {
@Mock
private DataModelService dataModelService;

@Mock
private DMNTypeService dmnTypeServiceMock;

@InjectMocks
private ScenarioSimulationServiceImpl service = new ScenarioSimulationServiceImpl(mock(SafeSessionInfo.class));
private ScenarioSimulationServiceImpl serviceSpy = spy(new ScenarioSimulationServiceImpl(mock(SafeSessionInfo.class)) {
@Override
protected ScenarioSimulationModel unmarshalInternal(String content) {
Simulation simulation = new Simulation();
Background background = new Background();
Settings settings = new Settings();
settings.setType(ScenarioSimulationModel.Type.DMN);
ScenarioSimulationModel toReturn = new ScenarioSimulationModel();
toReturn.setSimulation(simulation);
toReturn.setBackground(background);
toReturn.setSettings(settings);
return toReturn;
}
});

private Path path = PathFactory.newPath("contextpath", "file:///contextpath");

@Before
public void setUp() throws Exception {
public void setUp() {
doReturn("").when(ioService).readAllString(any());
doReturn(false).when(pathResolver).isDotFile(any());
doReturn(mock(Overview.class)).when(overviewLoader).loadOverview(any());

doReturn(mock(PackageDataModelOracle.class)).when(dataModelService).getDataModel(path);
}

@Test
public void loadContent() throws Exception {
final ScenarioSimulationModelContent scenarioSimulationModelContent = service.loadContent(path);
public void loadContent() {
final ScenarioSimulationModelContent scenarioSimulationModelContent = serviceSpy.loadContent(path);

assertNotNull(scenarioSimulationModelContent);
assertNotNull(scenarioSimulationModelContent.getDataModel());
assertNotNull(scenarioSimulationModelContent.getModel());
assertNotNull(scenarioSimulationModelContent.getOverview());

verify(serviceSpy, times(1)).constructContent(eq(path), isA(Overview.class));
verify(dmnTypeServiceMock, times(1)).initializeNameAndNamespace(isA(Settings.class), eq(path), anyString());
verify(resourceOpenedEvent).fire(any(ResourceOpenedEvent.class));
}
}
Expand Up @@ -47,6 +47,7 @@
import org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget;
import org.drools.workbench.screens.scenariosimulation.client.handlers.AbstractScenarioSimulationDocksHandler;
import org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback;
import org.drools.workbench.screens.scenariosimulation.client.popup.CustomBusyPopup;
import org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants;
import org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenter;
import org.drools.workbench.screens.scenariosimulation.client.type.ScenarioSimulationResourceType;
Expand Down Expand Up @@ -83,12 +84,14 @@
import org.uberfire.ext.editor.commons.service.support.SupportsRename;
import org.uberfire.ext.editor.commons.service.support.SupportsSaveAndRename;
import org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback;
import org.uberfire.ext.widgets.common.client.common.BusyPopup;
import org.uberfire.lifecycle.OnClose;
import org.uberfire.lifecycle.OnMayClose;
import org.uberfire.lifecycle.OnStartup;
import org.uberfire.mvp.Command;
import org.uberfire.mvp.PlaceRequest;
import org.uberfire.mvp.impl.DefaultPlaceRequest;
import org.uberfire.workbench.events.NotificationEvent;
import org.uberfire.workbench.model.menu.Menus;

import static org.drools.workbench.screens.scenariosimulation.client.editor.ScenarioSimulationEditorPresenter.IDENTIFIER;
Expand Down Expand Up @@ -417,7 +420,19 @@ protected void addCommonActions(final FileMenuBuilder fileMenuBuilder) {
protected void loadContent() {
scenarioSimulationEditorPresenter.loadContent();
service.call(getModelSuccessCallback(),
getNoSuchFileExceptionErrorCallback()).loadContent(versionRecordManager.getCurrentPath());
getLoadContentErrorCallback()).loadContent(versionRecordManager.getCurrentPath());
}

protected ErrorCallback<Boolean> getLoadContentErrorCallback() {
return (message, exception) -> {
CustomBusyPopup.close();
BusyPopup.close();
scenarioSimulationEditorPresenter.sendNotification(ScenarioSimulationEditorConstants.INSTANCE.loadContentFailedNotification()
+ exception.getMessage(),
NotificationEvent.NotificationType.ERROR);
placeManager.forceClosePlace(place);
return false;
};
}

@Override
Expand Down
Expand Up @@ -59,7 +59,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.widgets.client.callbacks.CommandDrivenErrorCallback;
import org.kie.workbench.common.widgets.client.docks.DefaultEditorDock;
import org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants;
import org.kie.workbench.common.widgets.configresource.client.widget.bound.ImportsWidgetPresenter;
Expand Down Expand Up @@ -221,6 +220,7 @@ public void setup() {
this.saveAndRenameCommandBuilder = saveAndRenameCommandBuilderMock;
this.assetUpdateValidator = assetUpdateValidatorMock;
this.projectController = projectControllerMock;
this.place = placeRequestMock;
}
});
when(placeRequestMock.getPath()).thenReturn(observablePathMock);
Expand Down Expand Up @@ -413,10 +413,21 @@ public void addCommonActions() {
@Test
public void loadContent() {
scenarioSimulationEditorBusinessClientWrapper.loadContent();
verify(scenarioSimulationCaller, times(1)).call(isA(RemoteCallback.class), isA(CommandDrivenErrorCallback.class));
verify(scenarioSimulationCaller, times(1)).call(isA(RemoteCallback.class), isA(ErrorCallback.class));
verify(scenarioSimulationServiceMock, times(1)).loadContent(eq(observablePathMock));
}

@Test
public void getLoadContentErrorCallback() {
ErrorCallback<Boolean> errorCallback = scenarioSimulationEditorBusinessClientWrapper.getLoadContentErrorCallback();
errorCallback.error(true, new Exception("Message"));

verify(placeManagerMock, times(1)).forceClosePlace(eq(placeRequestMock));
verify(scenarioSimulationEditorPresenterMock, times(1)).sendNotification(
eq(ScenarioSimulationEditorConstants.INSTANCE.loadContentFailedNotification() + "Message"),
eq(NotificationEvent.NotificationType.ERROR));
}

@Test
public void onEditTabSelected() {
scenarioSimulationEditorBusinessClientWrapper.onEditTabSelected();
Expand Down
Expand Up @@ -370,6 +370,8 @@ public interface ScenarioSimulationEditorConstants

String validationSucceed();

String loadContentFailedNotification();

String backgroundTabTitle();

String export();
Expand Down
Expand Up @@ -198,6 +198,7 @@ validationErrorMessage=The data structure behind these columns has changed and n
validationErrorTitle=Wrong column mapping
validationFailedNotification=Impossible to validate. Please verify project build compilation errors
validationSucceed=Validation Succeed
loadContentFailedNotification=Impossible to load file. Error:

backgroundTabTitle=Background
backgroundErrorNotification=There are errors in Background data, please have a look
Expand Down

0 comments on commit a9542c9

Please sign in to comment.