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));
}
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());
}
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));
}
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));
}
Aggregations