use of org.eclipse.che.ide.api.app.CurrentUser in project che by eclipse.
the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGenerateKeysIsNotSelected.
@Test
public void onAuthenticatedWhenGenerateKeysIsNotSelected() throws Exception {
String userId = "userId";
OAuthStatus authStatus = mock(OAuthStatus.class);
CurrentUser user = mock(CurrentUser.class);
ProfileDto profile = mock(ProfileDto.class);
when(view.isGenerateKeysSelected()).thenReturn(false);
when(appContext.getCurrentUser()).thenReturn(user);
when(user.getProfile()).thenReturn(profile);
when(profile.getUserId()).thenReturn(userId);
gitHubAuthenticator.authenticate(null, getCallBack());
gitHubAuthenticator.onAuthenticated(authStatus);
verify(view).isGenerateKeysSelected();
verifyNoMoreInteractions(registry);
}
use of org.eclipse.che.ide.api.app.CurrentUser in project che by eclipse.
the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGenerateKeysIsSuccess.
@Test
public void onAuthenticatedWhenGenerateKeysIsSuccess() throws Exception {
String userId = "userId";
OAuthStatus authStatus = mock(OAuthStatus.class);
SshKeyUploader keyProvider = mock(SshKeyUploader.class);
CurrentUser user = mock(CurrentUser.class);
ProfileDto profile = mock(ProfileDto.class);
when(view.isGenerateKeysSelected()).thenReturn(true);
when(registry.getUploader(GITHUB_HOST)).thenReturn(keyProvider);
when(appContext.getCurrentUser()).thenReturn(user);
when(user.getProfile()).thenReturn(profile);
when(profile.getUserId()).thenReturn(userId);
gitHubAuthenticator.authenticate(null, getCallBack());
gitHubAuthenticator.onAuthenticated(authStatus);
verify(keyProvider).uploadKey(eq(userId), generateKeyCallbackCaptor.capture());
AsyncCallback<Void> generateKeyCallback = generateKeyCallbackCaptor.getValue();
generateKeyCallback.onSuccess(null);
verify(view).isGenerateKeysSelected();
verify(registry).getUploader(eq(GITHUB_HOST));
verify(appContext).getCurrentUser();
verify(notificationManager).notify(anyString(), eq(SUCCESS), eq(FLOAT_MODE));
}
use of org.eclipse.che.ide.api.app.CurrentUser in project che by eclipse.
the class SshKeyManagerPresenter method onGenerateGithubKeyClicked.
/** {@inheritDoc} */
@Override
public void onGenerateGithubKeyClicked() {
CurrentUser user = appContext.getCurrentUser();
final SshKeyUploader githubUploader = registry.getUploaders().get(GITHUB_HOST);
if (user != null && githubUploader != null) {
githubUploader.uploadKey(user.getProfile().getUserId(), new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
refreshKeys();
}
@Override
public void onFailure(Throwable exception) {
removeFailedKey(GITHUB_HOST);
}
});
} else {
notificationManager.notify(constant.failedToGenerateSshKey(), constant.sshKeysProviderNotFound(GITHUB_HOST), FAIL, FLOAT_MODE);
}
}
Aggregations