Search in sources :

Example 21 with ConfirmCallback

use of org.eclipse.che.ide.api.dialogs.ConfirmCallback in project che by eclipse.

the class SshKeyManagerPresenterTest method testOnDeleteClickedWhenDeleteKeyConfirmed.

@Test
public void testOnDeleteClickedWhenDeleteKeyConfirmed() {
    when(sshPairDto.getService()).thenReturn(SshKeyManagerPresenter.VCS_SSH_SERVICE);
    when(sshPairDto.getName()).thenReturn(GITHUB_HOST);
    SafeHtml safeHtml = mock(SafeHtml.class);
    ConfirmDialog confirmDialog = mock(ConfirmDialog.class);
    when(constant.deleteSshKeyQuestion(anyString())).thenReturn(safeHtml);
    when(safeHtml.asString()).thenReturn("");
    when(dialogFactory.createConfirmDialog(anyString(), anyString(), (ConfirmCallback) anyObject(), (CancelCallback) anyObject())).thenReturn(confirmDialog);
    presenter.onDeleteClicked(sshPairDto);
    verify(dialogFactory).createConfirmDialog(anyString(), anyString(), confirmCallbackCaptor.capture(), (CancelCallback) anyObject());
    ConfirmCallback confirmCallback = confirmCallbackCaptor.getValue();
    confirmCallback.accepted();
    verify(confirmDialog).show();
    verify(service).deletePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
}
Also used : ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ConfirmDialog(org.eclipse.che.ide.api.dialogs.ConfirmDialog) Test(org.junit.Test)

Example 22 with ConfirmCallback

use of org.eclipse.che.ide.api.dialogs.ConfirmCallback in project che by eclipse.

the class SshKeyManagerPresenterTest method testShouldRefreshKeysAfterSuccessfulDeleteKey.

@Test
public void testShouldRefreshKeysAfterSuccessfulDeleteKey() throws OperationException {
    when(sshPairDto.getService()).thenReturn(SshKeyManagerPresenter.VCS_SSH_SERVICE);
    when(sshPairDto.getName()).thenReturn(GITHUB_HOST);
    SafeHtml safeHtml = mock(SafeHtml.class);
    ConfirmDialog confirmDialog = mock(ConfirmDialog.class);
    List<SshPairDto> sshPairDtoArray = new ArrayList<>();
    when(constant.deleteSshKeyQuestion(anyString())).thenReturn(safeHtml);
    when(safeHtml.asString()).thenReturn("");
    when(dialogFactory.createConfirmDialog(anyString(), anyString(), (ConfirmCallback) anyObject(), (CancelCallback) anyObject())).thenReturn(confirmDialog);
    presenter.onDeleteClicked(sshPairDto);
    verify(dialogFactory).createConfirmDialog(anyString(), anyString(), confirmCallbackCaptor.capture(), (CancelCallback) anyObject());
    ConfirmCallback confirmCallback = confirmCallbackCaptor.getValue();
    confirmCallback.accepted();
    verify(voidPromise).then(operationVoidCapture.capture());
    operationVoidCapture.getValue().apply(null);
    verify(sshPairDTOsPromise).then(operationSshPairDTOsCapture.capture());
    operationSshPairDTOsCapture.getValue().apply(sshPairDtoArray);
    verify(confirmDialog).show();
    verify(service).deletePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
    verify(service).getPairs(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE));
    verify(view).setPairs(eq(sshPairDtoArray));
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ArrayList(java.util.ArrayList) ConfirmDialog(org.eclipse.che.ide.api.dialogs.ConfirmDialog) Test(org.junit.Test)

Example 23 with ConfirmCallback

use of org.eclipse.che.ide.api.dialogs.ConfirmCallback in project che by eclipse.

the class SshKeyManagerPresenterTest method testOnDeleteClickedWhenDeleteKeyIsFailure.

@Test
public void testOnDeleteClickedWhenDeleteKeyIsFailure() throws OperationException {
    when(sshPairDto.getService()).thenReturn(SshKeyManagerPresenter.VCS_SSH_SERVICE);
    when(sshPairDto.getName()).thenReturn(GITHUB_HOST);
    SafeHtml safeHtml = mock(SafeHtml.class);
    ConfirmDialog confirmDialog = mock(ConfirmDialog.class);
    when(constant.deleteSshKeyQuestion(anyString())).thenReturn(safeHtml);
    when(safeHtml.asString()).thenReturn("");
    when(dialogFactory.createConfirmDialog(anyString(), anyString(), (ConfirmCallback) anyObject(), (CancelCallback) anyObject())).thenReturn(confirmDialog);
    presenter.onDeleteClicked(sshPairDto);
    verify(dialogFactory).createConfirmDialog(anyString(), anyString(), confirmCallbackCaptor.capture(), (CancelCallback) anyObject());
    ConfirmCallback confirmCallback = confirmCallbackCaptor.getValue();
    confirmCallback.accepted();
    verify(voidPromise).catchError(operationErrorCapture.capture());
    operationErrorCapture.getValue().apply(JsPromiseError.create(""));
    verify(confirmDialog).show();
    verify(service).deletePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), anyString());
    verify(notificationManager).notify(anyString(), eq(StatusNotification.Status.FAIL), eq(FLOAT_MODE));
    verify(service, never()).getPairs(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE));
}
Also used : ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ConfirmDialog(org.eclipse.che.ide.api.dialogs.ConfirmDialog) Test(org.junit.Test)

Aggregations

ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)23 OperationException (org.eclipse.che.api.promises.client.OperationException)9 ConfirmDialog (org.eclipse.che.ide.api.dialogs.ConfirmDialog)8 Operation (org.eclipse.che.api.promises.client.Operation)7 PromiseError (org.eclipse.che.api.promises.client.PromiseError)6 Test (org.junit.Test)6 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)5 Resource (org.eclipse.che.ide.api.resources.Resource)5 CancelCallback (org.eclipse.che.ide.api.dialogs.CancelCallback)4 ChoiceDialog (org.eclipse.che.ide.api.dialogs.ChoiceDialog)4 Promise (org.eclipse.che.api.promises.client.Promise)3 CommandImpl (org.eclipse.che.ide.api.command.CommandImpl)3 InputCallback (org.eclipse.che.ide.api.dialogs.InputCallback)3 Project (org.eclipse.che.ide.api.resources.Project)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 ArrayList (java.util.ArrayList)2 Function (org.eclipse.che.api.promises.client.Function)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2 RequestCall (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.RequestCall)2 SshPairDto (org.eclipse.che.api.ssh.shared.dto.SshPairDto)2