Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.7.x] AF-1119: "Are you sure you want to discard unsaved data?" Displayed #280

Merged
merged 1 commit into from Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -146,9 +146,11 @@ public DataSetDef getDataSetDef() {
public boolean mayClose() {
try {
// Flush the current workflow state
currentWorkflow.flush();
if (currentWorkflow != null) {
currentWorkflow.flush();
}
} catch (Exception e) {
// Ignore. The provider type selection workflow stage thorws an error
// Ignore. The provider type selection workflow stage throws an error
// due to the dataset def being in partial creation state.
}
Integer currentHash = getCurrentModelHash();
Expand Down Expand Up @@ -276,6 +278,7 @@ void onSave(final DataSetDef dataSetDef,
public void callback(Path path) {
disposeCurrentWorkflow();
BusyPopup.close();
setOriginalHash(0);
notification.fire(new NotificationEvent(DataSetAuthoringConstants.INSTANCE.savedOk()));
placeManager.closePlace(placeRequest);
}
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.dashbuilder.dataset.client.editor.SQLDataSetDefEditor;
import org.dashbuilder.dataset.def.DataColumnDef;
import org.dashbuilder.dataset.def.DataSetDef;
import org.dashbuilder.dataset.def.DataSetDefFactory;
import org.dashbuilder.dataset.def.SQLDataSetDef;
import org.dashbuilder.dataset.service.DataSetDefVfsServices;
import org.jboss.errai.common.client.api.Caller;
Expand All @@ -46,6 +47,7 @@
import java.util.List;

import static org.jgroups.util.Util.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -73,8 +75,8 @@ public class DataSetDefWizardScreenTest {

@Before
public void setup() throws Exception {
services = new CallerMock<DataSetDefVfsServices>( dataSetDefVfsServices );
services = new CallerMock<>( dataSetDefVfsServices );

when(dataSetDef.getUUID()).thenReturn("uuid1");
when(dataSetDef.getName()).thenReturn("name1");
when(dataSetDef.getProvider()).thenReturn(DataSetProviderType.SQL);
Expand All @@ -88,7 +90,7 @@ public void setup() throws Exception {
callback.callback(dataSetDef);
return null;
}).when(clientServices).newDataSet(any(DataSetProviderType.class), any(RemoteCallback.class));

doAnswer(invocationOnMock -> {
presenter.onClose();
return null;
Expand Down Expand Up @@ -225,17 +227,22 @@ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
@Test
public void testOnSave() {
final Path path = mock(Path.class);
DataSetDef dataSetDef = DataSetDefFactory.newBeanDataSetDef().buildDef();
PlaceRequest placeRequest = mock(PlaceRequest.class);
when(dataSetDefVfsServices.save(any(DataSetDef.class), anyString())).thenReturn(path);
presenter.currentWorkflow = editWorkflow;
when(dataSetProviderTypeWorkflow.getDataSetDef()).thenReturn(dataSetDef);

presenter.init(placeRequest);
presenter.onSave(dataSetDef, "saveMessage");
verify(placeManager, times(1)).goTo("DataSetAuthoringHome");
verify(notification, times(1)).fire(any(NotificationEvent.class));
verify(placeManager, times(1)).closePlace(any(PlaceRequest.class));
verify(workflowFactory).dispose(editWorkflow);
verify(workflowFactory, times(0)).providerType();
verify(workflowFactory).dispose(dataSetProviderTypeWorkflow);
verify(workflowFactory, times(0)).edit(any(DataSetProviderType.class));
verify(workflowFactory, times(0)).basicAttributes(any(DataSetProviderType.class));

assertNull("current workflow null", presenter.currentWorkflow);
assertFalse(presenter.isDirty(presenter.getCurrentModelHash()));
assertTrue(presenter.mayClose());
}

@Test
Expand Down