Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Kinzler2010-07-22 14:10:07 +0000
committerMathias Kinzler2010-07-22 14:10:07 +0000
commite4a2f3f2d8f09e5f3847256c7c3de9cc27b5b1b8 (patch)
tree02b19110fdb0feb1e7bae9c1e939c868a8dcd6d7 /org.eclipse.egit.ui.test/src/org
parentb1cdacd6a2f07a7e2030da8b82f816ade70edbfc (diff)
downloadegit-e4a2f3f2d8f09e5f3847256c7c3de9cc27b5b1b8.tar.gz
egit-e4a2f3f2d8f09e5f3847256c7c3de9cc27b5b1b8.tar.xz
egit-e4a2f3f2d8f09e5f3847256c7c3de9cc27b5b1b8.zip
TeamMenuTests
Add some UI tests for the following Team-> menu actions: BranchAction CommitAction PushAction FetchAction MergeAction TagAction DisconnectAction ShareProjectAction and for the history view Also added memory settings for extended PermGen to both existing launch configurations in order to make Synchronize tests work and removed redundant third lauch configuration. A minor fix on CreateTagDialog was needed to make it testable. Change-Id: Ieee337d2aeeb0d2fe2ee12dacc398cdd2d258aa7 Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/EGitTestCase.java2
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java512
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java2
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllLocalTests.java30
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllTests.java13
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java12
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java240
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/AllTeamActionTests.java27
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java238
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionTest.java117
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/DisconnectConnectTest.java97
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java151
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/PushActionTest.java140
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java157
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java50
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java28
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRemoteHandlingTest.java312
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java98
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java134
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java489
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java132
21 files changed, 2205 insertions, 776 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/EGitTestCase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/EGitTestCase.java
index 31b2c2c755..6eef85e220 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/EGitTestCase.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/EGitTestCase.java
@@ -14,6 +14,7 @@ import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.ui.test.Eclipse;
+import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
@@ -26,6 +27,7 @@ import org.junit.runner.RunWith;
public abstract class EGitTestCase {
protected static final SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ protected static final TestUtil util = new TestUtil();
@BeforeClass
public static void closeWelcomePage() {
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
new file mode 100644
index 0000000000..6d4181f871
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
@@ -0,0 +1,512 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.common;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.egit.core.op.CloneOperation;
+import org.eclipse.egit.core.op.CommitOperation;
+import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.eclipse.egit.ui.internal.push.PushConfiguredRemoteAction;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.Eclipse;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RefUpdate;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.jgit.util.FS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * Base class for testing with local (file-system based) repositories
+ * <p>
+ * This supports single repository scenarios as well as "remote" scenarios with
+ * two local repositories that are interconnected with each other via the
+ * "origin" configuration.
+ * <p>
+ * The repositories are created under a directory named "LocalRepositoriesTests"
+ * under the user home directory and everything is deleted recursively in
+ * {@link #afterClassBase()}.
+ * <p>
+ * {@link #createProjectAndCommitToRepository()} creates a couple of projects
+ * and adds them to a local repository named {@link #REPO1}.
+ * <p>
+ * {@link #createRemoteRepository(File)} creates a bare repository based on the
+ * File of another repository. The original repository will be configured with
+ * three remote specifications that can be used to push to the bare repository
+ * with slightly different set-ups (combinations of urls and specs): fetch,
+ * push, both, and mixed
+ * <p>
+ * A typical code sequence for setting up these two repositories could look
+ * like:
+ *
+ * <pre>
+ * private File localRepo;
+ * private File remoteRepo;
+ * ...
+ * {@literal @}BeforeClass
+ * public static void initRepos() throws Exception {
+ * localRepo = repositoryFile = createProjectAndCommitToRepository();
+ * remtoeRepo =remoteRepositoryFile = createRemoteRepository(repositoryFile);
+ * }
+ * </pre>
+ * <p>
+ * {@link #createChildRepository(File)} creates a "child" repository based on
+ * the File another repository; the child will be cloned from the original
+ * repository and a "origin" remote spec will be set-up automatically
+ */
+public abstract class LocalRepositoryTestCase extends EGitTestCase {
+
+ // the temporary directory
+ protected static File testDirectory;
+
+ protected static final String REPO1 = "FirstRepository";
+
+ protected static final String REPO2 = "RemoteRepository";
+
+ protected static final String CHILDREPO = "ChildRepository";
+
+ /** A general project containing FOLDER containing FILE1 and FILE2 */
+ protected static final String PROJ1 = "GeneralProject";
+
+ /** A folder obtained by checking in a project without .project */
+ protected static final String PROJ2 = "ProjectWithoutDotProject";
+
+ protected static final String FILE1 = "test.txt";
+
+ protected static final String FILE2 = "test2.txt";
+
+ protected static final String FOLDER = "folder";
+
+ @BeforeClass
+ public static void beforeClassBase() throws Exception {
+ deleteAllProjects();
+ // create our temporary directory in the user space
+ File userHome = FS.DETECTED.userHome();
+ testDirectory = new File(userHome, "LocalRepositoriesTests");
+ if (testDirectory.exists())
+ deleteRecursive(testDirectory);
+ testDirectory.mkdir();
+ }
+
+ @AfterClass
+ public static void afterClassBase() throws Exception {
+ // close all editors/dialogs
+ new Eclipse().reset();
+ // cleanup
+ deleteAllProjects();
+ deleteRecursive(testDirectory);
+ }
+
+ protected static void deleteRecursive(File dirOrFile) {
+ if (dirOrFile.isDirectory()) {
+ for (File file : dirOrFile.listFiles()) {
+ deleteRecursive(file);
+ }
+ }
+ boolean deleted = dirOrFile.delete();
+ if (!deleted) {
+ dirOrFile.deleteOnExit();
+ }
+ }
+
+ protected static void deleteAllProjects() throws CoreException {
+ for (IProject prj : ResourcesPlugin.getWorkspace().getRoot()
+ .getProjects())
+ if (prj.getName().equals(PROJ1))
+ prj.delete(false, false, null);
+ else if (prj.getName().equals(PROJ2)) {
+ // delete the .project on disk
+ EFS.getStore(prj.getFile(".project").getLocationURI())
+ .toLocalFile(EFS.NONE, null).delete();
+ prj.delete(false, false, null);
+ }
+
+ }
+
+ protected static File createProjectAndCommitToRepository() throws Exception {
+
+ File gitDir = new File(new File(testDirectory, REPO1),
+ Constants.DOT_GIT);
+ gitDir.mkdir();
+ Repository myRepository = new Repository(gitDir);
+ myRepository.create();
+
+ // we need to commit into master first
+ IProject firstProject = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(PROJ1);
+
+ if (firstProject.exists())
+ firstProject.delete(true, null);
+ IProjectDescription desc = ResourcesPlugin.getWorkspace()
+ .newProjectDescription(PROJ1);
+ desc.setLocation(new Path(new File(myRepository.getWorkDir(), PROJ1)
+ .getPath()));
+ firstProject.create(desc, null);
+ firstProject.open(null);
+
+ IFolder folder = firstProject.getFolder(FOLDER);
+ folder.create(false, true, null);
+ IFile textFile = folder.getFile(FILE1);
+ textFile.create(new ByteArrayInputStream("Hello, world"
+ .getBytes(firstProject.getDefaultCharset())), false, null);
+ IFile textFile2 = folder.getFile(FILE2);
+ textFile2.create(new ByteArrayInputStream("Some more content"
+ .getBytes(firstProject.getDefaultCharset())), false, null);
+
+ new ConnectProviderOperation(firstProject, gitDir).execute(null);
+
+ IProject secondPoject = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(PROJ2);
+
+ if (secondPoject.exists())
+ secondPoject.delete(true, null);
+
+ desc = ResourcesPlugin.getWorkspace().newProjectDescription(PROJ2);
+ desc.setLocation(new Path(new File(myRepository.getWorkDir(), PROJ2)
+ .getPath()));
+ secondPoject.create(desc, null);
+ secondPoject.open(null);
+
+ IFolder secondfolder = secondPoject.getFolder(FOLDER);
+ secondfolder.create(false, true, null);
+ IFile secondtextFile = secondfolder.getFile(FILE1);
+ secondtextFile.create(new ByteArrayInputStream("Hello, world"
+ .getBytes(firstProject.getDefaultCharset())), false, null);
+ IFile secondtextFile2 = secondfolder.getFile(FILE2);
+ secondtextFile2.create(new ByteArrayInputStream("Some more content"
+ .getBytes(firstProject.getDefaultCharset())), false, null);
+ // TODO we should be able to hide the .project
+ // IFile gitignore = secondPoject.getFile(".gitignore");
+ // gitignore.create(new ByteArrayInputStream("/.project\n"
+ // .getBytes(firstProject.getDefaultCharset())), false, null);
+
+ new ConnectProviderOperation(secondPoject, gitDir).execute(null);
+
+ IFile[] commitables = new IFile[] { firstProject.getFile(".project"),
+ textFile, textFile2, secondtextFile, secondtextFile2 };
+ ArrayList<IFile> untracked = new ArrayList<IFile>();
+ untracked.addAll(Arrays.asList(commitables));
+ // commit to stable
+ CommitOperation op = new CommitOperation(commitables,
+ new ArrayList<IFile>(), untracked, TestUtil.TESTAUTHOR,
+ TestUtil.TESTCOMMITTER, "Initial commit");
+ op.execute(null);
+
+ // now create a stable branch (from master)
+ createStableBranch(myRepository);
+ // and check in some stuff into master again
+ touchAndSubmit(null);
+ return gitDir;
+ }
+
+ protected static File createRemoteRepository(File repositoryDir)
+ throws Exception {
+ Repository myRepository = lookupRepository(repositoryDir);
+ File gitDir = new File(testDirectory, REPO2);
+ Repository myRemoteRepository = new Repository(gitDir);
+ myRemoteRepository.create();
+ // double-check that this is bare
+ assertTrue(myRemoteRepository.isBare());
+
+ createStableBranch(myRepository);
+
+ // now we configure a pure push destination
+ myRepository.getConfig().setString("remote", "push", "pushurl",
+ "file:///" + myRemoteRepository.getDirectory().getPath());
+ myRepository.getConfig().setString("remote", "push", "push",
+ "+refs/heads/*:refs/heads/*");
+
+ // and a pure fetch destination
+ myRepository.getConfig().setString("remote", "fetch", "url",
+ "file:///" + myRemoteRepository.getDirectory().getPath());
+ myRepository.getConfig().setString("remote", "fetch", "fetch",
+ "+refs/heads/*:refs/heads/*");
+
+ // a destination with both fetch and push urls and specs
+ myRepository.getConfig().setString("remote", "both", "pushurl",
+ "file:///" + myRemoteRepository.getDirectory().getPath());
+ myRepository.getConfig().setString("remote", "both", "push",
+ "+refs/heads/*:refs/heads/*");
+ myRepository.getConfig().setString("remote", "both", "url",
+ "file:///" + myRemoteRepository.getDirectory().getPath());
+ myRepository.getConfig().setString("remote", "both", "fetch",
+ "+refs/heads/*:refs/heads/*");
+
+ // a destination with only a fetch url and push and fetch specs
+ myRepository.getConfig().setString("remote", "mixed", "push",
+ "+refs/heads/*:refs/heads/*");
+ myRepository.getConfig().setString("remote", "mixed", "url",
+ "file:///" + myRemoteRepository.getDirectory().getPath());
+ myRepository.getConfig().setString("remote", "mixed", "fetch",
+ "+refs/heads/*:refs/heads/*");
+
+ myRepository.getConfig().save();
+ // and push
+ PushConfiguredRemoteAction pa = new PushConfiguredRemoteAction(
+ myRepository, "push");
+
+ pa.run(null, false);
+
+ try {
+ // delete the stable branch again
+ RefUpdate op = myRepository.updateRef("refs/heads/stable");
+ op.setRefLogMessage("branch deleted", //$NON-NLS-1$
+ false);
+ // we set the force update in order
+ // to avoid having this rejected
+ // due to minor issues
+ op.setForceUpdate(true);
+ op.delete();
+ } catch (IOException ioe) {
+ throw new InvocationTargetException(ioe);
+ }
+ return myRemoteRepository.getDirectory();
+ }
+
+ protected static File createChildRepository(File repositoryDir)
+ throws Exception {
+ Repository myRepository = lookupRepository(repositoryDir);
+ URIish uri = new URIish("file:///" + myRepository.getDirectory());
+ File workdir = new File(testDirectory, CHILDREPO);
+ CloneOperation clop = new CloneOperation(uri, true, null, workdir,
+ "refs/heads/master", "origin");
+ clop.run(null);
+ return new File(workdir, Constants.DOT_GIT);
+ }
+
+ protected static void createStableBranch(Repository myRepository)
+ throws IOException {
+ // let's create a stable branch temporarily so
+ // that we push two branches to remote
+ String newRefName = "refs/heads/stable";
+ RefUpdate updateRef = myRepository.updateRef(newRefName);
+ Ref sourceBranch = myRepository.getRef("refs/heads/master");
+ ObjectId startAt = sourceBranch.getObjectId();
+ String startBranch = myRepository
+ .shortenRefName(sourceBranch.getName());
+ updateRef.setNewObjectId(startAt);
+ updateRef
+ .setRefLogMessage("branch: Created from " + startBranch, false); //$NON-NLS-1$
+ updateRef.update();
+ }
+
+ protected void assertClickOpens(SWTBotTree tree, String menu, String window)
+ throws InterruptedException {
+ ContextMenuHelper.clickContextMenu(tree, menu);
+ SWTBotShell shell = bot.shell(window);
+ shell.activate();
+ waitInUI();
+ shell.bot().button(IDialogConstants.CANCEL_LABEL).click();
+ shell.close();
+ }
+
+ protected static void waitInUI() throws InterruptedException {
+ Thread.sleep(1000);
+ }
+
+ protected void shareProjects(File repositoryDir) throws Exception {
+ Repository myRepository = lookupRepository(repositoryDir);
+ FilenameFilter projectFilter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.equals(".project");
+ }
+ };
+ for (File file : myRepository.getWorkDir().listFiles()) {
+ if (file.isDirectory()) {
+ if (file.list(projectFilter).length > 0) {
+ IProjectDescription desc = ResourcesPlugin.getWorkspace()
+ .newProjectDescription(file.getName());
+ desc.setLocation(new Path(file.getPath()));
+ IProject prj = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(file.getName());
+ prj.create(desc, null);
+ prj.open(null);
+
+ new ConnectProviderOperation(prj, myRepository
+ .getDirectory()).execute(null);
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("boxing")
+ protected void assertProjectExistence(String projectName, boolean existence) {
+ IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ projectName);
+ assertEquals("Project existence " + projectName, prj.exists(),
+ existence);
+ }
+
+ protected static Repository lookupRepository(File directory)
+ throws Exception {
+ return org.eclipse.egit.core.Activator.getDefault()
+ .getRepositoryCache().lookupRepository(directory);
+ }
+
+ /**
+ * @param commitMessage
+ * may be null
+ * @throws Exception
+ */
+ protected static void touchAndSubmit(String commitMessage) throws Exception {
+ IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ PROJ1);
+ if (!prj.isAccessible())
+ throw new IllegalStateException("No project to touch");
+ IFile file = prj.getFile(new Path("folder/test.txt"));
+ String newContent = "Touched at " + System.currentTimeMillis();
+ file.setContents(new ByteArrayInputStream(newContent.getBytes(prj
+ .getDefaultCharset())), 0, null);
+
+ IFile[] commitables = new IFile[] { file };
+ ArrayList<IFile> untracked = new ArrayList<IFile>();
+ untracked.addAll(Arrays.asList(commitables));
+ String message = commitMessage;
+ if (message == null)
+ message = newContent;
+ waitInUI();
+ CommitOperation op = new CommitOperation(commitables,
+ new ArrayList<IFile>(), untracked, TestUtil.TESTAUTHOR,
+ TestUtil.TESTCOMMITTER, message);
+ op.execute(null);
+ }
+
+ protected static void addAndCommit(IFile file, String commitMessage)
+ throws Exception {
+ IProject prj = file.getProject();
+ if (!prj.isAccessible())
+ throw new IllegalStateException("No project to touch");
+ IFile[] commitables = new IFile[] { file };
+ ArrayList<IFile> untracked = new ArrayList<IFile>();
+ untracked.addAll(Arrays.asList(commitables));
+ CommitOperation op = new CommitOperation(commitables,
+ new ArrayList<IFile>(), untracked, TestUtil.TESTAUTHOR,
+ TestUtil.TESTCOMMITTER, commitMessage);
+ op.execute(null);
+ }
+
+ protected static void setTestFileContent(String newContent)
+ throws Exception {
+ IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ PROJ1);
+ if (!prj.isAccessible())
+ throw new IllegalStateException("No project found");
+ IFile file = prj.getFile(new Path("folder/test.txt"));
+ file.setContents(new ByteArrayInputStream(newContent.getBytes(prj
+ .getDefaultCharset())), 0, null);
+ }
+
+ protected String getTestFileContent() throws Exception {
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
+ .getFile(new Path("folder/test.txt"));
+ if (file.exists()) {
+ byte[] bytes = new byte[0];
+ InputStream is = null;
+ try {
+ is = file.getContents();
+ bytes = new byte[is.available()];
+ is.read(bytes);
+ } finally {
+ if (is != null)
+ is.close();
+ }
+ return new String(bytes, file.getCharset());
+ } else {
+ return "";
+ }
+ }
+
+ /**
+ * @param projectExplorerTree
+ * @param project
+ * name of a project
+ * @return the project item pertaining to the project
+ */
+ protected SWTBotTreeItem getProjectItem(SWTBotTree projectExplorerTree,
+ String project) {
+ for (SWTBotTreeItem item : projectExplorerTree.getAllItems()) {
+ String itemText = item.getText();
+ StringTokenizer tok = new StringTokenizer(itemText, " ");
+ String name = tok.nextToken();
+ // may be a dirty marker
+ if (name.equals(">"))
+ name = tok.nextToken();
+ if (project.equals(name))
+ return item;
+ }
+ return null;
+ }
+
+ protected void pressAltAndChar(SWTBotShell shell, char charToPress) {
+ Display display = Display.getDefault();
+ Event evt = new Event();
+ // Alt down
+ evt.type = SWT.KeyDown;
+ evt.item = shell.widget;
+ evt.keyCode = SWT.ALT;
+ display.post(evt);
+ // G down
+ evt.keyCode = 0;
+ evt.character = charToPress;
+ display.post(evt);
+ // G up
+ evt.type = SWT.KeyUp;
+ display.post(evt);
+ // Alt up
+ evt.keyCode = SWT.ALT;
+ evt.character = ' ';
+ display.post(evt);
+ }
+
+ /**
+ * Activates the item by "pressing" ALT + the character after '&'
+ *
+ * @param shell
+ * @param itemWithShortcut
+ */
+ protected void activateItemByKeyboard(SWTBotShell shell,
+ String itemWithShortcut) {
+ int index = itemWithShortcut.indexOf('&');
+ if (index >= 0 && index < itemWithShortcut.length())
+ pressAltAndChar(shell, itemWithShortcut.charAt(index + 1));
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java
index 8e78f1c0a4..7329fb1409 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java
@@ -47,7 +47,7 @@ public class GlobalConfigurationPageTest {
private static final SWTWorkbenchBot bot = new SWTWorkbenchBot();
- private static final TestUtil util = TestUtil.getInstance();
+ private static final TestUtil util = new TestUtil();
private static FileBasedConfig config;
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllLocalTests.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllLocalTests.java
new file mode 100644
index 0000000000..b420533ca3
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllLocalTests.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Ketan Padegaonkar <KetanPadegaonkar@gmail.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.test;
+
+import org.eclipse.egit.ui.prefpages.configuration.GlobalConfigurationPageTest;
+import org.eclipse.egit.ui.test.history.HistoryViewTest;
+import org.eclipse.egit.ui.test.team.actions.AllTeamActionTests;
+import org.eclipse.egit.ui.view.repositories.AllRepositoriesViewTests;
+import org.eclipse.egit.ui.wizards.clone.GitCloneWizardTest;
+import org.eclipse.egit.ui.wizards.share.SharingWizardTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses( { AllRepositoriesViewTests.class, //
+ GlobalConfigurationPageTest.class, //
+ GitCloneWizardTest.class, //
+ SharingWizardTest.class, //
+ AllTeamActionTests.class, //
+ HistoryViewTest.class })
+public class AllLocalTests {
+ // empty class, don't need anything here
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllTests.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllTests.java
index fc5de0970b..52547ed083 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllTests.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/AllTests.java
@@ -8,21 +8,16 @@
*******************************************************************************/
package org.eclipse.egit.ui.test;
-import org.eclipse.egit.ui.prefpages.configuration.GlobalConfigurationPageTest;
-import org.eclipse.egit.ui.view.repositories.AllRepositoriesViewTests;
import org.eclipse.egit.ui.view.synchronize.SynchronizeViewTest;
-import org.eclipse.egit.ui.wizards.clone.GitCloneWizardTest;
-import org.eclipse.egit.ui.wizards.share.SharingWizardTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
-@SuiteClasses( { AllRepositoriesViewTests.class, //
- GitCloneWizardTest.class, //
- GlobalConfigurationPageTest.class, //
- SharingWizardTest.class, //
- SynchronizeViewTest.class })
+@SuiteClasses( { AllLocalTests.class, //
+ // these need an outside connection
+ SynchronizeViewTest.class, //
+})
public class AllTests {
// empty class, don't need anything here
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
index 366be1a778..d34d2d904f 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
@@ -24,13 +24,11 @@ import org.osgi.util.tracker.ServiceTracker;
*/
public class TestUtil {
- private static final char AMPERSAND = '&';
+ public static String TESTAUTHOR = "Test Author <test.author@test.com>";
- private static final TestUtil INSTANCE = new TestUtil();
+ public static String TESTCOMMITTER = "Test Committer <test.committer@test.com>";
- public static TestUtil getInstance() {
- return INSTANCE;
- }
+ private static final char AMPERSAND = '&';
private ResourceBundle myBundle;
@@ -41,7 +39,7 @@ public class TestUtil {
* in menu items and field labels for keyboard shortcuts) will be filtered
* out (see also {@link #getPluginLocalizedValue(String, boolean)} in order
* to be able to reference these fields using SWTBot).
- *
+ *
* @param key
* the key, must not be null
* @return the localized value in the current default {@link Locale}, or
@@ -57,7 +55,7 @@ public class TestUtil {
/**
* Allows access to the localized values of the EGit UI Plug-in
* <p>
- *
+ *
* @param key
* see {@link #getPluginLocalizedValue(String)}
* @param keepAmpersands
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
new file mode 100644
index 0000000000..a898f4892d
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/history/HistoryViewTest.java
@@ -0,0 +1,240 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.history;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+
+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.egit.ui.UIText;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarToggleButton;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the Team->Branch action
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class HistoryViewTest extends LocalRepositoryTestCase {
+ private static final String SECONDFOLDER = "secondFolder";
+
+ private static final String ADDEDFILE = "another.txt";
+
+ private static final String ADDEDMESSAGE = "A new file in a new folder";
+
+ private static SWTBotPerspective perspective;
+
+ private static int commitCount;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ // File repoFile =
+ createProjectAndCommitToRepository();
+ perspective = bot.activePerspective();
+ bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
+ 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);
+ addAndCommit(addedFile, ADDEDMESSAGE);
+ // TODO count the commits
+ commitCount = 3;
+ waitInUI();
+ }
+
+ @AfterClass
+ public static void shutdown() {
+ perspective.activate();
+ }
+
+ @Test
+ public void testOpenHistoryOnFileNoFilter() throws Exception {
+ initFilter(0);
+
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1).rowCount());
+ assertEquals("Wrong number of commits", commitCount - 1,
+ 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(PROJ2)
+ .rowCount());
+
+ 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));
+ }
+
+ @Test
+ public void testOpenHistoryOnFileRepoFilter() throws Exception {
+ initFilter(1);
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, FOLDER).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, FOLDER, FILE1).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, FOLDER, FILE2).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, SECONDFOLDER).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, SECONDFOLDER, ADDEDFILE).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ2).rowCount());
+ }
+
+ @Test
+ public void testOpenHistoryOnFileProjectFilter() throws Exception {
+ initFilter(2);
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, FOLDER).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, FOLDER, FILE1).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, FOLDER, FILE2).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, SECONDFOLDER).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, SECONDFOLDER, ADDEDFILE).rowCount());
+ assertEquals("Wrong number of commits", 1, getHistoryViewTable(PROJ2)
+ .rowCount());
+ }
+
+ @Test
+ public void testOpenHistoryOnFileFolderFilter() throws Exception {
+ initFilter(3);
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1).rowCount());
+ assertEquals("Wrong number of commits", commitCount,
+ getHistoryViewTable(PROJ1, FOLDER).rowCount());
+ assertEquals("Wrong number of commits", commitCount - 1,
+ getHistoryViewTable(PROJ1, FOLDER, FILE1).rowCount());
+ assertEquals("Wrong number of commits", commitCount - 1,
+ 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", commitCount,
+ getHistoryViewTable(PROJ2).rowCount());
+ }
+
+ /**
+ * @param filter
+ * 0: none, 1: repository, 2: project, 3: folder
+ */
+ private void initFilter(int filter) {
+ getHistoryViewTable(PROJ1);
+ SWTBotView view = bot
+ .viewById("org.eclipse.team.ui.GenericHistoryView");
+ SWTBotToolbarToggleButton folder = (SWTBotToolbarToggleButton) view
+ .toolbarButton(UIText.HistoryPage_ShowAllVersionsForFolder);
+ SWTBotToolbarToggleButton project = (SWTBotToolbarToggleButton) view
+ .toolbarButton(UIText.HistoryPage_ShowAllVersionsForProject);
+ SWTBotToolbarToggleButton repo = (SWTBotToolbarToggleButton) view
+ .toolbarButton(UIText.HistoryPage_ShowAllVersionsForRepo);
+ switch (filter) {
+ case 0:
+ if (folder.isChecked())
+ folder.click();
+ if (project.isChecked())
+ project.click();
+ if (repo.isChecked())
+ repo.click();
+ break;
+ case 1:
+ if (!repo.isChecked())
+ repo.click();
+ break;
+ case 2:
+ if (!project.isChecked())
+ project.click();
+ break;
+ case 3:
+ if (!folder.isChecked())
+ folder.click();
+ break;
+ default:
+ break;
+ }
+ }
+
+ @Test
+ public void testOpenHistoryOnProject() throws Exception {
+ SWTBotTable table = getHistoryViewTable(PROJ1);
+ int rowCount = table.rowCount();
+ assertTrue(table.rowCount() > 0);
+ assertEquals(table.getTableItem(rowCount - 1).getText(0),
+ "Initial commit");
+ }
+
+ @Test
+ public void testAddCommit() throws Exception {
+ String commitMessage = "The special commit";
+ int countBefore = getHistoryViewTable(PROJ1).rowCount();
+ touchAndSubmit(commitMessage);
+ 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));
+ }
+
+ /**
+ * @param path
+ * must be length 2 or three (folder or file)
+ * @return the bale
+ */
+ private SWTBotTable getHistoryViewTable(String... path) {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ if (path.length == 1)
+ getProjectItem(projectExplorerTree, path[0]).select();
+ else if (path.length == 2)
+ getProjectItem(projectExplorerTree, path[0]).expand().getNode(
+ path[1]).select();
+ else
+ getProjectItem(projectExplorerTree, path[0]).expand().getNode(
+ path[1]).expand().getNode(path[2]).select();
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Show In",
+ "History");
+ return bot.viewById("org.eclipse.team.ui.GenericHistoryView").bot()
+ .table();
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/AllTeamActionTests.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/AllTeamActionTests.java
new file mode 100644
index 0000000000..2019fd864a
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/AllTeamActionTests.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.team.actions;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses( { BranchAndResetActionTest.class, //
+ TagActionTest.class, //
+ CommitActionTest.class, //
+ PushActionTest.class, //
+ FetchAndMergeActionTest.class, //
+ DisconnectConnectTest.class //
+})
+public class AllTeamActionTests {
+ // nothing
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java
new file mode 100644
index 0000000000..3c694cf208
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/BranchAndResetActionTest.java
@@ -0,0 +1,238 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.team.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.egit.core.op.BranchOperation;
+import org.eclipse.egit.core.op.TagOperation;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider;
+import org.eclipse.egit.ui.internal.repository.tree.LocalBranchesNode;
+import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
+import org.eclipse.egit.ui.internal.repository.tree.TagsNode;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.Tag;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.utils.TableCollection;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the Team->Branch action
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class BranchAndResetActionTest extends LocalRepositoryTestCase {
+ private static File repositoryFile;
+
+ private static SWTBotPerspective perspective;
+
+ private static String LOCAL_BRANCHES;
+
+ private static String TAGS;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ repositoryFile = createProjectAndCommitToRepository();
+ Repository repo = lookupRepository(repositoryFile);
+ perspective = bot.activePerspective();
+ bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
+
+ Tag tag = new Tag(repo);
+ tag.setTag("SomeTag");
+ tag.setAuthor(new PersonIdent(TestUtil.TESTAUTHOR));
+ tag.setMessage("I'm just a little tag");
+ tag.setObjId(repo.resolve(repo.getFullBranch()));
+ TagOperation top = new TagOperation(repo, tag, false);
+ top.execute(null);
+ touchAndSubmit(null);
+
+ RepositoriesViewLabelProvider provider = new RepositoriesViewLabelProvider();
+ LOCAL_BRANCHES = provider.getText(new LocalBranchesNode(
+ new RepositoryNode(null, repo), repo));
+ TAGS = provider.getText(new TagsNode(new RepositoryNode(null, repo),
+ repo));
+ waitInUI();
+ }
+
+ @AfterClass
+ public static void shutdown() {
+ perspective.activate();
+ }
+
+ @Before
+ public void prepare() throws Exception {
+ Repository repo = lookupRepository(repositoryFile);
+ if (!repo.getBranch().equals("master")) {
+ BranchOperation bop = new BranchOperation(repo, "refs/heads/master");
+ bop.execute(null);
+ }
+ }
+
+ @Test
+ public void testCheckoutLocalBranches() throws Exception {
+ checkoutAndVerify(new String[] { LOCAL_BRANCHES, "master" },
+ new String[] { LOCAL_BRANCHES, "stable" });
+ checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" },
+ new String[] { LOCAL_BRANCHES, "master" });
+ }
+
+ @Test
+ public void testResetToLocalBranch() throws Exception {
+ checkoutAndVerify(new String[] { LOCAL_BRANCHES, "master" },
+ new String[] { LOCAL_BRANCHES, "stable" });
+ String stable = getTestFileContent();
+ checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" },
+ new String[] { LOCAL_BRANCHES, "master" });
+ String master = getTestFileContent();
+ assertFalse(stable.equals(master));
+ SWTBotShell resetDialog = openResetDialog();
+ resetDialog.bot().tree().getTreeItem(LOCAL_BRANCHES).getNode("stable")
+ .select();
+ activateItemByKeyboard(resetDialog,
+ UIText.ResetTargetSelectionDialog_ResetTypeHardButton);
+
+ resetDialog.bot().button(UIText.ResetTargetSelectionDialog_ResetButton)
+ .click();
+
+ bot.shell(UIText.ResetTargetSelectionDialog_ResetQuestion).bot()
+ .button(IDialogConstants.YES_LABEL).click();
+ waitInUI();
+ String reset = getTestFileContent();
+ assertEquals("Wrong content after reset", stable, reset);
+ }
+
+ @Test
+ public void testCreateBranch() throws Exception {
+ SWTBotShell dialog = openBranchDialog();
+ dialog.bot().button(UIText.BranchSelectionDialog_NewBranch).click();
+ SWTBotShell branchNameDialog = bot
+ .shell(UIText.BranchSelectionDialog_QuestionNewBranchTitle);
+ branchNameDialog.bot().text().setText("master");
+ assertFalse(branchNameDialog.bot().button(IDialogConstants.OK_LABEL)
+ .isEnabled());
+ branchNameDialog.bot().text().setText("NewBranch");
+ branchNameDialog.bot().button(IDialogConstants.OK_LABEL).click();
+
+ assertEquals("New Branch should be selected", "NewBranch", bot.tree()
+ .selection().get(0, 0));
+ bot.button(UIText.BranchSelectionDialog_OkCheckout).click();
+ waitInUI();
+ assertEquals("New Branch should be checked out", "NewBranch",
+ lookupRepository(repositoryFile).getBranch());
+ }
+
+ private SWTBotShell openBranchDialog() {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String menuString = util.getPluginLocalizedValue("BranchAction_label");
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ SWTBotShell dialog = bot.shell(NLS.bind(
+ UIText.BranchSelectionDialog_TitleCheckout, repositoryFile
+ .toString()));
+ return dialog;
+ }
+
+ private SWTBotShell openResetDialog() {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String menuString = util.getPluginLocalizedValue("ResetAction_label");
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ SWTBotShell dialog = bot
+ .shell(UIText.ResetTargetSelectionDialog_WindowTitle);
+ return dialog;
+ }
+
+ @Test
+ public void testRenameBranch() throws Exception {
+ SWTBotShell dialog = openBranchDialog();
+ dialog.bot().button(UIText.BranchSelectionDialog_NewBranch).click();
+ SWTBotShell branchNameDialog = bot
+ .shell(UIText.BranchSelectionDialog_QuestionNewBranchTitle);
+ branchNameDialog.bot().text().setText("master");
+ assertFalse(branchNameDialog.bot().button(IDialogConstants.OK_LABEL)
+ .isEnabled());
+ branchNameDialog.bot().text().setText("Unrenamed");
+ branchNameDialog.bot().button(IDialogConstants.OK_LABEL).click();
+
+ assertEquals("New Branch should be selected", "Unrenamed", bot.tree()
+ .selection().get(0, 0));
+
+ bot.button(UIText.BranchSelectionDialog_Rename).click();
+
+ branchNameDialog = bot
+ .shell(UIText.BranchSelectionDialog_QuestionNewBranchTitle);
+ assertFalse(branchNameDialog.bot().button(IDialogConstants.OK_LABEL)
+ .isEnabled());
+ branchNameDialog.bot().text().setText("Renamed");
+ bot.button(IDialogConstants.OK_LABEL).click();
+
+ bot.button(UIText.BranchSelectionDialog_OkCheckout).click();
+ waitInUI();
+ assertEquals("New Branch should be checked out", "Renamed",
+ lookupRepository(repositoryFile).getBranch());
+ }
+
+ @Test
+ public void testCheckoutTags() throws Exception {
+ checkoutAndVerify(new String[] { LOCAL_BRANCHES, "master" },
+ new String[] { TAGS, "SomeTag" });
+ }
+
+ private void checkoutAndVerify(String[] currentBranch, String[] newBranch)
+ throws IOException, Exception {
+ SWTBotShell dialog = openBranchDialog();
+ TableCollection tc = dialog.bot().tree().selection();
+ assertEquals("Wrong selection count", 1, tc.rowCount());
+ assertEquals("Wrong item selected", currentBranch[1], tc.get(0, 0));
+
+ dialog.bot().tree().getTreeItem(newBranch[0]).expand().getNode(
+ newBranch[1]).select();
+ tc = dialog.bot().tree().selection();
+ assertEquals("Wrong selection count", 1, tc.rowCount());
+ assertEquals("Wrong item selected", newBranch[1], tc.get(0, 0));
+
+ Repository repo = lookupRepository(repositoryFile);
+
+ dialog.bot().button(UIText.BranchSelectionDialog_OkCheckout).click();
+ waitInUI();
+ if (ObjectId.isId(repo.getBranch())) {
+ String mapped = Activator.getDefault().getRepositoryUtil()
+ .mapCommitToRef(repo, repo.getBranch(), false);
+ assertEquals("Wrong branch", newBranch[1], mapped.substring(mapped
+ .lastIndexOf('/') + 1));
+ } else
+ assertEquals("Wrong branch", newBranch[1], repo.getBranch());
+ }
+
+}
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
new file mode 100644
index 0000000000..d7ead586e9
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CommitActionTest.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.team.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.core.op.BranchOperation;
+import org.eclipse.egit.core.op.TagOperation;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.Tag;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the Team->Commit action
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class CommitActionTest extends LocalRepositoryTestCase {
+ private static File repositoryFile;
+
+ private static SWTBotPerspective perspective;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ repositoryFile = createProjectAndCommitToRepository();
+ Repository repo = lookupRepository(repositoryFile);
+ // TODO delete the second project for the time being (.gitignore is
+ // currently not hiding the .project file from commit)
+ ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2).delete(
+ false, null);
+
+ Tag tag = new Tag(repo);
+ tag.setTag("SomeTag");
+ tag.setAuthor(new PersonIdent(TestUtil.TESTAUTHOR));
+ tag.setMessage("I'm just a little tag");
+ tag.setObjId(repo.resolve(repo.getFullBranch()));
+ TagOperation top = new TagOperation(repo, tag, false);
+ top.execute(null);
+ touchAndSubmit(null);
+
+ perspective = bot.activePerspective();
+ bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
+ waitInUI();
+ }
+
+ @AfterClass
+ public static void shutdown() {
+ perspective.activate();
+ }
+
+ @Before
+ public void prepare() throws Exception {
+ Repository repo = lookupRepository(repositoryFile);
+ if (!repo.getBranch().equals("master")) {
+ BranchOperation bop = new BranchOperation(repo, "refs/heads/master");
+ bop.execute(null);
+ }
+ }
+
+ @Test
+ public void testOpenCommitWithoutChanged() throws Exception {
+ clickOnCommit();
+ bot.shell(UIText.CommitAction_noFilesToCommit).close();
+ }
+
+ @Test
+ public void testCommitSingleFile() throws Exception {
+ setTestFileContent("I have changed this");
+ clickOnCommit();
+ SWTBotShell commitDialog = bot.shell(UIText.CommitDialog_CommitChanges);
+ assertEquals("Wrong row count", 1, commitDialog.bot().table()
+ .rowCount());
+ assertTrue("Wrong file", commitDialog.bot().table().getTableItem(0)
+ .getText(1).endsWith("test.txt"));
+ commitDialog.bot().textWithLabel(UIText.CommitDialog_Author).setText(
+ TestUtil.TESTAUTHOR);
+ commitDialog.bot().textWithLabel(UIText.CommitDialog_Committer)
+ .setText(TestUtil.TESTCOMMITTER);
+ commitDialog.bot().textWithLabel(UIText.CommitDialog_CommitMessage)
+ .setText("The new commit");
+ commitDialog.bot().button(UIText.CommitDialog_Commit).click();
+ testOpenCommitWithoutChanged();
+ }
+
+ private void clickOnCommit() throws Exception {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String menuString = util.getPluginLocalizedValue("CommitAction_label");
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/DisconnectConnectTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/DisconnectConnectTest.java
new file mode 100644
index 0000000000..3561fccedd
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/DisconnectConnectTest.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.team.actions;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the Team->Fetch and Team->Merge actions
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class DisconnectConnectTest extends LocalRepositoryTestCase {
+
+ private static SWTBotPerspective perspective;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ createProjectAndCommitToRepository();
+ perspective = bot.activePerspective();
+ bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
+ waitInUI();
+ }
+
+ @AfterClass
+ public static void shutdown() {
+ perspective.activate();
+ }
+
+ @Test
+ public void testDisconnectAndReconnect() throws Exception {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ PROJ1);
+ RepositoryMapping mapping = RepositoryMapping.getMapping(project);
+ assertNotNull(mapping);
+ clickOnDisconnect();
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(
+ IResource.DEPTH_INFINITE, null);
+ waitInUI();
+ mapping = RepositoryMapping.getMapping(project);
+ assertNull(mapping);
+ SWTBotShell connectDialog = openConnectDialog();
+ connectDialog.bot().tree().getAllItems()[0].select();
+ connectDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(
+ IResource.DEPTH_INFINITE, null);
+ waitInUI();
+ mapping = RepositoryMapping.getMapping(project);
+ assertNotNull(mapping);
+ }
+
+ private void clickOnDisconnect() throws Exception {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String menuString = util
+ .getPluginLocalizedValue("DisconnectAction_label");
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ }
+
+ private SWTBotShell openConnectDialog() throws Exception {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String menuString = "Share Project...";
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ bot.shell("Share Project").bot().table().getTableItem("Git").select();
+ bot.button(IDialogConstants.NEXT_LABEL).click();
+ return bot.shell(UIText.SharingWizard_windowTitle);
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java
new file mode 100644
index 0000000000..e8484c258a
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/FetchAndMergeActionTest.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.team.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider;
+import org.eclipse.egit.ui.internal.repository.tree.RemoteBranchesNode;
+import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the Team->Fetch and Team->Merge actions
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class FetchAndMergeActionTest extends LocalRepositoryTestCase {
+ private static File repositoryFile;
+
+ private static File childRepositoryFile;
+
+ private static SWTBotPerspective perspective;
+
+ private static String REMOTE_BRANCHES;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ repositoryFile = createProjectAndCommitToRepository();
+ childRepositoryFile = createChildRepository(repositoryFile);
+ perspective = bot.activePerspective();
+ bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
+ RepositoriesViewLabelProvider provider = new RepositoriesViewLabelProvider();
+ Repository repo = lookupRepository(childRepositoryFile);
+ REMOTE_BRANCHES = provider.getText(new RemoteBranchesNode(
+ new RepositoryNode(null, repo), repo));
+ }
+
+ @AfterClass
+ public static void shutdown() {
+ perspective.activate();
+ }
+
+ private String prepare() throws Exception {
+ deleteAllProjects();
+ shareProjects(repositoryFile);
+ Repository repo = lookupRepository(repositoryFile);
+ RevWalk rw = new RevWalk(repo);
+ ObjectId id = repo.resolve(repo.getFullBranch());
+ String commitId = rw.parseCommit(id).asCommit(rw).getCommitId().name();
+ touchAndSubmit(null);
+ deleteAllProjects();
+ shareProjects(childRepositoryFile);
+ waitInUI();
+ return commitId;
+ }
+
+ @Test
+ public void testFetchFromOriginThenMerge() throws Exception {
+ String previousCommit = prepare();
+ String oldContent = getTestFileContent();
+ SWTBotShell fetchDialog = openFetchDialog();
+ fetchDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
+ fetchDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
+ SWTBotShell confirm = bot.shell(NLS.bind(
+ UIText.FetchResultDialog_title, "origin"));
+ SWTBotTable table = confirm.bot().table();
+ String branch = table.getTableItem(0).getText(2);
+ assertTrue("Wrong result", previousCommit.startsWith(branch.substring(
+ 0, 7)));
+
+ confirm.close();
+
+ String newContent = getTestFileContent();
+ assertEquals(oldContent, newContent);
+
+ fetchDialog = openFetchDialog();
+ fetchDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
+ fetchDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
+ confirm = bot.shell(NLS.bind(UIText.FetchResultDialog_title, "origin"));
+ int count = confirm.bot().table().rowCount();
+
+ confirm.close();
+
+ assertEquals("Wrong result count", 0, count);
+
+ newContent = getTestFileContent();
+ assertEquals(oldContent, newContent);
+
+ SWTBotShell mergeDialog = openMergeDialog();
+
+ mergeDialog.bot().tree().getTreeItem(REMOTE_BRANCHES).expand().getNode(
+ "origin/master").select();
+ mergeDialog.bot().button(UIText.MergeTargetSelectionDialog_ButtonMerge)
+ .click();
+ bot.shell(UIText.MergeAction_MergeResultTitle).close();
+ newContent = getTestFileContent();
+ assertFalse(oldContent.equals(newContent));
+ }
+
+ private SWTBotShell openFetchDialog() throws Exception {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String menuString = util.getPluginLocalizedValue("FetchAction_label");
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ SWTBotShell dialog = bot.shell(UIText.FetchWizard_windowTitleDefault);
+ return dialog;
+ }
+
+ private SWTBotShell openMergeDialog() throws Exception {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String menuString = util.getPluginLocalizedValue("MergeAction_label");
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ Repository repo = lookupRepository(childRepositoryFile);
+ SWTBotShell dialog = bot.shell(NLS.bind(
+ UIText.MergeTargetSelectionDialog_TitleMerge, repo
+ .getDirectory().toString()));
+ return dialog;
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/PushActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/PushActionTest.java
new file mode 100644
index 0000000000..da5566f112
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/PushActionTest.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.team.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jgit.errors.IncorrectObjectTypeException;
+import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the Team->Push action
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class PushActionTest extends LocalRepositoryTestCase {
+ private static File repositoryFile;
+
+ private static File remoteRepositoryFile;
+
+ private static SWTBotPerspective perspective;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ perspective = bot.activePerspective();
+ bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
+ repositoryFile = createProjectAndCommitToRepository();
+ remoteRepositoryFile = createRemoteRepository(repositoryFile);
+ touchAndSubmit(null);
+ waitInUI();
+ }
+
+ @AfterClass
+ public static void shutdown() {
+ perspective.activate();
+ }
+
+ @Test
+ public void testPushToBothDestination() throws Exception {
+ pushTo("both", true);
+ pushTo("both", false);
+ }
+
+ @Test
+ @Ignore
+ // TODO fails because of a NPE
+ public void testPushToPushDestination() throws Exception {
+ pushTo("push", true);
+ pushTo("push", false);
+ }
+
+ private void pushTo(String destination, boolean withConfirmPage)
+ throws Exception, MissingObjectException,
+ IncorrectObjectTypeException, IOException {
+ Repository repo = lookupRepository(remoteRepositoryFile);
+ RevWalk rw = new RevWalk(repo);
+ String previous = rw.parseCommit(repo.resolve("HEAD")).asCommit(rw)
+ .getCommitId().name();
+
+ touchAndSubmit(null);
+ SWTBotShell pushDialog = openPushDialog();
+
+ SWTBotCombo destinationCombo = pushDialog.bot().comboBox();
+ String[] items = destinationCombo.items();
+ for (int i = 0; i < items.length; i++) {
+ if (items[i].startsWith(destination))
+ destinationCombo.setSelection(i);
+ }
+
+ pushDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
+ if (withConfirmPage)
+ pushDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
+ pushDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
+ SWTBotShell confirm = bot.shell(NLS.bind(UIText.ResultDialog_title,
+ destination));
+ String result = confirm.bot().table().getTableItem(0).getText(3);
+
+ assertTrue("Wrong result", previous.startsWith(result.substring(0, 7)));
+
+ confirm.close();
+
+ pushDialog = openPushDialog();
+
+ destinationCombo = pushDialog.bot().comboBox();
+ for (int i = 0; i < items.length; i++) {
+ if (items[i].startsWith(destination))
+ destinationCombo.setSelection(i);
+ }
+
+ pushDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
+ if (withConfirmPage)
+ pushDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
+ pushDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
+ confirm = bot.shell(NLS.bind(UIText.ResultDialog_title, destination));
+ result = confirm.bot().table().getTableItem(0).getText(3);
+
+ confirm.close();
+
+ assertEquals("Wrong result", UIText.PushResultTable_statusUpToDate,
+ result);
+ }
+
+ private SWTBotShell openPushDialog() throws Exception {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String menuString = util.getPluginLocalizedValue("PushAction_label");
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ SWTBotShell dialog = bot.shell(UIText.PushWizard_windowTitleDefault);
+ return dialog;
+ }
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java
new file mode 100644
index 0000000000..e6c0dbe184
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.team.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.egit.core.op.BranchOperation;
+import org.eclipse.egit.core.op.TagOperation;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.test.ContextMenuHelper;
+import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.Tag;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for the Team->Tag action
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class TagActionTest extends LocalRepositoryTestCase {
+ private static File repositoryFile;
+
+ private static SWTBotPerspective perspective;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ perspective = bot.activePerspective();
+ bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
+
+ repositoryFile = createProjectAndCommitToRepository();
+ Repository repo = lookupRepository(repositoryFile);
+
+ Tag tag = new Tag(repo);
+ tag.setTag("SomeTag");
+ tag.setAuthor(new PersonIdent(TestUtil.TESTAUTHOR));
+ tag.setMessage("I'm just a little tag");
+ tag.setObjId(repo.resolve(repo.getFullBranch()));
+ TagOperation top = new TagOperation(repo, tag, false);
+ top.execute(null);
+ touchAndSubmit(null);
+ waitInUI();
+ }
+
+ @AfterClass
+ public static void shutdown() {
+ perspective.activate();
+ }
+
+ @Before
+ public void prepare() throws Exception {
+ Repository repo = lookupRepository(repositoryFile);
+ if (!repo.getBranch().equals("master")) {
+ BranchOperation bop = new BranchOperation(repo, "refs/heads/master");
+ bop.execute(null);
+ }
+ }
+
+ @Test
+ public void testTagDialogShowExistingTags() throws Exception {
+ SWTBotShell tagDialog = openTagDialog();
+ int index = tagDialog.bot().tableWithLabel(
+ UIText.CreateTagDialog_existingTags).indexOf("SomeTag");
+ assertTrue("Tag is not showing", index >= 0);
+ }
+
+ @Test
+ public void testCreateTag() throws Exception {
+ SWTBotShell tagDialog = openTagDialog();
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName).setText(
+ "SomeTag");
+ assertFalse("Ok should be disabled", tagDialog.bot().button(
+ IDialogConstants.OK_LABEL).isEnabled());
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName).setText(
+ "AnotherTag");
+ assertFalse("Ok should be disabled", tagDialog.bot().button(
+ IDialogConstants.OK_LABEL).isEnabled());
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagMessage)
+ .setText("Here's the message text");
+ tagDialog.bot().button(IDialogConstants.OK_LABEL).click();
+ assertTrue(lookupRepository(repositoryFile).getTags().keySet()
+ .contains("AnotherTag"));
+ }
+
+ private SWTBotShell openTagDialog() throws Exception {
+ SWTBotTree projectExplorerTree = bot.viewById(
+ "org.eclipse.jdt.ui.PackageExplorer").bot().tree();
+ getProjectItem(projectExplorerTree, PROJ1).select();
+ String menuString = util.getPluginLocalizedValue("TagAction_label");
+ ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
+ menuString);
+ String branchName = lookupRepository(repositoryFile).getBranch();
+ SWTBotShell dialog = bot.shell(NLS.bind(
+ UIText.CreateTagDialog_questionNewTagTitle, branchName));
+ return dialog;
+ }
+
+ @Test
+ public void testChangeTagMessage() throws Exception {
+ SWTBotShell tagDialog = openTagDialog();
+ assertFalse("Ok should be disabled", tagDialog.bot().button(
+ IDialogConstants.OK_LABEL).isEnabled());
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName).setText(
+ "MessageChangeTag");
+ assertFalse("Ok should be disabled", tagDialog.bot().button(
+ IDialogConstants.OK_LABEL).isEnabled());
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagMessage)
+ .setText("Here's the first message");
+ tagDialog.bot().button(IDialogConstants.OK_LABEL).click();
+ waitInUI();
+ assertTrue(lookupRepository(repositoryFile).getTags().keySet()
+ .contains("MessageChangeTag"));
+ tagDialog = openTagDialog();
+ tagDialog.bot().tableWithLabel(UIText.CreateTagDialog_existingTags)
+ .getTableItem("MessageChangeTag").select();
+ assertFalse("Ok should be disabled", tagDialog.bot().button(
+ IDialogConstants.OK_LABEL).isEnabled());
+ String oldText = tagDialog.bot().textWithLabel(
+ UIText.CreateTagDialog_tagMessage).getText();
+ assertEquals("Wrong message text", "Here's the first message", oldText);
+ tagDialog.bot().checkBox(UIText.CreateTagDialog_overwriteTag).click();
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagMessage)
+ .setText("New message");
+ tagDialog.bot().button(IDialogConstants.OK_LABEL).click();
+ tagDialog = openTagDialog();
+ tagDialog.bot().tableWithLabel(UIText.CreateTagDialog_existingTags)
+ .getTableItem("MessageChangeTag").select();
+ String newText = tagDialog.bot().textWithLabel(
+ UIText.CreateTagDialog_tagMessage).getText();
+ assertEquals("Wrong message text", "New message", newText);
+ tagDialog.close();
+ }
+
+}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
index 35ce2f6977..0a0edf1fcd 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
@@ -20,6 +20,7 @@ import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
@@ -28,6 +29,7 @@ import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
@@ -83,8 +85,8 @@ public class GitRepositoriesViewBranchHandlingTest extends
repositoryFile);
refreshAndWait();
final SWTBotView view = getOrOpenView();
- SWTBotTreeItem localItem = getLocalBranchesItem(view.bot().tree(),
- repositoryFile);
+ SWTBotTreeItem localItem = myRepoViewUtil.getLocalBranchesItem(view
+ .bot().tree(), repositoryFile);
localItem.expand();
assertEquals("Wrong number of children", 1, localItem.getNodes().size());
@@ -105,7 +107,8 @@ public class GitRepositoriesViewBranchHandlingTest extends
getOrOpenView().toolbarButton("Refresh").click();
refreshAndWait();
- localItem = getLocalBranchesItem(view.bot().tree(), repositoryFile);
+ localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(),
+ repositoryFile);
localItem.expand();
assertEquals("Wrong number of children", 2, localItem.getNodes().size());
@@ -131,7 +134,7 @@ public class GitRepositoriesViewBranchHandlingTest extends
ContextMenuHelper.clickContextMenu(view.bot().tree(), myUtil
.getPluginLocalizedValue("CheckoutCommand"));
localItem.getNode(1).select();
-
+ waitInUI();
ContextMenuHelper.clickContextMenu(bot.tree(), myUtil
.getPluginLocalizedValue("DeleteBranchCommand"));
SWTBotShell confirmPopup = bot
@@ -139,7 +142,8 @@ public class GitRepositoriesViewBranchHandlingTest extends
confirmPopup.activate();
confirmPopup.bot().button(IDialogConstants.OK_LABEL).click();
refreshAndWait();
- localItem = getLocalBranchesItem(view.bot().tree(), repositoryFile);
+ localItem = myRepoViewUtil.getLocalBranchesItem(view.bot().tree(),
+ repositoryFile);
localItem.expand();
assertEquals("Wrong number of children", 1, localItem.getNodes().size());
}
@@ -152,13 +156,14 @@ public class GitRepositoriesViewBranchHandlingTest extends
SWTBotTree tree = getOrOpenView().bot().tree();
- SWTBotTreeItem item = getLocalBranchesItem(tree, clonedRepositoryFile)
- .expand();
+ SWTBotTreeItem item = myRepoViewUtil.getLocalBranchesItem(tree,
+ clonedRepositoryFile).expand();
List<String> children = item.getNodes();
assertEquals("Wrong number of local children", 1, children.size());
- item = getRemoteBranchesItem(tree, clonedRepositoryFile).expand();
+ item = myRepoViewUtil.getRemoteBranchesItem(tree, clonedRepositoryFile)
+ .expand();
children = item.getNodes();
assertEquals("Wrong number of children", 2, children.size());
assertTrue("Missing remote branch", children.contains("origin/master"));
@@ -171,7 +176,8 @@ public class GitRepositoriesViewBranchHandlingTest extends
assertEquals("stable", shell.bot().text(1).getText());
shell.bot().button(IDialogConstants.FINISH_LABEL).click();
refreshAndWait();
- item = getLocalBranchesItem(tree, clonedRepositoryFile).expand();
+ item = myRepoViewUtil.getLocalBranchesItem(tree, clonedRepositoryFile)
+ .expand();
children = item.getNodes();
assertEquals("Wrong number of local children", 2, children.size());
@@ -190,24 +196,22 @@ public class GitRepositoriesViewBranchHandlingTest extends
shareProjects(clonedRepositoryFile);
refreshAndWait();
+ Repository repo = lookupRepository(clonedRepositoryFile);
+ BranchOperation bop = new BranchOperation(repo, "refs/heads/master");
+ bop.execute(null);
+
+ assertEquals("master", repo.getBranch());
SWTBotTree tree = getOrOpenView().bot().tree();
- SWTBotTreeItem item = getLocalBranchesItem(tree,
+ SWTBotTreeItem item = myRepoViewUtil.getLocalBranchesItem(tree,
clonedRepositoryFile).expand();
- List<String> children = item.getNodes();
- assertEquals("Wrong number of local children", 2, children.size());
-
- // make sure to checkout master
- item.getNode(0).select();
- ContextMenuHelper.clickContextMenu(tree, myUtil
- .getPluginLocalizedValue("CheckoutCommand"));
- refreshAndWait();
- touchAndSubmit();
+ touchAndSubmit(null);
refreshAndWait();
- item = getRemoteBranchesItem(tree, clonedRepositoryFile).expand();
- children = item.getNodes();
+ item = myRepoViewUtil.getRemoteBranchesItem(tree,
+ clonedRepositoryFile).expand();
+ List<String> children = item.getNodes();
assertEquals("Wrong number of remote children", 2, children.size());
final boolean[] done = new boolean[] { false };
@@ -238,6 +242,7 @@ public class GitRepositoriesViewBranchHandlingTest extends
break;
Thread.sleep(10);
}
+ assertTrue("Job should be completed", done[0]);
GitLightweightDecorator.refresh();
@@ -245,7 +250,8 @@ public class GitRepositoriesViewBranchHandlingTest extends
.isId(lookupRepository(clonedRepositoryFile).getBranch()));
// now let's try to create a local branch from the remote one
- item = getRemoteBranchesItem(tree, clonedRepositoryFile).expand();
+ item = myRepoViewUtil.getRemoteBranchesItem(tree,
+ clonedRepositoryFile).expand();
item.getNode("origin/stable").select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("CreateBranchCommand"));
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java
index 24f30520e1..45fd60f688 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewFetchAndPushTest.java
@@ -95,8 +95,8 @@ public class GitRepositoriesViewFetchAndPushTest extends
repository.getConfig().setString("remote", "origin", "push",
"refs/heads/*:refs/remotes/origin/*");
- getRemotesItem(tree, clonedRepositoryFile).expand().getNode("origin")
- .expand().getNode(1).select();
+ myRepoViewUtil.getRemotesItem(tree, clonedRepositoryFile).expand().getNode(
+ "origin").expand().getNode(1).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("SimplePushCommand"));
@@ -121,8 +121,8 @@ public class GitRepositoriesViewFetchAndPushTest extends
confirmed.close();
assertTrue("New branch expected", newBranch);
// second time: expect up to date
- getRemotesItem(tree, clonedRepositoryFile).expand().getNode("origin")
- .expand().getNode(1).select();
+ myRepoViewUtil.getRemotesItem(tree, clonedRepositoryFile).expand().getNode(
+ "origin").expand().getNode(1).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("SimplePushCommand"));
@@ -143,10 +143,10 @@ public class GitRepositoriesViewFetchAndPushTest extends
String objectIdBefore = repository.getRef("refs/heads/master")
.getLeaf().getObjectId().name();
objectIdBefore = objectIdBefore.substring(0, 7);
- touchAndSubmit();
+ touchAndSubmit(null);
- getRemotesItem(tree, clonedRepositoryFile).expand().getNode("origin")
- .expand().getNode(1).select();
+ myRepoViewUtil.getRemotesItem(tree, clonedRepositoryFile).expand().getNode(
+ "origin").expand().getNode(1).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("SimplePushCommand"));
@@ -188,8 +188,8 @@ public class GitRepositoriesViewFetchAndPushTest extends
String dialogTitle = NLS.bind(UIText.FetchResultDialog_title,
destinationString);
- getRemotesItem(tree, clonedRepositoryFile).expand().getNode("origin")
- .expand().getNode(0).select();
+ myRepoViewUtil.getRemotesItem(tree, clonedRepositoryFile).expand().getNode(
+ "origin").expand().getNode(0).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("SimpleFetchCommand"));
@@ -203,7 +203,7 @@ public class GitRepositoriesViewFetchAndPushTest extends
String objid = repository.getRef("refs/heads/master").getTarget()
.getObjectId().name();
objid = objid.substring(0, 7);
- touchAndSubmit();
+ touchAndSubmit(null);
// push from other repository
PushConfiguredRemoteAction action = new PushConfiguredRemoteAction(
repository, "origin");
@@ -222,8 +222,8 @@ public class GitRepositoriesViewFetchAndPushTest extends
refreshAndWait();
- getRemotesItem(tree, clonedRepositoryFile).expand().getNode("origin")
- .expand().getNode(0).select();
+ myRepoViewUtil.getRemotesItem(tree, clonedRepositoryFile).expand().getNode(
+ "origin").expand().getNode(0).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("SimpleFetchCommand"));
@@ -238,8 +238,8 @@ public class GitRepositoriesViewFetchAndPushTest extends
assertTrue(found);
confirm.close();
- getRemotesItem(tree, clonedRepositoryFile).expand().getNode("origin")
- .expand().getNode(0).select();
+ myRepoViewUtil.getRemotesItem(tree, clonedRepositoryFile).expand().getNode(
+ "origin").expand().getNode(0).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("SimpleFetchCommand"));
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRemoteHandlingTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRemoteHandlingTest.java
index c80029fce2..f7c9f88e31 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRemoteHandlingTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewRemoteHandlingTest.java
@@ -51,6 +51,7 @@ public class GitRepositoriesViewRemoteHandlingTest extends
/**
* Verify that remote configuration is shown correctly; also check error
* node display
+ *
* @throws Exception
*/
@Test
@@ -59,8 +60,8 @@ public class GitRepositoriesViewRemoteHandlingTest extends
removeRemotesConfig(repositoryFile);
refreshAndWait();
SWTBotTree tree = getOrOpenView().bot().tree();
- SWTBotTreeItem remotesItem = getRemotesItem(tree, repositoryFile)
- .expand();
+ SWTBotTreeItem remotesItem = myRepoViewUtil.getRemotesItem(tree,
+ repositoryFile).expand();
assertEquals("Wrong number of remotes", 0, remotesItem.getNodes()
.size());
RepositoryConfig cfg = lookupRepository(repositoryFile).getConfig();
@@ -77,11 +78,11 @@ public class GitRepositoriesViewRemoteHandlingTest extends
cfg.save();
cfg.load();
refreshAndWait();
- remotesItem = getRemotesItem(tree, repositoryFile).expand();
+ remotesItem = myRepoViewUtil.getRemotesItem(tree, repositoryFile).expand();
assertEquals("Wrong number of remotes", 3, remotesItem.getNodes()
.size());
- remotesItem = getRemotesItem(tree, repositoryFile).expand();
+ remotesItem = myRepoViewUtil.getRemotesItem(tree, repositoryFile).expand();
List<String> testnodes = remotesItem.getNode("test").expand()
.getNodes();
assertTrue(testnodes.size() == 1);
@@ -103,164 +104,171 @@ public class GitRepositoriesViewRemoteHandlingTest extends
removeRemotesConfig(repositoryFile);
refreshAndWait();
- remotesItem = getRemotesItem(tree, repositoryFile).expand();
+ remotesItem = myRepoViewUtil.getRemotesItem(tree, repositoryFile).expand();
assertEquals("Wrong number of remotes", 0, remotesItem.getNodes()
.size());
}
/**
* Remote configuration scenarios
+ *
* @throws Exception
*/
@Test
- @Ignore // TODO does not compile currently
+ @Ignore
+ // TODO does not compile currently
public void testConfigureRemote() throws Exception {
-// removeRemotesConfig(repositoryFile);
-// refreshAndWait();
-// SWTBotTree tree = getOrOpenView().bot().tree();
-// SWTBotTreeItem remotesItem = getRemotesItem(tree, repositoryFile)
-// .expand();
-//
-// remotesItem = getRemotesItem(tree, repositoryFile).expand();
-// remotesItem.select();
-// ContextMenuHelper.clickContextMenu(tree, myUtil
-// .getPluginLocalizedValue("NewRemoteCommand"));
-// SWTBotShell shell = bot
-// .shell(UIText.ConfigureRemoteWizard_WizardTitle_New);
-// shell.bot().textWithLabel(UIText.SelectRemoteNamePage_RemoteNameLabel)
-// .setText("testRemote");
-// // for some reason the label-based widget getters don't work
-// // configure fetch is 0
-// shell.bot().checkBox(0).select();
-// // configure push is 0
-// shell.bot().checkBox(1).select();
-// // next is 1
-// shell.bot().button(1).click();
-// // change is 0
-// shell.bot().button(0).click();
-// shell = bot.shell(UIText.SelectUriWiazrd_Title);
-// shell.bot().text().setText("file:///" + remoteRepositoryFile.getPath());
-// // finish is 1
-// shell.bot().button(1).click();
-// shell = bot.shell(UIText.ConfigureRemoteWizard_WizardTitle_New);
-// // next is 2
-// shell.bot().button(2).click();
-// // add all branches spec is 2
-// shell.bot().button(2).click();
-// // next is 7
-// shell.bot().button(7).click();
-// // the URIish-like path
-// String testString = new org.eclipse.jgit.transport.URIish("file:///"
-// + remoteRepositoryFile.getPath()).toPrivateString();
-// assertEquals(testString, shell.bot().text().getText());
-// // add is 0
-// shell.bot().toolbarButton(0).click();
-// shell = bot.shell(UIText.SelectUriWiazrd_Title);
-// shell.bot().text().setText("file:///" + remoteRepositoryFile.getPath());
-// // finish is 1
-// shell.bot().button(1).click();
-// // duplicate
-// shell = bot.shell(UIText.ConfigureUriPage_DuplicateUriTitle);
-// shell.close();
-// shell = bot.shell(UIText.ConfigureRemoteWizard_WizardTitle_New);
-// shell.bot().button(1).click();
-// // add all branches spec is 3
-// shell.bot().button(3).click();
-// // finish i 9
-// shell.bot().button(9).click();
-// refreshAndWait();
-// // assert 2 children
-// SWTBotTreeItem item = getRemotesItem(tree, repositoryFile).expand()
-// .getNode("testRemote").expand();
-// List<String> children = item.getNodes();
-// assertTrue(children.size() == 2);
-// item.getNode(0).select();
-// ContextMenuHelper.clickContextMenu(tree, myUtil
-// .getPluginLocalizedValue("RemoveFetchCommand"));
-// refreshAndWait();
-// // assert 1 children
-// item = getRemotesItem(tree, repositoryFile).expand().getNode(
-// "testRemote").expand();
-// children = item.getNodes();
-// assertTrue(children.size() == 1);
-// item.getNode(0).select();
-// ContextMenuHelper.clickContextMenu(tree, myUtil
-// .getPluginLocalizedValue("RemovePushCommand"));
-// refreshAndWait();
-// // assert 0 children
-// item = getRemotesItem(tree, repositoryFile).expand().getNode(
-// "testRemote").expand();
-// children = item.getNodes();
-// assertTrue(children.size() == 0);
-//
-// getRemotesItem(tree, repositoryFile).expand().getNode("testRemote")
-// .select();
-// String shellText = NLS.bind(
-// UIText.ConfigureRemoteWizard_WizardTitle_Change, "testRemote");
-//
-// ContextMenuHelper.clickContextMenu(tree, myUtil
-// .getPluginLocalizedValue("ConfigureFetchCommand"));
-// shell = bot.shell(shellText);
-// // change is 0
-// shell.bot().button(0).click();
-// shell = bot.shell(UIText.SelectUriWiazrd_Title);
-// shell.bot().text().setText("file:///" + remoteRepositoryFile.getPath());
-// // finish is 1
-// shell.bot().button(1).click();
-// shell = bot.shell(shellText);
-// // next is 2
-// shell.bot().button(2).click();
-// // add all branches spec is 2
-// shell.bot().button(2).click();
-// // finish is 8
-// shell.bot().button(8).click();
-// refreshAndWait();
-// // assert 1 children
-// item = getRemotesItem(tree, repositoryFile).expand().getNode(
-// "testRemote").expand();
-// children = item.getNodes();
-// assertTrue(children.size() == 1);
-//
-// ContextMenuHelper.clickContextMenu(tree, myUtil
-// .getPluginLocalizedValue("ConfigurePushCommand"));
-// shell = bot.shell(shellText);
-//
-// shell.bot().toolbarButton(0).click();
-// shell = bot.shell(UIText.SelectUriWiazrd_Title);
-// shell.bot().text().setText("file:///" + remoteRepositoryFile.getPath());
-// // finish is 1
-// shell.bot().button(1).click();
-// shell = bot.shell(shellText);
-// shell.bot().button(1).click();
-// // add all branches spec is 3
-// shell.bot().button(3).click();
-// // finish i 9
-// shell.bot().button(9).click();
-// refreshAndWait();
-// // assert 2 children
-// item = getRemotesItem(tree, repositoryFile).expand().getNode(
-// "testRemote").expand();
-// children = item.getNodes();
-// assertTrue(children.size() == 2);
-// item.select();
-// ContextMenuHelper.clickContextMenu(tree, myUtil
-// .getPluginLocalizedValue("RemoveRemoteCommand"));
-// shell = bot.shell(UIText.RepositoriesView_ConfirmDeleteRemoteHeader);
-// shell.bot().button(1).click();
-//
-// refreshAndWait();
-// // assert 2 children
-// item = getRemotesItem(tree, repositoryFile).expand().getNode(
-// "testRemote").expand();
-// children = item.getNodes();
-// assertTrue(children.size() == 2);
-//
-// ContextMenuHelper.clickContextMenu(tree, myUtil
-// .getPluginLocalizedValue("RemoveRemoteCommand"));
-// bot.shell(UIText.RepositoriesView_ConfirmDeleteRemoteHeader).bot()
-// .button(0).click();
-// refreshAndWait();
-// assertTrue(getRemotesItem(tree, repositoryFile).getNodes().isEmpty());
+ // removeRemotesConfig(repositoryFile);
+ // refreshAndWait();
+ // SWTBotTree tree = getOrOpenView().bot().tree();
+ // SWTBotTreeItem remotesItem = getRemotesItem(tree, repositoryFile)
+ // .expand();
+ //
+ // remotesItem = getRemotesItem(tree, repositoryFile).expand();
+ // remotesItem.select();
+ // ContextMenuHelper.clickContextMenu(tree, myUtil
+ // .getPluginLocalizedValue("NewRemoteCommand"));
+ // SWTBotShell shell = bot
+ // .shell(UIText.ConfigureRemoteWizard_WizardTitle_New);
+ // shell.bot().textWithLabel(UIText.SelectRemoteNamePage_RemoteNameLabel)
+ // .setText("testRemote");
+ // // for some reason the label-based widget getters don't work
+ // // configure fetch is 0
+ // shell.bot().checkBox(0).select();
+ // // configure push is 0
+ // shell.bot().checkBox(1).select();
+ // // next is 1
+ // shell.bot().button(1).click();
+ // // change is 0
+ // shell.bot().button(0).click();
+ // shell = bot.shell(UIText.SelectUriWiazrd_Title);
+ // shell.bot().text().setText("file:///" +
+ // remoteRepositoryFile.getPath());
+ // // finish is 1
+ // shell.bot().button(1).click();
+ // shell = bot.shell(UIText.ConfigureRemoteWizard_WizardTitle_New);
+ // // next is 2
+ // shell.bot().button(2).click();
+ // // add all branches spec is 2
+ // shell.bot().button(2).click();
+ // // next is 7
+ // shell.bot().button(7).click();
+ // // the URIish-like path
+ // String testString = new org.eclipse.jgit.transport.URIish("file:///"
+ // + remoteRepositoryFile.getPath()).toPrivateString();
+ // assertEquals(testString, shell.bot().text().getText());
+ // // add is 0
+ // shell.bot().toolbarButton(0).click();
+ // shell = bot.shell(UIText.SelectUriWiazrd_Title);
+ // shell.bot().text().setText("file:///" +
+ // remoteRepositoryFile.getPath());
+ // // finish is 1
+ // shell.bot().button(1).click();
+ // // duplicate
+ // shell = bot.shell(UIText.ConfigureUriPage_DuplicateUriTitle);
+ // shell.close();
+ // shell = bot.shell(UIText.ConfigureRemoteWizard_WizardTitle_New);
+ // shell.bot().button(1).click();
+ // // add all branches spec is 3
+ // shell.bot().button(3).click();
+ // // finish i 9
+ // shell.bot().button(9).click();
+ // refreshAndWait();
+ // // assert 2 children
+ // SWTBotTreeItem item = getRemotesItem(tree, repositoryFile).expand()
+ // .getNode("testRemote").expand();
+ // List<String> children = item.getNodes();
+ // assertTrue(children.size() == 2);
+ // item.getNode(0).select();
+ // ContextMenuHelper.clickContextMenu(tree, myUtil
+ // .getPluginLocalizedValue("RemoveFetchCommand"));
+ // refreshAndWait();
+ // // assert 1 children
+ // item = getRemotesItem(tree, repositoryFile).expand().getNode(
+ // "testRemote").expand();
+ // children = item.getNodes();
+ // assertTrue(children.size() == 1);
+ // item.getNode(0).select();
+ // ContextMenuHelper.clickContextMenu(tree, myUtil
+ // .getPluginLocalizedValue("RemovePushCommand"));
+ // refreshAndWait();
+ // // assert 0 children
+ // item = getRemotesItem(tree, repositoryFile).expand().getNode(
+ // "testRemote").expand();
+ // children = item.getNodes();
+ // assertTrue(children.size() == 0);
+ //
+ // getRemotesItem(tree, repositoryFile).expand().getNode("testRemote")
+ // .select();
+ // String shellText = NLS.bind(
+ // UIText.ConfigureRemoteWizard_WizardTitle_Change, "testRemote");
+ //
+ // ContextMenuHelper.clickContextMenu(tree, myUtil
+ // .getPluginLocalizedValue("ConfigureFetchCommand"));
+ // shell = bot.shell(shellText);
+ // // change is 0
+ // shell.bot().button(0).click();
+ // shell = bot.shell(UIText.SelectUriWiazrd_Title);
+ // shell.bot().text().setText("file:///" +
+ // remoteRepositoryFile.getPath());
+ // // finish is 1
+ // shell.bot().button(1).click();
+ // shell = bot.shell(shellText);
+ // // next is 2
+ // shell.bot().button(2).click();
+ // // add all branches spec is 2
+ // shell.bot().button(2).click();
+ // // finish is 8
+ // shell.bot().button(8).click();
+ // refreshAndWait();
+ // // assert 1 children
+ // item = getRemotesItem(tree, repositoryFile).expand().getNode(
+ // "testRemote").expand();
+ // children = item.getNodes();
+ // assertTrue(children.size() == 1);
+ //
+ // ContextMenuHelper.clickContextMenu(tree, myUtil
+ // .getPluginLocalizedValue("ConfigurePushCommand"));
+ // shell = bot.shell(shellText);
+ //
+ // shell.bot().toolbarButton(0).click();
+ // shell = bot.shell(UIText.SelectUriWiazrd_Title);
+ // shell.bot().text().setText("file:///" +
+ // remoteRepositoryFile.getPath());
+ // // finish is 1
+ // shell.bot().button(1).click();
+ // shell = bot.shell(shellText);
+ // shell.bot().button(1).click();
+ // // add all branches spec is 3
+ // shell.bot().button(3).click();
+ // // finish i 9
+ // shell.bot().button(9).click();
+ // refreshAndWait();
+ // // assert 2 children
+ // item = getRemotesItem(tree, repositoryFile).expand().getNode(
+ // "testRemote").expand();
+ // children = item.getNodes();
+ // assertTrue(children.size() == 2);
+ // item.select();
+ // ContextMenuHelper.clickContextMenu(tree, myUtil
+ // .getPluginLocalizedValue("RemoveRemoteCommand"));
+ // shell = bot.shell(UIText.RepositoriesView_ConfirmDeleteRemoteHeader);
+ // shell.bot().button(1).click();
+ //
+ // refreshAndWait();
+ // // assert 2 children
+ // item = getRemotesItem(tree, repositoryFile).expand().getNode(
+ // "testRemote").expand();
+ // children = item.getNodes();
+ // assertTrue(children.size() == 2);
+ //
+ // ContextMenuHelper.clickContextMenu(tree, myUtil
+ // .getPluginLocalizedValue("RemoveRemoteCommand"));
+ // bot.shell(UIText.RepositoriesView_ConfirmDeleteRemoteHeader).bot()
+ // .button(0).click();
+ // refreshAndWait();
+ // assertTrue(getRemotesItem(tree,
+ // repositoryFile).getNodes().isEmpty());
}
private void removeRemotesConfig(File file) throws Exception {
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java
index b5ff543bb8..09bf38ce7a 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTagHandlingTest.java
@@ -16,6 +16,12 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.IJobChangeListener;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.test.ContextMenuHelper;
@@ -76,17 +82,17 @@ public class GitRepositoriesViewTagHandlingTest extends
@Test
public void testCreateTags() throws Exception {
SWTBotTree tree = getOrOpenView().bot().tree();
- int initialCount = getTagsItem(tree, repositoryFile).expand()
- .rowCount();
+ int initialCount = myRepoViewUtil.getTagsItem(tree, repositoryFile)
+ .expand().rowCount();
String initialObjid = getObjectIdOfCommit();
createTag("FirstTag", "The first tag");
- touchAndSubmit();
+ touchAndSubmit(null);
String newObject = getObjectIdOfCommit();
createTag("SecondTag", "The second tag");
refreshAndWait();
- SWTBotTreeItem[] items = getTagsItem(tree, repositoryFile).expand()
- .getItems();
+ SWTBotTreeItem[] items = myRepoViewUtil.getTagsItem(tree,
+ repositoryFile).expand().getItems();
assertEquals("Wrong number of tags", initialCount + 2, items.length);
assertTrue("Wrong commit id", initialObjid
@@ -98,27 +104,62 @@ public class GitRepositoriesViewTagHandlingTest extends
@Test
public void testResetToTag() throws Exception {
SWTBotTree tree = getOrOpenView().bot().tree();
-
- String initialContent = getTestFileContent();
- createTag("ResetToFirst", "The first tag");
- touchAndSubmit();
- String newContent = getTestFileContent();
- assertFalse("Wrong content", initialContent.equals(newContent));
- createTag("ResetToSecond", "The second tag");
- refreshAndWait();
- getTagsItem(tree, repositoryFile).expand().getNode("ResetToFirst")
- .select();
- ContextMenuHelper.clickContextMenu(tree, myUtil
- .getPluginLocalizedValue("ResetCommand"));
-
- SWTBotShell resetDialog = bot.shell(UIText.ResetCommand_WizardTitle);
- pressAltAndChar(resetDialog, 'H');
- resetDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
- waitInUI();
-
- bot.shell(UIText.ResetTargetSelectionDialog_ResetQuestion).bot()
- .button(IDialogConstants.YES_LABEL).click();
- assertEquals("Wrong content", initialContent, getTestFileContent());
+ IJobChangeListener listener = null;
+ try {
+ String initialContent = getTestFileContent();
+ createTag("ResetToFirst", "The first tag");
+ touchAndSubmit(null);
+ String newContent = getTestFileContent();
+ assertFalse("Wrong content", initialContent.equals(newContent));
+ createTag("ResetToSecond", "The second tag");
+ refreshAndWait();
+ myRepoViewUtil.getTagsItem(tree, repositoryFile).expand().getNode(
+ "ResetToFirst").select();
+
+ final boolean[] done = new boolean[] { false };
+
+ final String jobName = NLS.bind(UIText.ResetAction_reset,
+ "refs/tags/ResetToFirst");
+
+ listener = new JobChangeAdapter() {
+
+ @Override
+ public void done(IJobChangeEvent event) {
+ if (jobName.equals(event.getJob().getName()))
+ done[0] = true;
+ }
+
+ };
+
+ Job.getJobManager().addJobChangeListener(listener);
+
+ ContextMenuHelper.clickContextMenu(tree, myUtil
+ .getPluginLocalizedValue("ResetCommand"));
+
+ SWTBotShell resetDialog = bot
+ .shell(UIText.ResetCommand_WizardTitle);
+ pressAltAndChar(resetDialog, 'H');
+ resetDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
+ waitInUI();
+
+ bot.shell(UIText.ResetTargetSelectionDialog_ResetQuestion).bot()
+ .button(IDialogConstants.YES_LABEL).click();
+
+ for (int i = 0; i < 1000; i++) {
+ if (done[0])
+ break;
+ Thread.sleep(10);
+ }
+
+ assertTrue("Job should be completed", done[0]);
+
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(
+ IResource.DEPTH_INFINITE, null);
+ assertEquals("Wrong content", initialContent, getTestFileContent());
+ } finally {
+ if (listener != null)
+ Job.getJobManager().removeJobChangeListener(listener);
+ }
}
private String getCommitIdOfTag(String tagName) throws Exception {
@@ -128,7 +169,7 @@ public class GitRepositoriesViewTagHandlingTest extends
private void createTag(String name, String message) throws Exception {
SWTBotTree tree = getOrOpenView().bot().tree();
- getTagsItem(tree, repositoryFile).select();
+ myRepoViewUtil.getTagsItem(tree, repositoryFile).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("CreateTagCommand"));
String branchName = repository.getBranch();
@@ -138,9 +179,6 @@ public class GitRepositoriesViewTagHandlingTest extends
createDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName)
.setText(name);
createDialog.bot().textWithLabel(UIText.CreateTagDialog_tagMessage)
- .setText("dummy");
- // TODO the ok button does not enable upon the first setText
- createDialog.bot().textWithLabel(UIText.CreateTagDialog_tagMessage)
.setText(message);
waitInUI();
createDialog.bot().button(IDialogConstants.OK_LABEL).click();
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
index 2be062bff1..48ccc02f6c 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
@@ -46,6 +46,7 @@ import org.junit.runner.RunWith;
/**
* SWTBot Tests for the Git Repositories View.
+ *
* <pre>
* TODO
* global copy and paste command
@@ -78,7 +79,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
@Test
public void testExpandFirstLevel() throws Exception {
SWTBotTree tree = getOrOpenView().bot().tree();
- SWTBotTreeItem item = getRootItem(tree, repositoryFile).expand();
+ SWTBotTreeItem item = myRepoViewUtil.getRootItem(tree, repositoryFile)
+ .expand();
SWTBotTreeItem[] children = item.getItems();
assertEquals("Wrong number of children", 5, children.length);
}
@@ -92,28 +94,27 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
public void testOpen() throws Exception {
// expand first level
SWTBotTree tree = getOrOpenView().bot().tree();
- SWTBotTreeItem item = getRootItem(tree, repositoryFile);
+ SWTBotTreeItem item = myRepoViewUtil.getRootItem(tree, repositoryFile);
item.collapse();
refreshAndWait();
- item = getRootItem(tree, repositoryFile);
- // the number of children does appear to be 1 (with empty text)...
- assertEquals("Wrong number of children", 1, item.getNodes().size());
+ item = myRepoViewUtil.getRootItem(tree, repositoryFile);
+ assertTrue("Item should not be expanded", !item.isExpanded());
item.doubleClick();
- assertEquals("Wrong number of children", 5, item.getNodes().size());
+ assertTrue("Item should be expanded", item.isExpanded());
// open a file in editor
- item = getWorkdirItem(tree, repositoryFile).expand();
+ item = myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand();
SWTBotTreeItem fileiItem = item.getNode(PROJ1).expand().getNode(FOLDER)
.expand().getNode(FILE1).select();
fileiItem.doubleClick();
assertTrue(bot.activeEditor().getTitle().equals(FILE1));
bot.activeEditor().close();
// open a branch (checkout)
- item = getLocalBranchesItem(tree, repositoryFile).expand().getNode(
- "master").doubleClick();
+ item = myRepoViewUtil.getLocalBranchesItem(tree, repositoryFile)
+ .expand().getNode("master").doubleClick();
refreshAndWait();
String contentMaster = getTestFileContent();
- item = getLocalBranchesItem(tree, repositoryFile).expand().getNode(
- "stable").doubleClick();
+ item = myRepoViewUtil.getLocalBranchesItem(tree, repositoryFile)
+ .expand().getNode("stable").doubleClick();
refreshAndWait();
waitInUI();
String contentStable = getTestFileContent();
@@ -129,8 +130,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
@Test
public void testExpandSymbolicRef() throws Exception {
SWTBotTree tree = getOrOpenView().bot().tree();
- SWTBotTreeItem item = getSymbolicRefsItem(tree, repositoryFile)
- .expand();
+ SWTBotTreeItem item = myRepoViewUtil.getSymbolicRefsItem(tree,
+ repositoryFile).expand();
List<String> children = item.getNodes();
boolean found = false;
for (String child : children)
@@ -149,12 +150,12 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
SWTBotTree tree = getOrOpenView().bot().tree();
Repository myRepository = lookupRepository(repositoryFile);
List<String> children = Arrays.asList(myRepository.getWorkDir().list());
- List<String> treeChildren = getWorkdirItem(tree, repositoryFile)
- .expand().getNodes();
+ List<String> treeChildren = myRepoViewUtil.getWorkdirItem(tree,
+ repositoryFile).expand().getNodes();
assertTrue(children.containsAll(treeChildren)
&& treeChildren.containsAll(children));
- getWorkdirItem(tree, repositoryFile).expand().getNode(PROJ1).expand()
- .getNode(FOLDER).expand().getNode(FILE1);
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand().getNode(
+ PROJ1).expand().getNode(FOLDER).expand().getNode(FILE1);
}
/**
@@ -165,9 +166,10 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
*/
@Test
public void testContextMenuRepository() throws Exception {
- // TODO real tests instead of just context menu tests
+ // We just check if the dialogs open, the actual fetch and push
+ // is tested elsewhere
SWTBotTree tree = getOrOpenView().bot().tree();
- SWTBotTreeItem item = getRootItem(tree, repositoryFile);
+ SWTBotTreeItem item = myRepoViewUtil.getRootItem(tree, repositoryFile);
item.select();
assertClickOpens(tree, myUtil.getPluginLocalizedValue("FetchCommand"),
UIText.FetchWizard_windowTitleDefault);
@@ -183,7 +185,7 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
@Test
public void testShowProperties() throws Exception {
SWTBotTree tree = getOrOpenView().bot().tree();
- SWTBotTreeItem item = getRootItem(tree, repositoryFile);
+ SWTBotTreeItem item = myRepoViewUtil.getRootItem(tree, repositoryFile);
item.select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("OpenPropertiesCommand"));
@@ -202,7 +204,7 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
deleteAllProjects();
assertProjectExistence(PROJ1, false);
SWTBotTree tree = getOrOpenView().bot().tree();
- SWTBotTreeItem item = getRootItem(tree, repositoryFile);
+ SWTBotTreeItem item = myRepoViewUtil.getRootItem(tree, repositoryFile);
String wizardTitle = NLS.bind(
UIText.GitCreateProjectViaWizardWizard_WizardTitle,
repositoryFile.getPath());
@@ -221,12 +223,13 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
TableCollection selected = shell.bot().tree().selection();
String wizardNode = selected.get(0, 0);
// wizard directory should be working dir
- assertEquals(getWorkdirItem(tree, repositoryFile).getText(), wizardNode);
+ assertEquals(myRepoViewUtil.getWorkdirItem(tree, repositoryFile)
+ .getText(), wizardNode);
waitInUI();
shell.close();
// start wizard from .git
- getWorkdirItem(tree, repositoryFile).expand()
- .getNode(Constants.DOT_GIT).select();
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand().getNode(
+ Constants.DOT_GIT).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("ImportProjectsCommand"));
shell = bot.shell(wizardTitle);
@@ -263,7 +266,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
UIText.GitCreateProjectViaWizardWizard_WizardTitle,
repositoryFile.getPath());
// start wizard from PROJ2
- getWorkdirItem(tree, repositoryFile).expand().getNode(PROJ2).select();
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand().getNode(
+ PROJ2).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("ImportProjectsCommand"));
SWTBotShell shell = bot.shell(wizardTitle);
@@ -302,7 +306,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
UIText.GitCreateProjectViaWizardWizard_WizardTitle,
repositoryFile.getPath());
// start wizard from PROJ1
- getWorkdirItem(tree, repositoryFile).expand().getNode(PROJ1).select();
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand().getNode(
+ PROJ1).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("ImportProjectsCommand"));
SWTBotShell shell = bot.shell(wizardTitle);
@@ -338,12 +343,16 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
private void assertProjectInWorkingSet(String workingSetName,
String projectName) {
- IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
- IWorkingSet workingSet = workingSetManager.getWorkingSet(workingSetName);
+ IWorkingSetManager workingSetManager = PlatformUI.getWorkbench()
+ .getWorkingSetManager();
+ IWorkingSet workingSet = workingSetManager
+ .getWorkingSet(workingSetName);
IAdaptable[] elements = workingSet.getElements();
- assertEquals("Wrong number of projects in working set", 1, elements.length);
+ assertEquals("Wrong number of projects in working set", 1,
+ elements.length);
IProject project = (IProject) elements[0].getAdapter(IProject.class);
- assertEquals("Wrong project in working set", projectName, project.getName());
+ assertEquals("Wrong project in working set", projectName, project
+ .getName());
}
@Test
@@ -356,7 +365,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
UIText.GitCreateProjectViaWizardWizard_WizardTitle,
repositoryFile.getPath());
// start wizard from PROJ2
- getWorkdirItem(tree, repositoryFile).expand().getNode(PROJ2).select();
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand().getNode(
+ PROJ2).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("ImportProjectsCommand"));
SWTBotShell shell = bot.shell(wizardTitle);
@@ -391,7 +401,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
UIText.GitCreateProjectViaWizardWizard_WizardTitle,
repositoryFile.getPath());
// start wizard from PROJ2
- getWorkdirItem(tree, repositoryFile).expand().getNode(PROJ2).select();
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand().getNode(
+ PROJ2).select();
ContextMenuHelper.clickContextMenu(tree, myUtil
.getPluginLocalizedValue("ImportProjectsCommand"));
SWTBotShell shell = bot.shell(wizardTitle);
@@ -427,7 +438,7 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
bot.perspectiveById("org.eclipse.ui.resourcePerspective")
.activate();
SWTBotTree tree = getOrOpenView().bot().tree();
- getRootItem(tree, repositoryFile).select();
+ myRepoViewUtil.getRootItem(tree, repositoryFile).select();
// the selection should be root
assertTrue(tree.selection().get(0, 0).startsWith(REPO1));
@@ -480,7 +491,7 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
bot.perspectiveById("org.eclipse.ui.resourcePerspective")
.activate();
SWTBotTree tree = getOrOpenView().bot().tree();
- getRootItem(tree, repositoryFile).select();
+ myRepoViewUtil.getRootItem(tree, repositoryFile).select();
// the selection should be root
assertTrue(tree.selection().get(0, 0).startsWith(REPO1));
@@ -524,8 +535,9 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
bot.editorByTitle(FILE1).show();
- getWorkdirItem(tree, repositoryFile).expand().getNode(PROJ1)
- .expand().getNode(FOLDER).expand().getNode(FILE2).select();
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand()
+ .getNode(PROJ1).expand().getNode(FOLDER).expand().getNode(
+ FILE2).select();
// the editor should still be test.txt
assertEquals(FILE1, bot.activeEditor().getTitle());
@@ -534,21 +546,24 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
getOrOpenView().toolbarButton("Link with Editor").click();
// make sure focus is here
waitInUI();
- getWorkdirItem(tree, repositoryFile).expand().getNode(PROJ1)
- .expand().getNode(FOLDER).expand().getNode(FILE2).select();
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand()
+ .getNode(PROJ1).expand().getNode(FOLDER).expand().getNode(
+ FILE2).select();
waitInUI();
assertEquals(FILE2, bot.activeEditor().getTitle());
- getWorkdirItem(tree, repositoryFile).expand().getNode(PROJ1)
- .expand().getNode(FOLDER).expand().getNode(FILE1).select();
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand()
+ .getNode(PROJ1).expand().getNode(FOLDER).expand().getNode(
+ FILE1).select();
waitInUI();
assertEquals(FILE1, bot.activeEditor().getTitle());
// deactivate the link with editor
getOrOpenView().toolbarButton("Link with Editor").click();
- getWorkdirItem(tree, repositoryFile).expand().getNode(PROJ1)
- .expand().getNode(FOLDER).expand().getNode(FILE2).select();
+ myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand()
+ .getNode(PROJ1).expand().getNode(FOLDER).expand().getNode(
+ FILE2).select();
waitInUI();
assertEquals(FILE1, bot.activeEditor().getTitle());
@@ -564,8 +579,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
SWTBotTree tree = getOrOpenView().bot().tree();
refreshAndWait();
// create a branch (no checkout)
- SWTBotTreeItem localBranchesItem = getLocalBranchesItem(tree,
- repositoryFile).expand();
+ SWTBotTreeItem localBranchesItem = myRepoViewUtil.getLocalBranchesItem(
+ tree, repositoryFile).expand();
SWTBotTreeItem masterNode = localBranchesItem.getNode("master");
masterNode.select();
ContextMenuHelper.clickContextMenu(tree, "Create Branch...");
@@ -578,11 +593,12 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
localBranchesItem.getNode("abc").select();
ContextMenuHelper.clickContextMenu(tree, "Delete Branch...");
- SWTBotShell deleteBranchDialog = bot.shell(UIText.RepositoriesView_ConfirmDeleteTitle);
+ SWTBotShell deleteBranchDialog = bot
+ .shell(UIText.RepositoriesView_ConfirmDeleteTitle);
deleteBranchDialog.bot().button(IDialogConstants.OK_LABEL).click();
refreshAndWait();
- SWTBotTreeItem[] items = getLocalBranchesItem(tree, repositoryFile)
- .getItems();
+ SWTBotTreeItem[] items = myRepoViewUtil.getLocalBranchesItem(tree,
+ repositoryFile).getItems();
assertEquals("Wrong number of branches", 2, items.length);
assertEquals("master", items[0].getText());
assertEquals("stable", items[1].getText());
@@ -594,8 +610,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
SWTBotTree tree = getOrOpenView().bot().tree();
refreshAndWait();
// open a branch (checkout)
- SWTBotTreeItem localBranchesItem = getLocalBranchesItem(tree,
- repositoryFile).expand();
+ SWTBotTreeItem localBranchesItem = myRepoViewUtil.getLocalBranchesItem(
+ tree, repositoryFile).expand();
SWTBotTreeItem masterNode = localBranchesItem.getNode("master");
// create first branch (abc)
masterNode.select();
@@ -611,20 +627,24 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
createBranchShell.bot().checkBox().deselect();
createBranchShell.bot().button(IDialogConstants.FINISH_LABEL).click();
refreshAndWait();
- localBranchesItem = getLocalBranchesItem(tree,
+ localBranchesItem = myRepoViewUtil.getLocalBranchesItem(tree,
repositoryFile).expand();
// delete both
localBranchesItem.select("abc", "123");
- ContextMenuHelper.clickContextMenu(tree, UIText.RepositoriesView_DeleteBranchMenu);
-
- SWTBotShell deleteBranchDialog = bot.shell(UIText.RepositoriesView_ConfirmDeleteTitle);
- assertNotNull(deleteBranchDialog.bot().table(0).getTableItem("refs/heads/abc"));
- assertNotNull(deleteBranchDialog.bot().table(0).getTableItem("refs/heads/123"));
+ ContextMenuHelper.clickContextMenu(tree,
+ UIText.RepositoriesView_DeleteBranchMenu);
+
+ SWTBotShell deleteBranchDialog = bot
+ .shell(UIText.RepositoriesView_ConfirmDeleteTitle);
+ assertNotNull(deleteBranchDialog.bot().table(0).getTableItem(
+ "refs/heads/abc"));
+ assertNotNull(deleteBranchDialog.bot().table(0).getTableItem(
+ "refs/heads/123"));
deleteBranchDialog.bot().button(IDialogConstants.OK_LABEL).click();
refreshAndWait();
- SWTBotTreeItem[] items = getLocalBranchesItem(tree, repositoryFile)
- .getItems();
+ SWTBotTreeItem[] items = myRepoViewUtil.getLocalBranchesItem(tree,
+ repositoryFile).getItems();
assertEquals("Wrong number of branches", 2, items.length);
assertEquals("master", items[0].getText());
assertEquals("stable", items[1].getText());
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
index e9f5408ebf..190d4956c8 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
@@ -14,76 +14,35 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.StringTokenizer;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.egit.core.op.CommitOperation;
-import org.eclipse.egit.core.op.ConnectProviderOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.RepositoryUtil;
-import org.eclipse.egit.ui.internal.push.PushConfiguredRemoteAction;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
import org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider;
-import org.eclipse.egit.ui.internal.repository.tree.BranchesNode;
-import org.eclipse.egit.ui.internal.repository.tree.LocalBranchesNode;
-import org.eclipse.egit.ui.internal.repository.tree.RemoteBranchesNode;
-import org.eclipse.egit.ui.internal.repository.tree.RemotesNode;
-import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
-import org.eclipse.egit.ui.internal.repository.tree.SymbolicRefsNode;
-import org.eclipse.egit.ui.internal.repository.tree.TagsNode;
-import org.eclipse.egit.ui.internal.repository.tree.WorkingDirNode;
-import org.eclipse.egit.ui.test.ContextMenuHelper;
-import org.eclipse.egit.ui.test.Eclipse;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.lib.RefUpdate;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.util.FS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
-import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
/**
* Collection of utility methods for Git Repositories View tests
*/
-public abstract class GitRepositoriesViewTestBase {
-
- // static because it is used in @BeforeClass
- protected static final SWTWorkbenchBot bot = new SWTWorkbenchBot();
+public abstract class GitRepositoriesViewTestBase extends
+ LocalRepositoryTestCase {
protected static final RepositoriesViewLabelProvider labelProvider = new RepositoriesViewLabelProvider();
// test utilities
- protected static final TestUtil myUtil = TestUtil.getInstance();
+ protected static final TestUtil myUtil = new TestUtil();
+ protected static final GitRepositoriesViewTestUtils myRepoViewUtil = new GitRepositoriesViewTestUtils();
// the "Git Repositories View" bot
private SWTBotView viewbot;
@@ -91,87 +50,14 @@ public abstract class GitRepositoriesViewTestBase {
// the human-readable view name
protected static String viewName;
- // the temporary directory
- protected static File testDirectory;
-
// the human readable Git category
private static String gitCategory;
- protected static final String REPO1 = "FirstRepository";
-
- private static final String REPO2 = "RemoteRepository";
-
- /** A general project containing FOLDER containing FILE1 and FILE2 */
- protected static final String PROJ1 = "GeneralProject";
-
- /** A folder obtained by checking in a project without .project */
- protected static final String PROJ2 = "ProjectWithoutDotProject";
-
- protected static final String FILE1 = "test.txt";
-
- protected static final String FILE2 = "test2.txt";
-
- protected static final String FOLDER = "folder";
-
static {
viewName = myUtil.getPluginLocalizedValue("GitRepositoriesView_name");
gitCategory = myUtil.getPluginLocalizedValue("GitCategory_name");
}
- @BeforeClass
- public static void beforeClassBase() throws Exception {
- // close the welcome page
- try {
- bot.viewByTitle("Welcome").close();
- } catch (WidgetNotFoundException e) {
- // somebody else probably closed it, lets not feel bad about it.
- }
- clearView();
- deleteAllProjects();
- // create our temporary directory in the user space
- File userHome = FS.DETECTED.userHome();
- testDirectory = new File(userHome, "GitRepositoriesTest");
- if (testDirectory.exists())
- deleteRecursive(testDirectory);
- testDirectory.mkdir();
- }
-
- @AfterClass
- public static void afterClassBase() throws Exception {
- // close all editors/dialogs
- new Eclipse().reset();
- // cleanup
- clearView();
- deleteAllProjects();
- deleteRecursive(testDirectory);
- }
-
- private static void deleteRecursive(File dirOrFile) {
- if (dirOrFile.isDirectory()) {
- for (File file : dirOrFile.listFiles()) {
- deleteRecursive(file);
- }
- }
- boolean deleted = dirOrFile.delete();
- if (!deleted) {
- dirOrFile.deleteOnExit();
- }
- }
-
- protected static void deleteAllProjects() throws CoreException {
- for (IProject prj : ResourcesPlugin.getWorkspace().getRoot()
- .getProjects())
- if (prj.getName().equals(PROJ1))
- prj.delete(false, false, null);
- else if (prj.getName().equals(PROJ2)) {
- // delete the .project on disk
- EFS.getStore(prj.getFile(".project").getLocationURI())
- .toLocalFile(EFS.NONE, null).delete();
- prj.delete(false, false, null);
- }
-
- }
-
/**
* remove all configured repositories from the view
*/
@@ -180,138 +66,6 @@ public abstract class GitRepositoriesViewTestBase {
RepositoryUtil.PREFS_DIRECTORIES);
}
- protected static File createProjectAndCommitToRepository() throws Exception {
-
- File gitDir = new File(new File(testDirectory, REPO1),
- Constants.DOT_GIT);
- gitDir.mkdir();
- Repository myRepository = new Repository(gitDir);
- myRepository.create();
-
- // we need to commit into master first
- IProject firstProject = ResourcesPlugin.getWorkspace().getRoot()
- .getProject(PROJ1);
-
- if (firstProject.exists())
- firstProject.delete(true, null);
- IProjectDescription desc = ResourcesPlugin.getWorkspace()
- .newProjectDescription(PROJ1);
- desc.setLocation(new Path(new File(myRepository.getWorkDir(), PROJ1)
- .getPath()));
- firstProject.create(desc, null);
- firstProject.open(null);
-
- IFolder folder = firstProject.getFolder(FOLDER);
- folder.create(false, true, null);
- IFile textFile = folder.getFile(FILE1);
- textFile.create(new ByteArrayInputStream("Hello, world"
- .getBytes(firstProject.getDefaultCharset())), false, null);
- IFile textFile2 = folder.getFile(FILE2);
- textFile2.create(new ByteArrayInputStream("Some more content"
- .getBytes(firstProject.getDefaultCharset())), false, null);
-
- new ConnectProviderOperation(firstProject, gitDir).execute(null);
-
- IProject secondPoject = ResourcesPlugin.getWorkspace().getRoot()
- .getProject(PROJ2);
-
- if (secondPoject.exists())
- secondPoject.delete(true, null);
-
- desc = ResourcesPlugin.getWorkspace().newProjectDescription(PROJ2);
- desc.setLocation(new Path(new File(myRepository.getWorkDir(), PROJ2)
- .getPath()));
- secondPoject.create(desc, null);
- secondPoject.open(null);
-
- IFolder secondfolder = secondPoject.getFolder(FOLDER);
- secondfolder.create(false, true, null);
- IFile secondtextFile = secondfolder.getFile(FILE1);
- secondtextFile.create(new ByteArrayInputStream("Hello, world"
- .getBytes(firstProject.getDefaultCharset())), false, null);
- IFile secondtextFile2 = secondfolder.getFile(FILE2);
- secondtextFile2.create(new ByteArrayInputStream("Some more content"
- .getBytes(firstProject.getDefaultCharset())), false, null);
-
- new ConnectProviderOperation(secondPoject, gitDir).execute(null);
-
- IFile[] commitables = new IFile[] { firstProject.getFile(".project"),
- textFile, textFile2, secondtextFile, secondtextFile2 };
- ArrayList<IFile> untracked = new ArrayList<IFile>();
- untracked.addAll(Arrays.asList(commitables));
- // commit to stable
- CommitOperation op = new CommitOperation(commitables,
- new ArrayList<IFile>(), untracked,
- "Test Author <test.author@test.com>",
- "Test Committer <test.commiter@test.com>", "Initial commit");
- op.execute(null);
-
- // now create a stable branch (from master)
- createStableBranch(myRepository);
- // and check in some stuff into master again
- touchAndSubmit();
- return gitDir;
- }
-
- protected static File createRemoteRepository(File repositoryDir)
- throws Exception {
- Repository myRepository = org.eclipse.egit.core.Activator.getDefault()
- .getRepositoryCache().lookupRepository(repositoryDir);
- File gitDir = new File(testDirectory, REPO2);
- Repository myRemoteRepository = new Repository(gitDir);
- myRemoteRepository.create();
-
- createStableBranch(myRepository);
-
- // now we configure the push destination
- myRepository.getConfig().setString("remote", "push", "pushurl",
- "file:///" + myRemoteRepository.getDirectory().getPath());
- myRepository.getConfig().setString("remote", "push", "push",
- "+refs/heads/*:refs/heads/*");
- myRepository.getConfig().save();
- // and push
- PushConfiguredRemoteAction pa = new PushConfiguredRemoteAction(
- myRepository, "push");
-
- pa.run(null, false);
-
- try {
- // delete the stable branch again
- RefUpdate op = myRepository.updateRef("refs/heads/stable");
- op.setRefLogMessage("branch deleted", //$NON-NLS-1$
- false);
- // we set the force update in order
- // to avoid having this rejected
- // due to minor issues
- op.setForceUpdate(true);
- op.delete();
- } catch (IOException ioe) {
- throw new InvocationTargetException(ioe);
- }
- return myRemoteRepository.getDirectory();
- }
-
- protected static void createStableBranch(Repository myRepository)
- throws IOException {
- // let's create a stable branch temporarily so
- // that we push two branches to remote
- String newRefName = "refs/heads/stable";
- RefUpdate updateRef = myRepository.updateRef(newRefName);
- Ref sourceBranch = myRepository.getRef("refs/heads/master");
- ObjectId startAt = sourceBranch.getObjectId();
- String startBranch = myRepository
- .shortenRefName(sourceBranch.getName());
- updateRef.setNewObjectId(startAt);
- updateRef
- .setRefLogMessage("branch: Created from " + startBranch, false); //$NON-NLS-1$
- updateRef.update();
- }
-
- @After
- public void afterBase() {
- new Eclipse().reset();
- }
-
protected SWTBotView getOrOpenView() throws Exception {
if (viewbot == null) {
bot.menu("Window").menu("Show View").menu("Other...").click();
@@ -328,16 +82,6 @@ public abstract class GitRepositoriesViewTestBase {
return viewbot;
}
- protected void assertClickOpens(SWTBotTree tree, String menu, String window)
- throws InterruptedException {
- ContextMenuHelper.clickContextMenu(tree, menu);
- SWTBotShell shell = bot.shell(window);
- shell.activate();
- waitInUI();
- shell.bot().button(IDialogConstants.CANCEL_LABEL).click();
- shell.close();
- }
-
protected void assertHasRepo(File repositoryDir) throws Exception {
final SWTBotTree tree = getOrOpenView().bot().tree();
final SWTBotTreeItem[] items = tree.getAllItems();
@@ -365,36 +109,6 @@ public abstract class GitRepositoriesViewTestBase {
refreshJob.join();
}
- protected static void waitInUI() throws InterruptedException {
- Thread.sleep(1000);
- }
-
- protected void shareProjects(File repositoryDir) throws Exception {
- Repository myRepository = org.eclipse.egit.core.Activator.getDefault()
- .getRepositoryCache().lookupRepository(repositoryDir);
- FilenameFilter projectFilter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.equals(".project");
- }
- };
- for (File file : myRepository.getWorkDir().listFiles()) {
- if (file.isDirectory()) {
- if (file.list(projectFilter).length > 0) {
- IProjectDescription desc = ResourcesPlugin.getWorkspace()
- .newProjectDescription(file.getName());
- desc.setLocation(new Path(file.getPath()));
- IProject prj = ResourcesPlugin.getWorkspace().getRoot()
- .getProject(file.getName());
- prj.create(desc, null);
- prj.open(null);
-
- new ConnectProviderOperation(prj, myRepository
- .getDirectory()).execute(null);
- }
- }
- }
- }
-
@SuppressWarnings("boxing")
protected void assertProjectExistence(String projectName, boolean existence) {
IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(
@@ -402,197 +116,4 @@ public abstract class GitRepositoriesViewTestBase {
assertEquals("Project existence " + projectName, prj.exists(),
existence);
}
-
- protected static Repository lookupRepository(File directory)
- throws Exception {
- return org.eclipse.egit.core.Activator.getDefault()
- .getRepositoryCache().lookupRepository(directory);
- }
-
- protected static void touchAndSubmit() throws Exception {
- IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(
- PROJ1);
- if (!prj.isAccessible())
- throw new IllegalStateException("No project to touch");
- IFile file = prj.getFile(new Path("folder/test.txt"));
- String newContent = "Touched at " + System.currentTimeMillis();
- file.setContents(new ByteArrayInputStream(newContent.getBytes(prj
- .getDefaultCharset())), 0, null);
-
- IFile[] commitables = new IFile[] { file };
- ArrayList<IFile> untracked = new ArrayList<IFile>();
- untracked.addAll(Arrays.asList(commitables));
- CommitOperation op = new CommitOperation(commitables,
- new ArrayList<IFile>(), untracked,
- "Test Author <test.author@test.com>",
- "Test Committer <test.commiter@test.com>", newContent);
- op.execute(null);
- }
-
- protected SWTBotTreeItem getLocalBranchesItem(SWTBotTree tree, File repo)
- throws Exception {
- Repository repository = lookupRepository(repo);
- RepositoryNode root = new RepositoryNode(null, repository);
- BranchesNode branches = new BranchesNode(root, repository);
- LocalBranchesNode localBranches = new LocalBranchesNode(branches,
- repository);
-
- String rootText = labelProvider.getText(root);
- SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
- SWTBotTreeItem branchesItem = rootItem.expand().getNode(
- labelProvider.getText(branches));
- SWTBotTreeItem localItem = branchesItem.expand().getNode(
- labelProvider.getText(localBranches));
- return localItem;
- }
-
- protected SWTBotTreeItem getRemoteBranchesItem(SWTBotTree tree,
- File repositoryFile) throws Exception {
- Repository repository = lookupRepository(repositoryFile);
- RepositoryNode root = new RepositoryNode(null, repository);
- BranchesNode branches = new BranchesNode(root, repository);
- RemoteBranchesNode remoteBranches = new RemoteBranchesNode(branches,
- repository);
-
- String rootText = labelProvider.getText(root);
- SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
- SWTBotTreeItem branchesItem = rootItem.expand().getNode(
- labelProvider.getText(branches));
- SWTBotTreeItem remoteItem = branchesItem.expand().getNode(
- labelProvider.getText(remoteBranches));
- return remoteItem;
- }
-
- protected SWTBotTreeItem getWorkdirItem(SWTBotTree tree, File repositoryFile)
- throws Exception {
- Repository repository = lookupRepository(repositoryFile);
- RepositoryNode root = new RepositoryNode(null, repository);
-
- WorkingDirNode workdir = new WorkingDirNode(root, repository);
-
- String rootText = labelProvider.getText(root);
- SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
- SWTBotTreeItem workdirItem = rootItem.expand().getNode(
- labelProvider.getText(workdir));
- return workdirItem;
- }
-
- protected SWTBotTreeItem getRootItem(SWTBotTree tree, File repositoryFile)
- throws Exception {
- Repository repository = lookupRepository(repositoryFile);
- RepositoryNode root = new RepositoryNode(null, repository);
- String rootText = labelProvider.getText(root);
- SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
- return rootItem;
- }
-
- protected SWTBotTreeItem getSymbolicRefsItem(SWTBotTree tree,
- File repositoryFile) throws Exception {
- Repository repository = lookupRepository(repositoryFile);
- RepositoryNode root = new RepositoryNode(null, repository);
- SymbolicRefsNode symrefsnode = new SymbolicRefsNode(root, repository);
- SWTBotTreeItem rootItem = tree.getTreeItem(labelProvider.getText(root))
- .expand();
- SWTBotTreeItem symrefsitem = rootItem.getNode(labelProvider
- .getText(symrefsnode));
- return symrefsitem;
- }
-
- protected SWTBotTreeItem getRemotesItem(SWTBotTree tree, File repositoryFile)
- throws Exception {
- Repository repository = lookupRepository(repositoryFile);
- RepositoryNode root = new RepositoryNode(null, repository);
- RemotesNode remotes = new RemotesNode(root, repository);
-
- String rootText = labelProvider.getText(root);
- SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
- SWTBotTreeItem remotesItem = rootItem.expand().getNode(
- labelProvider.getText(remotes));
- return remotesItem;
- }
-
- protected SWTBotTreeItem getTagsItem(SWTBotTree tree, File repositoryFile)
- throws Exception {
- Repository repository = lookupRepository(repositoryFile);
- RepositoryNode root = new RepositoryNode(null, repository);
- TagsNode tags = new TagsNode(root, repository);
-
- String rootText = labelProvider.getText(root);
- SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
- SWTBotTreeItem tagsItem = rootItem.expand().getNode(
- labelProvider.getText(tags));
- return tagsItem;
- }
-
- protected String getTestFileContent() throws Exception {
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
- .getFile(new Path("folder/test.txt"));
- if (file.exists()) {
- byte[] bytes = new byte[0];
- InputStream is = null;
- try {
- is = file.getContents();
- bytes = new byte[is.available()];
- is.read(bytes);
- } finally {
- if (is != null)
- is.close();
- }
- return new String(bytes, file.getCharset());
- } else {
- return "";
- }
- }
-
- /**
- * @param projectExplorerTree
- * @param project
- * name of a project
- * @return the project item pertaining to the project
- */
- protected SWTBotTreeItem getProjectItem(SWTBotTree projectExplorerTree,
- String project) {
- for (SWTBotTreeItem item : projectExplorerTree.getAllItems()) {
- String itemText = item.getText();
- StringTokenizer tok = new StringTokenizer(itemText, " ");
- String name = tok.nextToken();
- if (project.equals(name))
- return item;
- }
- return null;
- }
-
- protected void pressAltAndChar(SWTBotShell shell, char charToPress) {
- Display display = Display.getDefault();
- Event evt = new Event();
- // Alt down
- evt.type = SWT.KeyDown;
- evt.item = shell.widget;
- evt.keyCode = SWT.ALT;
- display.post(evt);
- // G down
- evt.keyCode = 0;
- evt.character = charToPress;
- display.post(evt);
- // G up
- evt.type = SWT.KeyUp;
- display.post(evt);
- // Alt up
- evt.keyCode = SWT.ALT;
- evt.character = ' ';
- display.post(evt);
- }
-
- /**
- * @param shell
- * @param itemWithShortcut
- * ALT + the char right after '&' will be pressed
- */
- protected void activateItemByKeyboard(SWTBotShell shell,
- String itemWithShortcut) {
- int index = itemWithShortcut.indexOf('&');
- if (index >= 0 && index < itemWithShortcut.length())
- pressAltAndChar(shell, itemWithShortcut.charAt(index + 1));
- }
-
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java
new file mode 100644
index 0000000000..ad899e70e2
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2010 SAP AG.
+ * 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
+ *
+ * Contributors:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.view.repositories;
+
+import java.io.File;
+
+import org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider;
+import org.eclipse.egit.ui.internal.repository.tree.BranchesNode;
+import org.eclipse.egit.ui.internal.repository.tree.LocalBranchesNode;
+import org.eclipse.egit.ui.internal.repository.tree.RemoteBranchesNode;
+import org.eclipse.egit.ui.internal.repository.tree.RemotesNode;
+import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
+import org.eclipse.egit.ui.internal.repository.tree.SymbolicRefsNode;
+import org.eclipse.egit.ui.internal.repository.tree.TagsNode;
+import org.eclipse.egit.ui.internal.repository.tree.WorkingDirNode;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+
+public class GitRepositoriesViewTestUtils {
+
+ private final RepositoriesViewLabelProvider labelProvider = new RepositoriesViewLabelProvider();
+
+ public SWTBotTreeItem getLocalBranchesItem(SWTBotTree tree, File repo)
+ throws Exception {
+ Repository repository = lookupRepository(repo);
+ RepositoryNode root = new RepositoryNode(null, repository);
+ BranchesNode branches = new BranchesNode(root, repository);
+ LocalBranchesNode localBranches = new LocalBranchesNode(branches,
+ repository);
+
+ String rootText = labelProvider.getText(root);
+ SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
+ SWTBotTreeItem branchesItem = rootItem.expand().getNode(
+ labelProvider.getText(branches));
+ SWTBotTreeItem localItem = branchesItem.expand().getNode(
+ labelProvider.getText(localBranches));
+ return localItem;
+ }
+
+ public SWTBotTreeItem getTagsItem(SWTBotTree tree, File repo)
+ throws Exception {
+ Repository repository = lookupRepository(repo);
+ RepositoryNode root = new RepositoryNode(null, repository);
+ TagsNode tags = new TagsNode(root, repository);
+
+ String rootText = labelProvider.getText(root);
+ SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
+ SWTBotTreeItem tagsItem = rootItem.expand().getNode(
+ labelProvider.getText(tags));
+ return tagsItem;
+ }
+
+ public SWTBotTreeItem getRemoteBranchesItem(SWTBotTree tree,
+ File repositoryFile) throws Exception {
+ Repository repository = lookupRepository(repositoryFile);
+ RepositoryNode root = new RepositoryNode(null, repository);
+ BranchesNode branches = new BranchesNode(root, repository);
+ RemoteBranchesNode remoteBranches = new RemoteBranchesNode(branches,
+ repository);
+
+ String rootText = labelProvider.getText(root);
+ SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
+ SWTBotTreeItem branchesItem = rootItem.expand().getNode(
+ labelProvider.getText(branches));
+ SWTBotTreeItem remoteItem = branchesItem.expand().getNode(
+ labelProvider.getText(remoteBranches));
+ return remoteItem;
+ }
+
+ public SWTBotTreeItem getWorkdirItem(SWTBotTree tree, File repositoryFile)
+ throws Exception {
+ Repository repository = lookupRepository(repositoryFile);
+ RepositoryNode root = new RepositoryNode(null, repository);
+
+ WorkingDirNode workdir = new WorkingDirNode(root, repository);
+
+ String rootText = labelProvider.getText(root);
+ SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
+ SWTBotTreeItem workdirItem = rootItem.expand().getNode(
+ labelProvider.getText(workdir));
+ return workdirItem;
+ }
+
+ public SWTBotTreeItem getRootItem(SWTBotTree tree, File repositoryFile)
+ throws Exception {
+ Repository repository = lookupRepository(repositoryFile);
+ RepositoryNode root = new RepositoryNode(null, repository);
+ String rootText = labelProvider.getText(root);
+ SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
+ return rootItem;
+ }
+
+ public SWTBotTreeItem getSymbolicRefsItem(SWTBotTree tree,
+ File repositoryFile) throws Exception {
+ Repository repository = lookupRepository(repositoryFile);
+ RepositoryNode root = new RepositoryNode(null, repository);
+ SymbolicRefsNode symrefsnode = new SymbolicRefsNode(root, repository);
+ SWTBotTreeItem rootItem = tree.getTreeItem(labelProvider.getText(root))
+ .expand();
+ SWTBotTreeItem symrefsitem = rootItem.getNode(labelProvider
+ .getText(symrefsnode));
+ return symrefsitem;
+ }
+
+ public SWTBotTreeItem getRemotesItem(SWTBotTree tree, File repositoryFile)
+ throws Exception {
+ Repository repository = lookupRepository(repositoryFile);
+ RepositoryNode root = new RepositoryNode(null, repository);
+ RemotesNode remotes = new RemotesNode(root, repository);
+
+ String rootText = labelProvider.getText(root);
+ SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
+ SWTBotTreeItem remotesItem = rootItem.expand().getNode(
+ labelProvider.getText(remotes));
+ return remotesItem;
+ }
+
+ public Repository lookupRepository(File directory) throws Exception {
+ return org.eclipse.egit.core.Activator.getDefault()
+ .getRepositoryCache().lookupRepository(directory);
+ }
+
+}

Back to the top