Search in sources :

Example 6 with SshPairDto

use of org.eclipse.che.api.ssh.shared.dto.SshPairDto in project che by eclipse.

the class HttpSshServiceClientTest method shouldMakeCreatePairRequest.

@Test
public void shouldMakeCreatePairRequest() throws Exception {
    //given
    SshPairDto sshPairDto = mock(SshPairDto.class);
    //when
    client.createPair(sshPairDto);
    //then
    String url = fromUri(SSH_SERVICE_URL).path(SshService.class.getMethod("createPair", SshPairDto.class)).build().toString();
    verify(requestFactory).fromUrl(eq(url));
    verify(jsonRequest).usePostMethod();
    verify(jsonRequest).setBody(eq(sshPairDto));
    verify(jsonRequest).request();
    verify(jsonResponse).asDto(eq(SshPairDto.class));
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) SshService(org.eclipse.che.api.ssh.server.SshService) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 7 with SshPairDto

use of org.eclipse.che.api.ssh.shared.dto.SshPairDto in project che by eclipse.

the class SshKeyManagerPresenterTest method testOnGenerateClickedWhenGenerateKeyIsFailed.

@Test
public void testOnGenerateClickedWhenGenerateKeyIsFailed() throws OperationException {
    when(dialogFactory.createInputDialog(anyString(), anyString(), (InputCallback) anyObject(), (CancelCallback) anyObject())).thenReturn(inputDialog);
    presenter.onGenerateClicked();
    verify(dialogFactory).createInputDialog(anyString(), anyString(), inputCallbackCaptor.capture(), cancelCallbackCaptor.capture());
    InputCallback inputCallback = inputCallbackCaptor.getValue();
    inputCallback.accepted(GITHUB_HOST);
    verify(sshPairDTOPromise).catchError(operationErrorCapture.capture());
    operationErrorCapture.getValue().apply(JsPromiseError.create(""));
    verify(service).generatePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
    verify(service, never()).getPairs(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE));
    verify(view, never()).setPairs((List<SshPairDto>) anyObject());
    verify(notificationManager).notify(anyString(), anyString(), any(StatusNotification.Status.class), (DisplayMode) anyObject());
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) Test(org.junit.Test)

Example 8 with SshPairDto

use of org.eclipse.che.api.ssh.shared.dto.SshPairDto 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 9 with SshPairDto

use of org.eclipse.che.api.ssh.shared.dto.SshPairDto in project che by eclipse.

the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGetFailedKeyIsSuccess.

@Test
public void onAuthenticatedWhenGetFailedKeyIsSuccess() throws Exception {
    String userId = "userId";
    SshPairDto pair = mock(SshPairDto.class);
    List<SshPairDto> pairs = new ArrayList<>();
    pairs.add(pair);
    OAuthStatus authStatus = mock(OAuthStatus.class);
    SshKeyUploader keyUploader = mock(SshKeyUploader.class);
    CurrentUser user = mock(CurrentUser.class);
    ProfileDto profile = mock(ProfileDto.class);
    MessageDialog messageDialog = mock(MessageDialog.class);
    when(view.isGenerateKeysSelected()).thenReturn(true);
    when(registry.getUploader(GITHUB_HOST)).thenReturn(keyUploader);
    when(appContext.getCurrentUser()).thenReturn(user);
    when(user.getProfile()).thenReturn(profile);
    when(profile.getUserId()).thenReturn(userId);
    when(dialogFactory.createMessageDialog(anyString(), anyString(), Matchers.<ConfirmCallback>anyObject())).thenReturn(messageDialog);
    when(pair.getName()).thenReturn(GITHUB_HOST);
    when(pair.getService()).thenReturn(SshKeyManagerPresenter.VCS_SSH_SERVICE);
    gitHubAuthenticator.authenticate(null, getCallBack());
    gitHubAuthenticator.onAuthenticated(authStatus);
    verify(keyUploader).uploadKey(eq(userId), generateKeyCallbackCaptor.capture());
    AsyncCallback<Void> generateKeyCallback = generateKeyCallbackCaptor.getValue();
    generateKeyCallback.onFailure(new Exception(""));
    verify(sshPairDTOsPromise).then(operationSshPairDTOsCapture.capture());
    operationSshPairDTOsCapture.getValue().apply(pairs);
    verify(view).isGenerateKeysSelected();
    verify(registry).getUploader(eq(GITHUB_HOST));
    verify(appContext).getCurrentUser();
    verify(dialogFactory).createMessageDialog(anyString(), anyString(), Matchers.<ConfirmCallback>anyObject());
    verify(messageDialog).show();
    verify(sshServiceClient).getPairs(eq(SshKeyManagerPresenter.VCS_SSH_SERVICE));
    verify(sshServiceClient).deletePair(eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) SshKeyUploader(org.eclipse.che.plugin.ssh.key.client.SshKeyUploader) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) MessageDialog(org.eclipse.che.ide.api.dialogs.MessageDialog) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.junit.Test)

Aggregations

SshPairDto (org.eclipse.che.api.ssh.shared.dto.SshPairDto)9 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 ButtonCell (com.google.gwt.cell.client.ButtonCell)2 Context (com.google.gwt.cell.client.Cell.Context)2 TextCell (com.google.gwt.cell.client.TextCell)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)2 Column (com.google.gwt.user.cellview.client.Column)2 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)2 ConfirmDialog (org.eclipse.che.ide.api.dialogs.ConfirmDialog)2 InputCallback (org.eclipse.che.ide.api.dialogs.InputCallback)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Machine (org.eclipse.che.api.core.model.machine.Machine)1 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 SshService (org.eclipse.che.api.ssh.server.SshService)1 ProfileDto (org.eclipse.che.api.user.shared.dto.ProfileDto)1