Search in sources :

Example 6 with SWTBotView

use of org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView in project egit by eclipse.

the class GitRepositoriesViewBranchHandlingTest method testBranchConfiguration.

@Test
public void testBranchConfiguration() throws Exception {
    Repository repo = lookupRepository(clonedRepositoryFile);
    try (Git git = new Git(repo)) {
        git.branchCreate().setName("configTest").setStartPoint("refs/remotes/origin/master").setUpstreamMode(SetupUpstreamMode.TRACK).call();
    }
    BranchRebaseMode rebase = repo.getConfig().getEnum(BranchRebaseMode.values(), ConfigConstants.CONFIG_BRANCH_SECTION, "configTest", ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.NONE);
    assertEquals(BranchRebaseMode.NONE, rebase);
    SWTBotView view = getOrOpenView();
    SWTBotTreeItem localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
    TestUtil.expandAndWait(localItem).getNode("configTest").select();
    ContextMenuHelper.clickContextMenuSync(view.bot().tree(), myUtil.getPluginLocalizedValue("ShowIn"), "Properties");
    SWTBotView propsView = bot.viewById(IPageLayout.ID_PROP_SHEET);
    SWTBotTreeItem rootItem = propsView.bot().tree().getTreeItem(UIText.BranchPropertySource_UpstreamConfigurationCategory);
    SWTBotTreeItem rebaseItem = TestUtil.expandAndWait(rootItem).getNode(UIText.BranchPropertySource_RebaseDescriptor);
    assertEquals(UIText.BranchPropertySource_ValueNotSet, rebaseItem.cell(1));
    SWTBotTreeItem remoteItem = rootItem.getNode(UIText.BranchPropertySource_RemoteDescriptor);
    assertEquals("origin", remoteItem.cell(1));
    SWTBotTreeItem upstreamItem = rootItem.getNode(UIText.BranchPropertySource_UpstreamBranchDescriptor);
    assertEquals("refs/heads/master", upstreamItem.cell(1));
    view = getOrOpenView();
    localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
    TestUtil.expandAndWait(localItem).getNode("configTest").select();
    ContextMenuHelper.clickContextMenu(view.bot().tree(), myUtil.getPluginLocalizedValue("ConfigurBranchCommand.label"));
    SWTBotShell configureBranchDialog = bot.shell(UIText.BranchConfigurationDialog_BranchConfigurationTitle);
    assertEquals(MessageFormat.format(UIText.BranchConfigurationDialog_EditBranchConfigMessage, "configTest"), configureBranchDialog.bot().text().getText());
    assertEquals("refs/heads/master", configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchConfigurationDialog_UpstreamBranchLabel).getText());
    assertEquals("origin", configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchConfigurationDialog_RemoteLabel).getText());
    assertEquals(UIText.BranchRebaseMode_None, configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchRebaseModeCombo_RebaseModeLabel).getText());
    configureBranchDialog.bot().comboBoxWithLabel(UIText.BranchRebaseModeCombo_RebaseModeLabel).setSelection(0);
    // add a listener to wait for the configuration changed event
    final AtomicBoolean changed = new AtomicBoolean();
    ConfigChangedListener listener = new ConfigChangedListener() {

        @Override
        public void onConfigChanged(ConfigChangedEvent event) {
            changed.set(true);
        }
    };
    ListenerHandle handle = repo.getConfig().addChangeListener(listener);
    // only now click ok
    configureBranchDialog.bot().button("OK").click();
    // cleanup behind ourselves
    handle.remove();
    if (!changed.get())
        fail("We should have received a config change event");
    // Repo view updates itself after config change.
    refreshAndWait();
    rebase = repo.getConfig().getEnum(BranchRebaseMode.values(), ConfigConstants.CONFIG_BRANCH_SECTION, "configTest", ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.NONE);
    assertEquals(BranchRebaseMode.REBASE, rebase);
    localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(), clonedRepositoryFile);
    TestUtil.expandAndWait(localItem).getNode("configTest").select();
    ContextMenuHelper.clickContextMenu(view.bot().tree(), myUtil.getPluginLocalizedValue("ShowIn"), "Properties");
    propsView = bot.viewById(IPageLayout.ID_PROP_SHEET);
    rootItem = propsView.bot().tree().getTreeItem(UIText.BranchPropertySource_UpstreamConfigurationCategory);
    rebaseItem = TestUtil.expandAndWait(rootItem).getNode(UIText.BranchPropertySource_RebaseDescriptor);
    assertEquals("true", rebaseItem.cell(1));
}
Also used : BranchRebaseMode(org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConfigChangedListener(org.eclipse.jgit.events.ConfigChangedListener) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) ListenerHandle(org.eclipse.jgit.events.ListenerHandle) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) ConfigChangedEvent(org.eclipse.jgit.events.ConfigChangedEvent) Test(org.junit.Test)

Example 7 with SWTBotView

use of org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView in project egit by eclipse.

the class GitRepositoriesViewFetchAndPushTest method testPushToOrigin.

private void testPushToOrigin(boolean useRemote) throws Exception {
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(clonedRepositoryFile);
    shareProjects(clonedRepositoryFile);
    Repository repository = lookupRepository(clonedRepositoryFile);
    // add the configuration for push
    repository.getConfig().setString("remote", "origin", "push", "refs/heads/*:refs/remotes/origin/*");
    repository.getConfig().save();
    // make sure to have a "new" branch name so that the
    // dialog will return with a corresponding message
    SWTBotView repoView = getOrOpenView();
    String currentBranch = repository.getBranch();
    try (Git git = new Git(repository)) {
        git.branchRename().setOldName(currentBranch).setNewName("" + System.currentTimeMillis()).call();
    }
    Job.getJobManager().join(JobFamilies.REPO_VIEW_REFRESH, null);
    SWTBotTree tree = repoView.bot().tree();
    tree.select(0);
    selectNode(tree, useRemote, false);
    runPush(tree);
    String destinationString = clonedRepositoryFile.getParentFile().getName() + " - " + "origin";
    String dialogTitle = NLS.bind(UIText.PushResultDialog_title, destinationString);
    // first time: expect new branch
    bot.waitUntil(Conditions.shellIsActive(dialogTitle));
    SWTBotShell confirmed = bot.shell(dialogTitle);
    SWTBotTreeItem[] treeItems = confirmed.bot().tree().getAllItems();
    boolean newBranch = false;
    for (SWTBotTreeItem item : treeItems) {
        newBranch = item.getText().contains(UIText.PushResultTable_statusOkNewBranch);
        if (newBranch)
            break;
    }
    confirmed.close();
    assertTrue("New branch expected", newBranch);
    // second time: expect up to date
    selectNode(tree, useRemote, false);
    runPush(tree);
    bot.waitUntil(Conditions.shellIsActive(dialogTitle));
    confirmed = bot.shell(dialogTitle);
    treeItems = confirmed.bot().tree().getAllItems();
    boolean uptodate = false;
    for (SWTBotTreeItem item : treeItems) {
        uptodate = item.getText().contains(UIText.PushResultTable_statusUpToDate);
        if (uptodate)
            break;
    }
    confirmed.close();
    assertTrue("Up to date expected", uptodate);
    // touch and run again: expect new branch
    String objectIdBefore = repository.exactRef(repository.getFullBranch()).getLeaf().getObjectId().name();
    objectIdBefore = objectIdBefore.substring(0, 7);
    touchAndSubmit(null);
    SWTBotTree updatedTree = getOrOpenView().bot().tree();
    updatedTree.select(0);
    selectNode(updatedTree, useRemote, false);
    runPush(updatedTree);
    bot.waitUntil(Conditions.shellIsActive(dialogTitle));
    confirmed = bot.shell(dialogTitle);
    treeItems = confirmed.bot().tree().getAllItems();
    newBranch = false;
    for (SWTBotTreeItem item : treeItems) {
        newBranch = item.getText().contains(objectIdBefore);
        if (newBranch)
            break;
    }
    confirmed.close();
    assertTrue("New branch expected", newBranch);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)

Example 8 with SWTBotView

use of org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView in project egit by eclipse.

the class GitRepositoriesViewTest method testLinkWithSelectionEditor.

/**
 * Link with editor, both ways
 *
 * @throws Exception
 */
@Test
@Ignore("'Link with Selection' does not activate editor on selection change (bug 409722).")
public void testLinkWithSelectionEditor() throws Exception {
    deleteAllProjects();
    shareProjects(repositoryFile);
    SWTBotTree tree = getOrOpenView().bot().tree();
    myRepoViewUtil.getRootItem(tree, repositoryFile).select();
    // the selection should be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));
    SWTBotView view = TestUtil.showExplorerView();
    SWTBotTree projectExplorerTree = view.bot().tree();
    SWTBotTreeItem item = TestUtil.expandAndWait(getProjectItem(projectExplorerTree, PROJ1));
    item = TestUtil.expandAndWait(item.getNode(FOLDER)).getNode(FILE1);
    view.show();
    item.doubleClick();
    item = TestUtil.expandAndWait(getProjectItem(projectExplorerTree, PROJ1));
    item = TestUtil.expandAndWait(item.getNode(FOLDER)).getNode(FILE2);
    view.show();
    item.doubleClick();
    // now we should have two editors
    // the selection should be still be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));
    // activate the link with selection
    toggleLinkWithSelection();
    bot.editorByTitle(FILE2).show();
    // the selection should have changed to the latest editor
    TestUtil.waitUntilTreeHasSelectedNodeWithText(bot, tree, FILE2, 10000);
    bot.editorByTitle(FILE1).show();
    // selection should have changed
    TestUtil.waitUntilTreeHasSelectedNodeWithText(bot, tree, FILE1, 10000);
    // deactivate the link with editor
    toggleLinkWithSelection();
    bot.editorByTitle(FILE2).show();
    // the selection should be still be test.txt
    TestUtil.waitUntilTreeHasSelectedNodeWithText(bot, tree, FILE1, 10000);
    bot.editorByTitle(FILE1).show();
    item = TestUtil.expandAndWait(myRepoViewUtil.getWorkdirItem(tree, repositoryFile));
    item = TestUtil.expandAndWait(item.getNode(PROJ1));
    item = TestUtil.expandAndWait(item.getNode(FOLDER));
    item.getNode(FILE2).select();
    // the editor should still be test.txt
    assertEquals(FILE1, bot.activeEditor().getTitle());
    // activate again
    toggleLinkWithSelection();
    // make sure focus is here
    // tried to remove this waitInUI but failed.
    // tried setting focus, waiting for focus, joining RepositoriesView
    // refresh job
    waitInUI();
    item = TestUtil.expandAndWait(myRepoViewUtil.getWorkdirItem(tree, repositoryFile));
    item = TestUtil.expandAndWait(item.getNode(PROJ1));
    item = TestUtil.expandAndWait(item.getNode(FOLDER));
    item.getNode(FILE2).select();
    TestUtil.waitUntilEditorIsActive(bot, bot.editorByTitle(FILE2), 10000);
    item = TestUtil.expandAndWait(myRepoViewUtil.getWorkdirItem(tree, repositoryFile));
    item = TestUtil.expandAndWait(item.getNode(PROJ1));
    item = TestUtil.expandAndWait(item.getNode(FOLDER));
    item.getNode(FILE1).select();
    TestUtil.waitUntilEditorIsActive(bot, bot.editorByTitle(FILE1), 10000);
    // deactivate the link with editor
    toggleLinkWithSelection();
    item = TestUtil.expandAndWait(myRepoViewUtil.getWorkdirItem(tree, repositoryFile));
    item = TestUtil.expandAndWait(item.getNode(PROJ1));
    item = TestUtil.expandAndWait(item.getNode(FOLDER));
    item.getNode(FILE2).select();
    TestUtil.waitUntilEditorIsActive(bot, bot.editorByTitle(FILE1), 10000);
}
Also used : SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with SWTBotView

use of org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView in project egit by eclipse.

the class GitRepositoriesViewTest method testShowProperties.

/**
 * Show properties
 *
 * @throws Exception
 */
@Test
public void testShowProperties() throws Exception {
    SWTBotTree tree = getOrOpenView().bot().tree();
    SWTBotTreeItem item = myRepoViewUtil.getRootItem(tree, repositoryFile);
    item.select();
    ContextMenuHelper.clickContextMenuSync(tree, myUtil.getPluginLocalizedValue("ShowIn"), "Properties");
    SWTBotView propertieView = bot.viewById(IPageLayout.ID_PROP_SHEET);
    assertTrue(propertieView.isActive());
}
Also used : SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) Test(org.junit.Test)

Example 10 with SWTBotView

use of org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView in project egit by eclipse.

the class GitRepositoriesViewTestBase method assertEmpty.

protected void assertEmpty() throws Exception {
    final SWTBotView view = getOrOpenView();
    view.bot().label(UIText.RepositoriesView_messsageEmpty);
}
Also used : SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)

Aggregations

SWTBotView (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)41 SWTBotTree (org.eclipse.swtbot.swt.finder.widgets.SWTBotTree)14 Test (org.junit.Test)12 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)10 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)7 Repository (org.eclipse.jgit.lib.Repository)3 SWTWorkbenchBot (org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot)3 Git (org.eclipse.jgit.api.Git)2 Composite (org.eclipse.swt.widgets.Composite)2 Tree (org.eclipse.swt.widgets.Tree)2 WidgetNotFoundException (org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException)2 SWTBotStyledText (org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText)2 SWTBotToolbarToggleButton (org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarToggleButton)2 DockerClient (com.spotify.docker.client.DockerClient)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IDynamicVariable (org.eclipse.core.variables.IDynamicVariable)1 GitScopeOperation (org.eclipse.egit.ui.internal.operations.GitScopeOperation)1