summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorTomasz Zarna2012-02-26 16:04:42 (EST)
committer Tomasz Zarna2012-02-26 16:04:42 (EST)
commit5fdcd7594af6b027ee875d3ecf150a2f7b641df7 (patch)
treee44a7ead0117c79de237708e7c03b293e3d128b4
parent0af3920c50772983118ea438c2e5657299e76078 (diff)
downloadegit-5fdcd7594af6b027ee875d3ecf150a2f7b641df7.zip
egit-5fdcd7594af6b027ee875d3ecf150a2f7b641df7.tar.gz
egit-5fdcd7594af6b027ee875d3ecf150a2f7b641df7.tar.bz2
Add UI tests for File and Workspace options in Create Patch wizardrefs/changes/67/5167/1
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CreatePatchWizard.java9
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java146
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/LocationPage.java34
3 files changed, 156 insertions, 33 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CreatePatchWizard.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CreatePatchWizard.java
index d57de44..cb41f2a 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CreatePatchWizard.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CreatePatchWizard.java
@@ -10,6 +10,7 @@ package org.eclipse.egit.ui.common;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.egit.ui.test.team.actions.LocationPage;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
@@ -57,4 +58,12 @@ public class CreatePatchWizard {
public void close() {
shell.close();
}
+
+ public LocationPage getLocationPage() {
+ return new LocationPage(shell);
+ }
+
+ public SWTBotShell getShell() {
+ return shell;
+ }
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
index b613712..ca6375d 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java
@@ -10,6 +10,7 @@ package org.eclipse.egit.ui.test.team.actions;
import static org.junit.Assert.assertEquals;
+import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@@ -18,16 +19,27 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.core.op.CommitOperation;
+import org.eclipse.egit.core.op.ResetOperation;
+import org.eclipse.egit.core.op.ResetOperation.ResetType;
+import org.eclipse.egit.core.op.TagOperation;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.common.CreatePatchWizard;
import org.eclipse.egit.ui.common.CreatePatchWizard.NoChangesPopup;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.test.TestUtil;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.TagBuilder;
+import org.eclipse.jgit.storage.file.FileRepository;
+import org.eclipse.jgit.util.IO;
+import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
+import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -39,37 +51,51 @@ public class CreatePatchActionTest extends LocalRepositoryTestCase {
private static SWTBotPerspective perspective;
+ private static Repository repo;
+
+ private static final String TAG_NAME = "savepoint";
+
+ private static final String PATCH_FILE = "test.patch";
+
+ private static final String EXPECTED_PATCH_CONTENT = //
+ "diff --git a/GeneralProject/folder/test.txt b/GeneralProject/folder/test.txt\n"
+ + "index e256dbb..d070357 100644\n"
+ + "--- a/GeneralProject/folder/test.txt\n"
+ + "+++ b/GeneralProject/folder/test.txt\n"
+ + "@@ -1 +1 @@\n"
+ + "-oldContent\n"
+ + "\\ No newline at end of file\n"
+ + "+newContent\n" //
+ + "\\ No newline at end of file";
+
@BeforeClass
public static void setup() throws Exception {
perspective = bot.activePerspective();
bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
- createProjectAndCommitToRepository();
- waitInUI();
- }
+ File gitDir = createProjectAndCommitToRepository();
+ repo = new FileRepository(gitDir);
- @AfterClass
- public static void shutdown() {
- perspective.activate();
- }
-
- @Test
- public void testNoChanges() throws Exception {
- // commit all files
IFile[] commitables = getAllFiles();
ArrayList<IFile> untracked = new ArrayList<IFile>();
untracked.addAll(Arrays.asList(commitables));
- CommitOperation op = new CommitOperation(commitables, untracked,
+ CommitOperation cop = new CommitOperation(commitables, untracked,
TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
- op.setAmending(true);
- op.execute(null);
+ cop.setAmending(true);
+ cop.execute(null);
+
+ TagBuilder tag = new TagBuilder();
+ tag.setTag(TAG_NAME);
+ tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
+ tag.setMessage("I'm a savepoint");
+ tag.setObjectId(repo.resolve(repo.getFullBranch()),
+ Constants.OBJ_COMMIT);
+ TagOperation top = new TagOperation(repo, tag, false);
+ top.execute(null);
- CreatePatchWizard.openWizard(PROJ1);
- NoChangesPopup popup = new NoChangesPopup(
- bot.shell(UIText.GitCreatePatchAction_cannotCreatePatch));
- popup.cancelPopup();
+ waitInUI();
}
- private IFile[] getAllFiles() {
+ private static IFile[] getAllFiles() {
IProject firstProject = ResourcesPlugin.getWorkspace().getRoot()
.getProject(PROJ1);
IProject secondProject = ResourcesPlugin.getWorkspace().getRoot()
@@ -88,29 +114,83 @@ public class CreatePatchActionTest extends LocalRepositoryTestCase {
secondtextFile2 };
}
+ @AfterClass
+ public static void shutdown() {
+ perspective.activate();
+ }
+
+ @After
+ public void rollback() throws Exception {
+ ResetOperation rop = new ResetOperation(repo, TAG_NAME, ResetType.HARD);
+ rop.execute(null);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(PROJ1);
+ project.getFile(PATCH_FILE).delete(true, null);
+ }
+
+ @Test
+ public void testNoChanges() throws Exception {
+ CreatePatchWizard.openWizard(PROJ1);
+ NoChangesPopup popup = new NoChangesPopup(
+ bot.shell(UIText.GitCreatePatchAction_cannotCreatePatch));
+ popup.cancelPopup();
+ }
+
@Test
public void testClipboard() throws Exception {
touchAndSubmit("oldContent", null);
touch("newContent");
waitInUI();
+
+ CreatePatchWizard createPatchWizard = openCreatePatchWizard();
+ createPatchWizard.finish();
+
+ bot.waitUntil(Conditions.shellCloses(createPatchWizard.getShell()));
+
+ assertClipboard(EXPECTED_PATCH_CONTENT);
+ }
+
+ @Test
+ public void testFilesystem() throws Exception {
+ touchAndSubmit("oldContent", null);
+ touch("newContent");
+ waitInUI();
+
CreatePatchWizard createPatchWizard = openCreatePatchWizard();
+ LocationPage locationPage = createPatchWizard.getLocationPage();
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(PROJ1);
+ File patch = new File(project.getLocation().toFile(), PATCH_FILE);
+ locationPage.selectFilesystem(patch.toString());
createPatchWizard.finish();
+
+ bot.waitUntil(Conditions.shellCloses(createPatchWizard.getShell()));
+
+ byte[] bytes = IO.readFully(patch);
+ String patchContent = new String(bytes, "UTF-8");
+
+ assertEquals(EXPECTED_PATCH_CONTENT, patchContent);
+ }
+
+ @Test
+ public void testWorkspace() throws Exception {
+ touchAndSubmit("oldContent", null);
+ touch("newContent");
waitInUI();
- StringBuilder sb = new StringBuilder();
- sb.append(
- "diff --git a/GeneralProject/folder/test.txt b/GeneralProject/folder/test.txt")
- .append("\n");
- sb.append("index e256dbb..d070357 100644").append("\n");
- sb.append("--- a/GeneralProject/folder/test.txt").append("\n");
- sb.append("+++ b/GeneralProject/folder/test.txt").append("\n");
- sb.append("@@ -1 +1 @@").append("\n");
- sb.append("-oldContent").append("\n");
- sb.append("\\ No newline at end of file").append("\n");
- sb.append("+newContent").append("\n");
- sb.append("\\ No newline at end of file");
-
- assertClipboard(sb.toString());
+ CreatePatchWizard createPatchWizard = openCreatePatchWizard();
+ LocationPage locationPage = createPatchWizard.getLocationPage();
+ locationPage.selectWorkspace("/" + PROJ1 + "/" + PATCH_FILE);
+ createPatchWizard.finish();
+
+ bot.waitUntil(Conditions.shellCloses(createPatchWizard.getShell()));
+
+ IFile patch = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(PROJ1).getFile(PATCH_FILE);
+ byte[] bytes = IO.readFully(patch.getLocation().toFile());
+ String patchContent = new String(bytes, patch.getCharset());
+
+ assertEquals(EXPECTED_PATCH_CONTENT, patchContent);
}
private CreatePatchWizard openCreatePatchWizard() throws Exception {
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/LocationPage.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/LocationPage.java
new file mode 100644
index 0000000..8220a84
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/LocationPage.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (C) 2012, Tomasz Zarna <Tomasz.Zarna@pl.ibm.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.team.actions;
+
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+
+public class LocationPage {
+ private SWTBotShell shell;
+
+ public LocationPage(SWTBotShell shell) {
+ this.shell = shell;
+ }
+
+ void selectClipboard() {
+ shell.bot().radio(UIText.GitCreatePatchWizard_Clipboard).click();
+ }
+
+ void selectFilesystem(final String path) {
+ shell.bot().radio(UIText.GitCreatePatchWizard_File).click();
+ shell.bot().text(0).setText(path);
+ }
+
+ void selectWorkspace(final String path) {
+ shell.bot().radio(UIText.GitCreatePatchWizard_Workspace).click();
+ shell.bot().text(1).setText(path);
+ }
+}