Search in sources :

Example 1 with ProjectData

use of org.eclipse.che.plugin.github.ide.load.ProjectData in project che by eclipse.

the class GithubImporterPageViewImpl method createRepositoriesTable.

/**
     * Creates table what contains list of available repositories.
     *
     * @param resources
     */
private void createRepositoriesTable(final Resources resources, GitHubLocalizationConstant locale) {
    repositories = new CellTable<>(15, resources);
    Column<ProjectData, ImageResource> iconColumn = new Column<ProjectData, ImageResource>(new ImageResourceCell()) {

        @Override
        public ImageResource getValue(ProjectData item) {
            return null;
        }
    };
    Column<ProjectData, SafeHtml> repositoryColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {

        @Override
        public SafeHtml getValue(final ProjectData item) {
            return SafeHtmlUtils.fromString(item.getName());
        }
    };
    Column<ProjectData, SafeHtml> descriptionColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {

        @Override
        public SafeHtml getValue(final ProjectData item) {
            return new SafeHtmlBuilder().appendHtmlConstant("<span>").appendEscaped(item.getDescription() == null ? "" : item.getDescription()).appendHtmlConstant("</span>").toSafeHtml();
        }
    };
    repositories.addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    repositories.setColumnWidth(iconColumn, 28, Style.Unit.PX);
    repositories.addColumn(repositoryColumn, locale.samplesListRepositoryColumn());
    repositories.addColumn(descriptionColumn, locale.samplesListDescriptionColumn());
    // don't show loading indicator
    repositories.setLoadingIndicator(null);
    final SingleSelectionModel<ProjectData> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            ProjectData selectedObject = selectionModel.getSelectedObject();
            delegate.onRepositorySelected(selectedObject);
        }
    });
    repositories.setSelectionModel(selectionModel);
}
Also used : SingleSelectionModel(com.google.gwt.view.client.SingleSelectionModel) SafeHtmlCell(com.google.gwt.cell.client.SafeHtmlCell) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent) ImageResource(com.google.gwt.resources.client.ImageResource) Column(com.google.gwt.user.cellview.client.Column) ImageResourceCell(com.google.gwt.cell.client.ImageResourceCell) ProjectData(org.eclipse.che.plugin.github.ide.load.ProjectData)

Example 2 with ProjectData

use of org.eclipse.che.plugin.github.ide.load.ProjectData in project che by eclipse.

the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenGetUserReposIsSuccessful.

@Test
public void onLoadRepoClickedWhenGetUserReposIsSuccessful() throws Exception {
    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));
    when(view.getAccountName()).thenReturn("AccountName");
    presenter.onLoadRepoClicked();
    verify(gitHubClientService).getRepositoriesList();
    verify(gitHubClientService).getUserInfo();
    verify(gitHubClientService).getOrganizations();
    verify(view).setLoaderVisibility(eq(true));
    verify(view).setInputsEnableState(eq(false));
    verify(view).setLoaderVisibility(eq(false));
    verify(view).setInputsEnableState(eq(true));
    verify(view).setAccountNames(Matchers.<Set>anyObject());
    verify(view, times(2)).showGithubPanel();
    verify(view).setRepositories(Matchers.<List<ProjectData>>anyObject());
    verify(view).reset();
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Promise(org.eclipse.che.api.promises.client.Promise) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProjectData(org.eclipse.che.plugin.github.ide.load.ProjectData) Test(org.junit.Test)

Example 3 with ProjectData

use of org.eclipse.che.plugin.github.ide.load.ProjectData in project che by eclipse.

the class GithubImporterPagePresenterTest method onLoadRepoClickedWhenGetUserReposIsFailed.

@Test
public void onLoadRepoClickedWhenGetUserReposIsFailed() throws Exception {
    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));
    presenter.onLoadRepoClicked();
    verify(gitHubClientService).getRepositoriesList();
    verify(gitHubClientService).getUserInfo();
    verify(gitHubClientService).getOrganizations();
    verify(view).setLoaderVisibility(eq(true));
    verify(view).setInputsEnableState(eq(false));
    verify(view).setLoaderVisibility(eq(false));
    verify(view).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) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) ProjectData(org.eclipse.che.plugin.github.ide.load.ProjectData) Test(org.junit.Test)

Example 4 with ProjectData

use of org.eclipse.che.plugin.github.ide.load.ProjectData 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 5 with ProjectData

use of org.eclipse.che.plugin.github.ide.load.ProjectData in project che by eclipse.

the class GithubImporterPagePresenter method refreshProjectList.

/**
     * Refresh project list on view.
     */
private void refreshProjectList() {
    List<ProjectData> projectsData = new ArrayList<>();
    String accountName = view.getAccountName();
    if (repositories.containsKey(accountName)) {
        List<GitHubRepository> repo = repositories.get(accountName);
        for (GitHubRepository repository : repo) {
            ProjectData projectData = new ProjectData(repository.getName(), repository.getDescription(), null, null, repository.getSshUrl(), repository.getGitUrl());
            projectsData.add(projectData);
        }
        Collections.sort(projectsData, new Comparator<ProjectData>() {

            @Override
            public int compare(ProjectData o1, ProjectData o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        view.setRepositories(projectsData);
        view.reset();
        view.showGithubPanel();
    }
}
Also used : ArrayList(java.util.ArrayList) ProjectData(org.eclipse.che.plugin.github.ide.load.ProjectData) GitHubRepository(org.eclipse.che.plugin.github.shared.GitHubRepository)

Aggregations

ProjectData (org.eclipse.che.plugin.github.ide.load.ProjectData)7 Test (org.junit.Test)4 Promise (org.eclipse.che.api.promises.client.Promise)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 ArrayList (java.util.ArrayList)2 ImageResourceCell (com.google.gwt.cell.client.ImageResourceCell)1 SafeHtmlCell (com.google.gwt.cell.client.SafeHtmlCell)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 Column (com.google.gwt.user.cellview.client.Column)1 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)1 SingleSelectionModel (com.google.gwt.view.client.SingleSelectionModel)1 ProfileDto (org.eclipse.che.api.user.shared.dto.ProfileDto)1 CurrentUser (org.eclipse.che.ide.api.app.CurrentUser)1 GitHubRepository (org.eclipse.che.plugin.github.shared.GitHubRepository)1 OAuthStatus (org.eclipse.che.security.oauth.OAuthStatus)1