Search in sources :

Example 1 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGenerateKeysIsFailure.

@Test
public void onAuthenticatedWhenGenerateKeysIsFailure() 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);
    MessageDialog messageDialog = mock(MessageDialog.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);
    when(dialogFactory.createMessageDialog(anyString(), anyString(), Matchers.<ConfirmCallback>anyObject())).thenReturn(messageDialog);
    gitHubAuthenticator.authenticate(null, getCallBack());
    gitHubAuthenticator.onAuthenticated(authStatus);
    verify(keyProvider).uploadKey(eq(userId), generateKeyCallbackCaptor.capture());
    AsyncCallback<Void> generateKeyCallback = generateKeyCallbackCaptor.getValue();
    generateKeyCallback.onFailure(new Exception(""));
    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));
}
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) MessageDialog(org.eclipse.che.ide.api.dialogs.MessageDialog) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.junit.Test)

Example 2 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenAuthorizeIsSuccessful.

@Test
public void onLoadRepoClickedWhenAuthorizeIsSuccessful() throws Exception {
    doAnswer(new Answer() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            presenter.onFailRequest(promiseError);
            return null;
        }
    }).doAnswer(new Answer() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            presenter.onSuccessRequest(jsArrayMixed);
            return null;
        }
    }).when(presenter).doRequest(any(Promise.class), any(Promise.class), any(Promise.class));
    final Throwable exception = mock(UnauthorizedException.class);
    String userId = "userId";
    CurrentUser user = mock(CurrentUser.class);
    ProfileDto profile = mock(ProfileDto.class);
    doReturn(exception).when(promiseError).getCause();
    when(appContext.getCurrentUser()).thenReturn(user);
    when(user.getProfile()).thenReturn(profile);
    when(profile.getUserId()).thenReturn(userId);
    presenter.onLoadRepoClicked();
    verify(gitHubClientService).getRepositoriesList();
    verify(gitHubClientService).getUserInfo();
    verify(gitHubClientService).getOrganizations();
    verify(gitHubAuthenticator).authenticate(anyString(), asyncCallbackCaptor.capture());
    AsyncCallback<OAuthStatus> asyncCallback = asyncCallbackCaptor.getValue();
    asyncCallback.onSuccess(null);
    verify(view, times(3)).setLoaderVisibility(eq(true));
    verify(view, times(3)).setInputsEnableState(eq(false));
    verify(view, times(3)).setInputsEnableState(eq(true));
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Promise(org.eclipse.che.api.promises.client.Promise) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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 3 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenAuthorizeIsFailed.

@Test
public void onLoadRepoClickedWhenAuthorizeIsFailed() throws Exception {
    String userId = "userId";
    CurrentUser user = mock(CurrentUser.class);
    ProfileDto profile = mock(ProfileDto.class);
    when(appContext.getCurrentUser()).thenReturn(user);
    when(user.getProfile()).thenReturn(profile);
    when(profile.getUserId()).thenReturn(userId);
    final Throwable exception = mock(UnauthorizedException.class);
    doAnswer(new Answer() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            presenter.onFailRequest(promiseError);
            return null;
        }
    }).when(presenter).doRequest(any(Promise.class), any(Promise.class), any(Promise.class));
    doReturn(exception).when(promiseError).getCause();
    presenter.onLoadRepoClicked();
    verify(gitHubClientService).getRepositoriesList();
    verify(gitHubClientService).getUserInfo();
    verify(gitHubClientService).getOrganizations();
    verify(gitHubAuthenticator).authenticate(anyString(), asyncCallbackCaptor.capture());
    AsyncCallback<OAuthStatus> asyncCallback = asyncCallbackCaptor.getValue();
    asyncCallback.onFailure(exception);
    verify(view, times(2)).setLoaderVisibility(eq(true));
    verify(view, times(2)).setInputsEnableState(eq(false));
    verify(view, times(2)).setInputsEnableState(eq(true));
    verify(view, never()).setAccountNames((Set<String>) anyObject());
    verify(view, never()).showGithubPanel();
    verify(view, never()).setRepositories(Matchers.<List<ProjectData>>anyObject());
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Promise(org.eclipse.che.api.promises.client.Promise) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) ProjectData(org.eclipse.che.plugin.github.ide.load.ProjectData) Test(org.junit.Test)

Example 4 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class ProfileLinksInjectorTest method shouldInjectProfileLinks.

@Test
public void shouldInjectProfileLinks() throws Exception {
    final ProfileDto profileDto = DtoFactory.newDto(ProfileDto.class).withUserId("user123").withEmail("user@codenvy.com");
    linksInjector.injectLinks(profileDto, serviceContext);
    // [rel, method] pairs links
    final Set<Pair<String, String>> links = profileDto.getLinks().stream().map(link -> Pair.of(link.getMethod(), link.getRel())).collect(Collectors.toSet());
    final Set<Pair<String, String>> expectedLinks = new HashSet<>(asList(Pair.of("GET", Constants.LINK_REL_SELF), Pair.of("GET", Constants.LINK_REL_CURRENT_PROFILE), Pair.of("PUT", Constants.LINK_REL_PROFILE_ATTRIBUTES), Pair.of("PUT", Constants.LINK_REL_CURRENT_PROFILE_ATTRIBUTES), Pair.of("DELETE", Constants.LINK_REL_CURRENT_PROFILE_ATTRIBUTES)));
    assertEquals(links, expectedLinks, "Difference " + Sets.symmetricDifference(links, expectedLinks) + "\n");
}
Also used : InjectMocks(org.mockito.InjectMocks) Listeners(org.testng.annotations.Listeners) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ServiceContext(org.eclipse.che.api.core.rest.ServiceContext) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Mock(org.mockito.Mock) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Mockito.when(org.mockito.Mockito.when) Pair(org.eclipse.che.commons.lang.Pair) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) UriBuilderImpl(org.everrest.core.impl.uri.UriBuilderImpl) HashSet(java.util.HashSet) Arrays.asList(java.util.Arrays.asList) DtoFactory(org.eclipse.che.dto.server.DtoFactory) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Pair(org.eclipse.che.commons.lang.Pair) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class ProfileServiceTest method shouldGetProfileById.

@Test
public void shouldGetProfileById() throws Exception {
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/profile/" + SUBJECT.getUserId());
    assertEquals(response.getStatusCode(), 200);
    final ProfileDto profileDto = unwrapDto(response, ProfileDto.class);
    assertEquals(profileDto.getUserId(), SUBJECT.getUserId());
}
Also used : Response(com.jayway.restassured.response.Response) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.testng.annotations.Test)

Aggregations

ProfileDto (org.eclipse.che.api.user.shared.dto.ProfileDto)12 Test (org.junit.Test)9 CurrentUser (org.eclipse.che.ide.api.app.CurrentUser)7 OAuthStatus (org.eclipse.che.security.oauth.OAuthStatus)7 Matchers.anyString (org.mockito.Matchers.anyString)7 SshKeyUploader (org.eclipse.che.plugin.ssh.key.client.SshKeyUploader)4 Test (org.testng.annotations.Test)3 Response (com.jayway.restassured.response.Response)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 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 Sets (com.google.common.collect.Sets)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1