Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-02-09 22:08:10 +0000
committerMatthias Sohn2016-02-11 10:51:40 +0000
commit2349a197c1304fa534b117ed5ec23f437bb26a25 (patch)
treedb6b99b652c47f923fcad9606f71c1e8d851e95d /org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team
parent7aac7a22a1042bb52936d3361f9450c3625f5ca3 (diff)
downloadegit-2349a197c1304fa534b117ed5ec23f437bb26a25.tar.gz
egit-2349a197c1304fa534b117ed5ec23f437bb26a25.tar.xz
egit-2349a197c1304fa534b117ed5ec23f437bb26a25.zip
Make AddToIndex/RemoveFromIndex work for multiple repositories again
Commit 4e89050 inadvertently introduced the restriction that all resources in the selection be in one repository. However, AddToIndex, RemoveFromIndex, and Ignore previously also worked if projects from different repositories were selected. Remove the restriction on a single repository from the ResourceStatePropertyTester, and simplify the isEnabled() of AddToIndex and RemoveFromIndex action handlers a bit. The ResourceStatePropertyTester is currently used only for these commands in the Team context menu. If is ever to be used with some command for which all resources really must be from one repository, it can be combined with the "resourcesSingleRepository" property test. Performance should not suffer as all repository or index diff operations in the property tester operate on caches. Add new tests to test the "Add To Index" and "Remove From Index" actions for single and multiple repository selections. Change-Id: I71b1ece61cceeb08ee775e7afae33beee2b57b9f Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/StageUnstageActionTest.java163
1 files changed, 163 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/StageUnstageActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/StageUnstageActionTest.java
new file mode 100644
index 0000000000..5f28c01d31
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/StageUnstageActionTest.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Thomas Wolf <thomas.wolf@paranor.ch>
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.team.actions;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.core.JobFamilies;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.internal.resources.IResourceState;
+import org.eclipse.egit.ui.internal.resources.ResourceStateFactory;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the Team->Add To Index/Remove From Index actions.
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class StageUnstageActionTest extends LocalRepositoryTestCase {
+
+ private static final String REPO_A = "repoA";
+
+ private static final String REPO_B = "repoB";
+
+ private static final String PROJ_A = "FirstProject";
+
+ private static final String PROJ_B = "SecondProject";
+
+ private String addToIndexLabel;
+
+ private String removeFromIndexLabel;
+
+ @Before
+ public void setup() throws Exception {
+ createProjectAndCommitToRepository(REPO_A, PROJ_A);
+ createProjectAndCommitToRepository(REPO_B, PROJ_B);
+ addToIndexLabel = util
+ .getPluginLocalizedValue("AddToIndexAction_label");
+ removeFromIndexLabel = util
+ .getPluginLocalizedValue("RemoveFromIndexAction_label");
+ }
+
+ @Test
+ public void testActionsInitiallyNotPresent() {
+ // Verify that neither add to index nor remove from index are available.
+ SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
+ util.getProjectItems(projectExplorerTree, PROJ_A)[0].select();
+ assertFalse("Add To Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", addToIndexLabel));
+ assertFalse("Remove From Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", removeFromIndexLabel));
+ util.getProjectItems(projectExplorerTree, PROJ_B)[0].select();
+ assertFalse("Add To Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", addToIndexLabel));
+ assertFalse("Remove From Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", removeFromIndexLabel));
+ projectExplorerTree.select(projectExplorerTree.getAllItems());
+ assertFalse("Add To Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", addToIndexLabel));
+ assertFalse("Remove From Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", removeFromIndexLabel));
+ }
+
+ @Test
+ public void testSingleProject() throws Exception {
+ // Change something in first project
+ String filePath = FOLDER + '/' + FILE1;
+ touch(PROJ_A, filePath, "Changed content");
+ // Select other project
+ SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
+ util.getProjectItems(projectExplorerTree, PROJ_B)[0].select();
+ // Verify that Add to index is not present
+ assertFalse("Add To Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", addToIndexLabel));
+ assertFalse("Remove From Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", removeFromIndexLabel));
+ // Select first project; add to index
+ util.getProjectItems(projectExplorerTree, PROJ_A)[0].select();
+ ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team",
+ addToIndexLabel);
+ TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
+ // Verify file got staged
+ verifyStaging(PROJ_A, filePath, true);
+ // Remove from index
+ util.getProjectItems(projectExplorerTree, PROJ_A)[0].select();
+ assertFalse("Add To Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", addToIndexLabel));
+ ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team",
+ removeFromIndexLabel);
+ TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
+ // Verify file is unstaged again
+ verifyStaging(PROJ_A, filePath, false);
+ }
+
+ @Test
+ public void testBothProjects() throws Exception {
+ // Change something in both
+ String filePath = FOLDER + '/' + FILE1;
+ touch(PROJ_A, filePath, "Changed content");
+ touch(PROJ_B, filePath, "Changed content");
+ // Select both projects
+ SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
+ projectExplorerTree.select(projectExplorerTree.getAllItems());
+ assertFalse("Remove From Index should not be present",
+ ContextMenuHelper.contextMenuItemExists(projectExplorerTree,
+ "Team", removeFromIndexLabel));
+ // Add to index
+ ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team",
+ addToIndexLabel);
+ TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
+ // Verify both files got staged
+ verifyStaging(PROJ_A, filePath, true);
+ verifyStaging(PROJ_B, filePath, true);
+ // Select both projects
+ projectExplorerTree.select(projectExplorerTree.getAllItems());
+ // Remove from index
+ ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team",
+ removeFromIndexLabel);
+ TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
+ // Verify both files got unstaged
+ verifyStaging(PROJ_A, filePath, false);
+ verifyStaging(PROJ_B, filePath, false);
+ }
+
+ private void verifyStaging(String projectName, String filePath,
+ boolean expected) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+ IResource resource = project.findMember(filePath);
+ assertNotNull(filePath + " should exist", resource);
+ IResourceState state = ResourceStateFactory.getInstance().get(resource);
+ if (expected) {
+ assertTrue(projectName + '/' + filePath + " should be staged",
+ state.isStaged());
+ } else {
+ assertFalse(projectName + '/' + filePath + " should be unstaged",
+ state.isStaged());
+ }
+ }
+}

Back to the top