aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Baumgart2010-09-24 09:00:09 -0400
committerMatthias Sohn2010-09-24 09:00:09 -0400
commit4fb81b320fe1b3dc07df3e8bdc4b46a4bae78aac (patch)
treef3b0af9ae1de4bca9a7d7222cc3033275b4f75fc
parentb9e8e1bae984120a6c2fbc1ed95e4a74f8cfef86 (diff)
downloadegit-4fb81b320fe1b3dc07df3e8bdc4b46a4bae78aac.zip
egit-4fb81b320fe1b3dc07df3e8bdc4b46a4bae78aac.tar.gz
egit-4fb81b320fe1b3dc07df3e8bdc4b46a4bae78aac.tar.xz
Fix ui tests accessing history view too early
Test cases in HistoryViewTest sometimes failed on Windows because History view was accessed too early. Problem was fixed by joining GenerateHistoryJob. CommitActionTest was fixed by joining the commit job. Change-Id: I2badd891e8791f15d7ab74eb75e38409867541e6 Signed-off-by: Jens Baumgart <jens.baumgart@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java66
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionTest.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java26
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GenerateHistoryJob.java9
5 files changed, 88 insertions, 26 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
index 7ef62d3..d2328c1 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
@@ -22,6 +22,8 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.test.ContextMenuHelper;
@@ -68,13 +70,14 @@ public class HistoryViewTest extends LocalRepositoryTestCase {
repoFile = createProjectAndCommitToRepository();
perspective = bot.activePerspective();
bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
- IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(
- PROJ1);
+ IProject prj = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(PROJ1);
IFolder folder2 = prj.getFolder(SECONDFOLDER);
folder2.create(false, true, null);
IFile addedFile = folder2.getFile(ADDEDFILE);
- addedFile.create(new ByteArrayInputStream("More content".getBytes(prj
- .getDefaultCharset())), false, null);
+ addedFile.create(
+ new ByteArrayInputStream("More content".getBytes(prj
+ .getDefaultCharset())), false, null);
addAndCommit(addedFile, ADDEDMESSAGE);
// TODO count the commits
commitCount = 3;
@@ -96,17 +99,18 @@ public class HistoryViewTest extends LocalRepositoryTestCase {
getHistoryViewTable(PROJ1, FOLDER).rowCount());
assertEquals("Wrong number of commits", commitCount - 1,
getHistoryViewTable(PROJ1, FOLDER, FILE1).rowCount());
- assertEquals("Wrong number of commits", 1, getHistoryViewTable(PROJ1,
- FOLDER, FILE2).rowCount());
- assertEquals("Wrong number of commits", 1, getHistoryViewTable(PROJ1,
- SECONDFOLDER).rowCount());
- assertEquals("Wrong number of commits", 1, getHistoryViewTable(PROJ1,
- SECONDFOLDER, ADDEDFILE).rowCount());
+ assertEquals("Wrong number of commits", 1,
+ getHistoryViewTable(PROJ1, FOLDER, FILE2).rowCount());
+ assertEquals("Wrong number of commits", 1,
+ getHistoryViewTable(PROJ1, SECONDFOLDER).rowCount());
+ assertEquals("Wrong number of commits", 1,
+ getHistoryViewTable(PROJ1, SECONDFOLDER, ADDEDFILE).rowCount());
assertEquals("Wrong number of commits", 1, getHistoryViewTable(PROJ2)
.rowCount());
- assertEquals("Wrong commit message", ADDEDMESSAGE, getHistoryViewTable(
- PROJ1, SECONDFOLDER, ADDEDFILE).getTableItem(0).getText(0));
+ assertEquals("Wrong commit message", ADDEDMESSAGE,
+ getHistoryViewTable(PROJ1, SECONDFOLDER, ADDEDFILE)
+ .getTableItem(0).getText(0));
assertEquals("Wrong commit message", "Initial commit",
getHistoryViewTable(PROJ1, FOLDER, FILE2).getTableItem(0)
.getText(0));
@@ -163,8 +167,8 @@ public class HistoryViewTest extends LocalRepositoryTestCase {
getHistoryViewTable(PROJ1, FOLDER, FILE2).rowCount());
assertEquals("Wrong number of commits", commitCount,
getHistoryViewTable(PROJ1, SECONDFOLDER).rowCount());
- assertEquals("Wrong number of commits", 1, getHistoryViewTable(PROJ1,
- SECONDFOLDER, ADDEDFILE).rowCount());
+ assertEquals("Wrong number of commits", 1,
+ getHistoryViewTable(PROJ1, SECONDFOLDER, ADDEDFILE).rowCount());
assertEquals("Wrong number of commits", commitCount,
getHistoryViewTable(PROJ2).rowCount());
}
@@ -172,8 +176,9 @@ public class HistoryViewTest extends LocalRepositoryTestCase {
/**
* @param filter
* 0: none, 1: repository, 2: project, 3: folder
+ * @throws Exception
*/
- private void initFilter(int filter) {
+ private void initFilter(int filter) throws Exception {
getHistoryViewTable(PROJ1);
SWTBotView view = bot
.viewById("org.eclipse.team.ui.GenericHistoryView");
@@ -226,18 +231,19 @@ public class HistoryViewTest extends LocalRepositoryTestCase {
waitInUI();
int countAfter = getHistoryViewTable(PROJ1).rowCount();
assertEquals("Wrong number of entries", countBefore + 1, countAfter);
- assertEquals("Wrong comit message", commitMessage, getHistoryViewTable(
- PROJ1).getTableItem(0).getText(0));
+ assertEquals("Wrong comit message", commitMessage,
+ getHistoryViewTable(PROJ1).getTableItem(0).getText(0));
}
/**
* @param path
* must be length 2 or three (folder or file)
* @return the bale
+ * @throws Exception
*/
- private SWTBotTable getHistoryViewTable(String... path) {
- SWTBotTree projectExplorerTree = bot.viewById(
- "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ private SWTBotTable getHistoryViewTable(String... path) throws Exception {
+ SWTBotTree projectExplorerTree = bot
+ .viewById("org.eclipse.jdt.ui.PackageExplorer").bot().tree();
SWTBotTreeItem explorerItem;
if (path.length == 1)
explorerItem = getProjectItem(projectExplorerTree, path[0]);
@@ -250,7 +256,15 @@ public class HistoryViewTest extends LocalRepositoryTestCase {
explorerItem.select();
ContextMenuHelper.clickContextMenu(projectExplorerTree, "Show In",
"History");
- // explorerItem.select();
+ // join GenerateHistoryJob
+ Job.getJobManager().join(JobFamilies.GENERATE_HISTORY, null);
+ // join UI update triggered by GenerateHistoryJob
+ projectExplorerTree.widget.getDisplay().syncExec(new Runnable() {
+
+ public void run() {
+ // empty
+ }
+ });
return bot.viewById("org.eclipse.team.ui.GenericHistoryView").bot()
.table();
}
@@ -294,10 +308,10 @@ public class HistoryViewTest extends LocalRepositoryTestCase {
ContextMenuHelper.clickContextMenu(table,
UIText.GitHistoryPage_CreateTagMenuLabel);
SWTBotShell dialog = bot.shell(UIText.CreateTagDialog_NewTag);
- dialog.bot().textWithLabel(UIText.CreateTagDialog_tagName).setText(
- "NewTag");
- dialog.bot().textWithLabel(UIText.CreateTagDialog_tagMessage).setText(
- "New Tag message");
+ dialog.bot().textWithLabel(UIText.CreateTagDialog_tagName)
+ .setText("NewTag");
+ dialog.bot().textWithLabel(UIText.CreateTagDialog_tagMessage)
+ .setText("New Tag message");
dialog.bot().button(IDialogConstants.OK_LABEL).click();
waitInUI();
assertNotNull(repo.resolve(Constants.R_TAGS + "NewTag"));
@@ -332,7 +346,7 @@ public class HistoryViewTest extends LocalRepositoryTestCase {
/**
* Workaround to ensure that the TableItem of a SWT table with style
* SWT_VIRTUAL is loaded.
- *
+ *
* @param item
*/
private static void ensureTableItemLoaded(TableItem item) {
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionTest.java
index dcde47a..edcda8d 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionTest.java
@@ -17,8 +17,10 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.core.op.TagOperation;
+import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.test.ContextMenuHelper;
@@ -105,6 +107,8 @@ public class CommitActionTest extends LocalRepositoryTestCase {
commitDialog.bot().styledTextWithLabel(UIText.CommitDialog_CommitMessage)
.setText("The new commit");
commitDialog.bot().button(UIText.CommitDialog_Commit).click();
+ // wait until commit is completed
+ Job.getJobManager().join(JobFamilies.COMMIT, null);
testOpenCommitWithoutChanged();
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java
new file mode 100644
index 0000000..28655d1
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/JobFamilies.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
+ *
+ * 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;
+
+/**
+ * Job families of EGit jobs. May be used in tests to join
+ * job execution.
+ *
+ */
+public class JobFamilies {
+ /**
+ * GenerateHistoryJob
+ */
+ public final static Object GENERATE_HISTORY = new Object();
+ /**
+ * Commit job
+ */
+ public final static Object COMMIT = new Object();
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
index a8cf8dd..9420041 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/CommitActionHandler.java
@@ -42,6 +42,7 @@ import org.eclipse.egit.core.AdaptableFileTreeIterator;
import org.eclipse.egit.core.op.CommitOperation;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator;
import org.eclipse.egit.ui.internal.dialogs.CommitDialog;
@@ -217,6 +218,14 @@ public class CommitActionHandler extends RepositoryActionHandler {
}
return Status.OK_STATUS;
}
+
+ @Override
+ public boolean belongsTo(Object family) {
+ if (family.equals(JobFamilies.COMMIT))
+ return true;
+ return super.belongsTo(family);
+ }
+
};
job.setUser(true);
job.schedule();
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GenerateHistoryJob.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GenerateHistoryJob.java
index 984e444..090eda8 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GenerateHistoryJob.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GenerateHistoryJob.java
@@ -15,6 +15,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIText;
class GenerateHistoryJob extends Job {
@@ -74,4 +75,12 @@ class GenerateHistoryJob extends Job {
page.showCommitList(this, allCommits, asArray);
lastUpdateCnt = allCommits.size();
}
+
+ @Override
+ public boolean belongsTo(Object family) {
+ if (family.equals(JobFamilies.GENERATE_HISTORY))
+ return true;
+ return super.belongsTo(family);
+ }
+
}