diff options
| author | Tomasz Zarna | 2012-02-17 15:26:53 +0000 |
|---|---|---|
| committer | Matthias Sohn | 2012-02-17 15:26:53 +0000 |
| commit | 44672820918b956c621e9af560ad9daf4eb36fd0 (patch) | |
| tree | a7578502970f91fcabc94bb0cb4f48709e852d81 | |
| parent | 7205115b9a2280ab366c75a03d0348245a4243a7 (diff) | |
| download | egit-44672820918b956c621e9af560ad9daf4eb36fd0.tar.gz egit-44672820918b956c621e9af560ad9daf4eb36fd0.tar.xz egit-44672820918b956c621e9af560ad9daf4eb36fd0.zip | |
Add a UI test for Create Patch wizard
Change-Id: I5e49ede1ac9fc0e01d05807f31a823ce1376452e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
4 files changed, 241 insertions, 17 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 new file mode 100644 index 0000000000..d57de4445f --- /dev/null +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/CreatePatchWizard.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.common; + +import org.eclipse.egit.ui.test.ContextMenuHelper; +import org.eclipse.egit.ui.test.TestUtil; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; + +public class CreatePatchWizard { + + public static class NoChangesPopup { + private SWTBotShell shell; + + public NoChangesPopup(SWTBotShell shell) { + this.shell = shell; + } + + public void cancelPopup() { + shell.close(); + } + } + + private static final SWTWorkbenchBot bot = new SWTWorkbenchBot(); + + protected static final TestUtil util = new TestUtil(); + + private SWTBotShell shell; + + public CreatePatchWizard(SWTBotShell shell) { + this.shell = shell; + } + + public static void openWizard(final String project) { + SWTBotTree projectExplorerTree = bot + .viewById("org.eclipse.jdt.ui.PackageExplorer").bot().tree(); + util.getProjectItem(projectExplorerTree, project).select(); + + String[] menuPath = new String[] { + util.getPluginLocalizedValue("TeamMenu.label"), + util.getPluginLocalizedValue("CreatePatchAction.label") }; + ContextMenuHelper.clickContextMenu(projectExplorerTree, menuPath); + } + + public void finish() { + shell.bot().button(IDialogConstants.FINISH_LABEL).click(); + } + + public void close() { + shell.close(); + } +} 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 index 714a00d794..15f40726e4 100644 --- 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 @@ -223,19 +223,19 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase { new ConnectProviderOperation(firstProject, gitDir).execute(null); - IProject secondPoject = ResourcesPlugin.getWorkspace().getRoot() + IProject secondProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(PROJ2); - if (secondPoject.exists()) - secondPoject.delete(true, null); + if (secondProject.exists()) + secondProject.delete(true, null); desc = ResourcesPlugin.getWorkspace().newProjectDescription(PROJ2); desc.setLocation(new Path(new File(myRepository.getWorkTree(), PROJ2) .getPath())); - secondPoject.create(desc, null); - secondPoject.open(null); + secondProject.create(desc, null); + secondProject.open(null); - IFolder secondfolder = secondPoject.getFolder(FOLDER); + IFolder secondfolder = secondProject.getFolder(FOLDER); secondfolder.create(false, true, null); IFile secondtextFile = secondfolder.getFile(FILE1); secondtextFile.create(new ByteArrayInputStream("Hello, world" @@ -248,7 +248,7 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase { // gitignore.create(new ByteArrayInputStream("/.project\n" // .getBytes(firstProject.getDefaultCharset())), false, null); - new ConnectProviderOperation(secondPoject, gitDir).execute(null); + new ConnectProviderOperation(secondProject, gitDir).execute(null); IFile[] commitables = new IFile[] { firstProject.getFile(".project"), textFile, textFile2, secondtextFile, secondtextFile2 }; @@ -413,19 +413,29 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase { } /** + * Modify with a random content and commit. + * * @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); + touchAndSubmit(newContent, commitMessage); + } + + /** + * Modify with the given content and commit. + * + * @param newContent + * new file content + * @param commitMessage + * may be null + * @throws Exception + */ + protected static void touchAndSubmit(String newContent, String commitMessage) + throws Exception { + IFile file = touch(newContent); IFile[] commitables = new IFile[] { file }; ArrayList<IFile> untracked = new ArrayList<IFile>(); @@ -441,6 +451,26 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase { op.execute(null); } + /** + * Modify with the given content. + * + * @param newContent + * new file content + * @return the modified file + * @throws Exception + */ + protected static IFile touch(final String newContent) 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")); + file.setContents( + new ByteArrayInputStream(newContent.getBytes(prj + .getDefaultCharset())), 0, null); + return file; + } + protected static void addAndCommit(IFile file, String commitMessage) throws Exception { IProject prj = file.getProject(); 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 index 39e909d6ba..8f711e8224 100644 --- 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 @@ -15,15 +15,15 @@ import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses( { BranchAndResetActionTest.class, // +@SuiteClasses({ BranchAndResetActionTest.class, // TagActionTest.class, // CommitActionTest.class, // PushActionTest.class, // FetchAndMergeActionTest.class, // DisconnectConnectTest.class, // ShowInTest.class, // - CompareActionsTest.class -}) + CompareActionsTest.class, // + CreatePatchActionTest.class }) public class AllTeamActionTests { // nothing } 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 new file mode 100644 index 0000000000..b613712a09 --- /dev/null +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CreatePatchActionTest.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * 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 static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; + +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.core.op.CommitOperation; +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.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.widgets.SWTBotShell; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests for the Team->Create Patch action + */ +public class CreatePatchActionTest extends LocalRepositoryTestCase { + + private static SWTBotPerspective perspective; + + @BeforeClass + public static void setup() throws Exception { + perspective = bot.activePerspective(); + bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate(); + createProjectAndCommitToRepository(); + waitInUI(); + } + + @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, + TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit"); + op.setAmending(true); + op.execute(null); + + CreatePatchWizard.openWizard(PROJ1); + NoChangesPopup popup = new NoChangesPopup( + bot.shell(UIText.GitCreatePatchAction_cannotCreatePatch)); + popup.cancelPopup(); + } + + private IFile[] getAllFiles() { + IProject firstProject = ResourcesPlugin.getWorkspace().getRoot() + .getProject(PROJ1); + IProject secondProject = ResourcesPlugin.getWorkspace().getRoot() + .getProject(PROJ2); + + IFolder folder = firstProject.getFolder(FOLDER); + IFile textFile = folder.getFile(FILE1); + IFile textFile2 = folder.getFile(FILE2); + + IFolder secondfolder = secondProject.getFolder(FOLDER); + IFile secondtextFile = secondfolder.getFile(FILE1); + IFile secondtextFile2 = secondfolder.getFile(FILE2); + + return new IFile[] { firstProject.getFile(".project"), textFile, + textFile2, secondProject.getFile(".project"), secondtextFile, + secondtextFile2 }; + } + + @Test + public void testClipboard() throws Exception { + touchAndSubmit("oldContent", null); + touch("newContent"); + waitInUI(); + CreatePatchWizard createPatchWizard = openCreatePatchWizard(); + createPatchWizard.finish(); + 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()); + } + + private CreatePatchWizard openCreatePatchWizard() throws Exception { + CreatePatchWizard.openWizard(PROJ1); + SWTBotShell shell = bot + .shell(UIText.GitCreatePatchWizard_CreatePatchTitle); + return new CreatePatchWizard(shell); + } + + private static void assertClipboard(final String expected) { + final String[] value = { null }; + Display.getDefault().syncExec(new Runnable() { + public void run() { + Clipboard clp = new Clipboard(Display.getCurrent()); + value[0] = (String) clp.getContents(TextTransfer.getInstance()); + clp.dispose(); + } + }); + assertEquals(expected, value[0]); + } +} |
