Search in sources :

Example 6 with CurrentUser

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);
}
Also used : CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) Matchers.anyString(org.mockito.Matchers.anyString) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.junit.Test)

Example 7 with CurrentUser

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));
}
Also used : SshKeyUploader(org.eclipse.che.plugin.ssh.key.client.SshKeyUploader) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) Matchers.anyString(org.mockito.Matchers.anyString) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.junit.Test)

Example 8 with CurrentUser

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);
    }
}
Also used : SshKeyUploader(org.eclipse.che.plugin.ssh.key.client.SshKeyUploader) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser)

Aggregations

CurrentUser (org.eclipse.che.ide.api.app.CurrentUser)8 ProfileDto (org.eclipse.che.api.user.shared.dto.ProfileDto)7 OAuthStatus (org.eclipse.che.security.oauth.OAuthStatus)7 Test (org.junit.Test)7 Matchers.anyString (org.mockito.Matchers.anyString)7 SshKeyUploader (org.eclipse.che.plugin.ssh.key.client.SshKeyUploader)5 Promise (org.eclipse.che.api.promises.client.Promise)2 MessageDialog (org.eclipse.che.ide.api.dialogs.MessageDialog)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 ArrayList (java.util.ArrayList)1 SshPairDto (org.eclipse.che.api.ssh.shared.dto.SshPairDto)1 ProjectData (org.eclipse.che.plugin.github.ide.load.ProjectData)1