Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Hohenegger2015-12-11 08:00:13 +0000
committerMatthias Sohn2015-12-30 00:02:14 +0000
commit4775d5d731de404ff062bc22a2d31fb78e17a89b (patch)
treebc6212ad6987528fff5919cb8f952dd01abbf6e3 /org.eclipse.egit.ui.test
parentdbc39e38aa3f7d3447dcc189acff0d318ad8a036 (diff)
downloadegit-4775d5d731de404ff062bc22a2d31fb78e17a89b.tar.gz
egit-4775d5d731de404ff062bc22a2d31fb78e17a89b.tar.xz
egit-4775d5d731de404ff062bc22a2d31fb78e17a89b.zip
Add tests for Gitflow command enablement
- package explorer on project selection Change-Id: I96eda381a8d909b48e538c09d4e1c535ba71b81b Signed-off-by: Max Hohenegger <eclipse@hohenegger.eu> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui.test')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractFeatureFinishHandlerTest.java5
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractGitflowHandlerTest.java8
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/CommandEnablementTest.java130
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureRebaseHandlerTest.java5
4 files changed, 137 insertions, 11 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractFeatureFinishHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractFeatureFinishHandlerTest.java
index a7bf42e2f0..cafcf89e95 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractFeatureFinishHandlerTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractFeatureFinishHandlerTest.java
@@ -12,7 +12,6 @@ import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.op.BranchOperation;
-import org.eclipse.egit.gitflow.op.InitOperation;
import org.eclipse.egit.gitflow.ui.Activator;
import org.eclipse.egit.gitflow.ui.internal.JobFamilies;
import org.eclipse.egit.gitflow.ui.internal.UIText;
@@ -56,10 +55,6 @@ public abstract class AbstractFeatureFinishHandlerTest extends AbstractGitflowHa
abstract protected void selectOptions();
- protected void init() throws CoreException {
- new InitOperation(repository).execute(null);
- }
-
@Override
protected void createFeature(String featureName) {
final SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractGitflowHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractGitflowHandlerTest.java
index c6bee24e0d..03b5ee58e2 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractGitflowHandlerTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractGitflowHandlerTest.java
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.op.FeatureCheckoutOperation;
import org.eclipse.egit.gitflow.op.FeatureStartOperation;
+import org.eclipse.egit.gitflow.op.InitOperation;
import org.eclipse.egit.gitflow.ui.Activator;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.test.TestUtil;
@@ -48,10 +49,11 @@ public abstract class AbstractGitflowHandlerTest extends LocalRepositoryTestCase
protected static final String FEATURE_NAME = "myFeature";
protected Repository repository;
+ protected File repositoryFile;
@Before
public void setup() throws Exception {
- File repositoryFile = createProjectAndCommitToRepository();
+ repositoryFile = createProjectAndCommitToRepository();
repository = lookupRepository(repositoryFile);
resetPreferences();
@@ -90,4 +92,8 @@ public abstract class AbstractGitflowHandlerTest extends LocalRepositoryTestCase
protected Ref findBranch(String branchName) throws IOException {
return repository.getRef(R_HEADS + branchName);
}
+
+ protected void init() throws CoreException {
+ new InitOperation(repository).execute(null);
+ }
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/CommandEnablementTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/CommandEnablementTest.java
new file mode 100644
index 0000000000..69cbceab72
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/CommandEnablementTest.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
+ *
+ * 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.gitflow;
+
+import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.egit.gitflow.ui.internal.UIText;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.internal.repository.RepositoriesView;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotCommand;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the Gitflow plugin.xml expressions, property testers, AdapterFactories, etc.
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class CommandEnablementTest extends AbstractGitflowHandlerTest {
+
+ private static final String FEATURE_START_CMD = "org.eclipse.egit.gitflow.ui.command.featureStart";
+ private static final String FEATURE_FINISH_CMD = "org.eclipse.egit.gitflow.ui.command.featureFinish";
+
+ private static final String RELEASE_START_CMD = "org.eclipse.egit.gitflow.ui.command.releaseStart";
+ private static final String RELEASE_END_CMD = "org.eclipse.egit.gitflow.ui.command.releaseFinish";
+
+ private static final String HOTFIX_START_CMD = "org.eclipse.egit.gitflow.ui.command.hotfixStart";
+ private static final String HOTFIX_END_CMD = "org.eclipse.egit.gitflow.ui.command.hotfixFinish";
+
+ @Test
+ public void testPackageExplorerStartFinishEnablement() throws Exception {
+ selectPackageExplorerItem(0);
+ assertAllCommandsDisabled();
+ init();
+ assertAllCommandsEnabledAndExecutable();
+ }
+
+ @Test
+ public void testRepositoryViewStartFinishEnablement() throws Exception {
+ initRepositoriesView();
+ selectRepositoryInView(0);
+ assertAllCommandsDisabled();
+ init();
+ assertAllCommandsEnabledAndExecutable();
+ }
+
+ private void selectPackageExplorerItem(int index) {
+ SWTBotTree explorerTree = TestUtil.getExplorerTree();
+ explorerTree.select(index);
+ }
+
+ private void selectRepositoryInView(int index) {
+ SWTBotTree explorerTree = getRepositoryTree();
+ explorerTree.select(index);
+ }
+
+ private void assertAllCommandsEnabledAndExecutable() throws Exception {
+ testCommand(FEATURE_START_CMD, FEATURE_FINISH_CMD, UIText.FeatureStartHandler_provideFeatureName);
+ testCommand(RELEASE_START_CMD, RELEASE_END_CMD, UIText.ReleaseStartHandler_provideReleaseName);
+ testCommand(HOTFIX_START_CMD, HOTFIX_END_CMD, UIText.HotfixStartHandler_provideHotfixName);
+ }
+
+
+ private void assertAllCommandsDisabled() {
+ assertCommandEnablement(FEATURE_START_CMD, false);
+ assertCommandEnablement(RELEASE_START_CMD, false);
+ assertCommandEnablement(HOTFIX_START_CMD, false);
+ }
+
+ private void initRepositoriesView() throws IOException {
+ Activator.getDefault().getRepositoryUtil()
+ .addConfiguredRepository(repositoryFile);
+ repository = org.eclipse.egit.core.Activator.getDefault()
+ .getRepositoryCache().lookupRepository(repositoryFile);
+ }
+
+ public static SWTBotTree getRepositoryTree() {
+ SWTBotView view = TestUtil.showView(RepositoriesView.VIEW_ID);
+ return view.bot().tree();
+ }
+
+ private void testCommand(String startCommandId, String finishCommandId, String dialogTitle) throws Exception {
+ assertCommandEnablement(startCommandId, true);
+ assertCommandOpensDialog(startCommandId, dialogTitle);
+ assertCommandEnablement(finishCommandId, false);
+ }
+
+ private void assertCommandOpensDialog(String startCommandId,
+ String dialogTitle) throws Exception {
+ runCommand(startCommandId);
+ bot.waitUntil(shellIsActive(dialogTitle));
+ bot.button("Cancel").click();
+ }
+
+
+ private void runCommand(String commandId) throws Exception {
+ final Command command = getCommandService().getCommand(commandId);
+ SWTBotCommand swtBotCommand = new SWTBotCommand(command);
+ swtBotCommand.click();
+ }
+
+ @SuppressWarnings("boxing")
+ private void assertCommandEnablement(String id, boolean enablement) {
+ ICommandService service = getCommandService();
+ Command command = service.getCommand(id);
+ assertTrue(command.isDefined());
+ assertTrue(command.isHandled());
+ assertEquals(enablement, command.isEnabled());
+ }
+
+ private ICommandService getCommandService() {
+ return PlatformUI.getWorkbench().getService(ICommandService.class);
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureRebaseHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureRebaseHandlerTest.java
index 2310462531..a97ae116a0 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureRebaseHandlerTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureRebaseHandlerTest.java
@@ -14,7 +14,6 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.op.FeatureCheckoutOperation;
-import org.eclipse.egit.gitflow.op.InitOperation;
import org.eclipse.egit.gitflow.ui.Activator;
import org.eclipse.egit.gitflow.ui.internal.JobFamilies;
import org.eclipse.egit.gitflow.ui.internal.UIText;
@@ -99,10 +98,6 @@ public class FeatureRebaseHandlerTest extends AbstractGitflowHandlerTest {
assertEquals(FILE1_PATH, uncommitted[0]);
}
- private void init() throws CoreException {
- new InitOperation(repository).execute(null);
- }
-
@Override
protected void checkoutFeature(String featureName) throws CoreException {
new FeatureCheckoutOperation(new GitFlowRepository(repository), featureName).execute(null);

Back to the top