Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot')
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AddChangelogEntrySWTBotTest.java275
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AllSWTBotTests.java30
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/CreateChangeLogFromHistorySWTBotTest.java198
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/DisabledPrepareChangelogSWTBotTest.java104
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/FormatChangeLogSWTBotTest.java144
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/PrepareChangelogSWTBotTest.java250
6 files changed, 1001 insertions, 0 deletions
diff --git a/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AddChangelogEntrySWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AddChangelogEntrySWTBotTest.java
new file mode 100644
index 0000000000..ba82f0c838
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AddChangelogEntrySWTBotTest.java
@@ -0,0 +1,275 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc. and others.
+ * 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.linuxtools.changelog.ui.tests.swtbot;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.linuxtools.changelog.tests.fixtures.ChangeLogTestProject;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorer;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.IEditorReference;
+import org.hamcrest.Matcher;
+import org.hamcrest.core.IsInstanceOf;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName;
+import static org.hamcrest.Matchers.allOf;
+
+
+/**
+ * UI tests for "ChangeLog Entry" (CTRL+ALT+C).
+ *
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class AddChangelogEntrySWTBotTest {
+
+ private static SWTWorkbenchBot bot;
+ private static SWTBotTree projectExplorerViewTree;
+ private ChangeLogTestProject project;
+ private static final String OFFSET_MARKER = "<-- SELECT -->";
+ // The name of the test project, we create
+ private final String PROJECT_NAME = "changelog-java-project";
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // delay click speed; with this turned on things get flaky
+ //System.setProperty("org.eclipse.swtbot.playback.delay", "200");
+ bot = new SWTWorkbenchBot();
+ try {
+ bot.viewByTitle("Welcome").close();
+ } catch (WidgetNotFoundException e) {
+ // ignore
+ }
+ // Make sure project explorer is open and tree available
+ ProjectExplorer.openView();
+ projectExplorerViewTree = ProjectExplorer.getTree();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ // Create an empty test project
+ project = new ChangeLogTestProject(PROJECT_NAME);
+ project.addJavaNature(); // make it a Java project
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ this.project.getTestProject().delete(true, null);
+ }
+
+ /**
+ * ChangeLog editor should pop-up if inside an active editor
+ * and a ChangeLog file exists in the project. Tests the CTRL+ALT+c
+ * shortcut.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void canAddChangeLogEntryUsingShortCutIfSourceIsActive() throws Exception {
+ // Add a Java source file
+ String sourceCode = "package src;\n" +
+ "public class JavaTest {\n" +
+ "public static void main(String args[]) {\n" +
+ "//" + OFFSET_MARKER + "\n" +
+ "System.out.println(\"Hello World!\");\n" +
+ "}\n" +
+ "}\n";
+
+ assertNull(project.getTestProject().findMember( new Path(
+ "/src/JavaTest.java")));
+ InputStream newFileInputStream = new ByteArrayInputStream(
+ sourceCode.getBytes());
+ project.addFileToProject("/src", "JavaTest.java", newFileInputStream);
+
+ // Add a changelog file
+ newFileInputStream = new ByteArrayInputStream(
+ "".getBytes());
+ project.addFileToProject("/", "ChangeLog", newFileInputStream);
+
+ assertNotNull(project.getTestProject().findMember( new Path(
+ "/src/JavaTest.java")));
+ assertNotNull(project.getTestProject().findMember( new Path(
+ "/ChangeLog")));
+
+ // Open JavaTest.java in an editor
+ projectExplorerViewTree.expandNode(PROJECT_NAME).expandNode("src").expandNode("JavaTest.java").doubleClick();
+
+ Matcher<?> editorMatcher = allOf(
+ IsInstanceOf.instanceOf(IEditorReference.class),
+ withPartName("JavaTest.java")
+ );
+ // Wait for Java editor to open
+ bot.waitUntil(Conditions.waitForEditor((Matcher<IEditorReference>) editorMatcher));
+ SWTBotEditor swtBoteditor = bot.editorByTitle("JavaTest.java");
+ SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
+ eclipseEditor.selectLine(getLineOfOffsetMarker(sourceCode));
+
+ // Press: CTRL + ALT + c
+ eclipseEditor.pressShortcut(Keystrokes.CTRL, Keystrokes.ALT, KeyStroke.getInstance("C"));
+ // Wait for ChangeLog editor to open
+ editorMatcher = allOf(
+ IsInstanceOf.instanceOf(IEditorReference.class),
+ withPartName("ChangeLog")
+ );
+ bot.waitUntil(Conditions.waitForEditor((Matcher<IEditorReference>) editorMatcher));
+ swtBoteditor = bot.activeEditor();
+ swtBoteditor.save(); // save to avoid "save changes"-pop-up
+ assertEquals("ChangeLog", swtBoteditor.getTitle());
+ eclipseEditor = swtBoteditor.toTextEditor();
+ // make sure expected entry has been added.
+ assertTrue(eclipseEditor.getText().contains("\t* src/JavaTest.java (main):"));
+ }
+
+ /**
+ * ChangeLog editor should pop-up if inside an active editor
+ * and a ChangeLog file exists in the project. Tests the "Edit" => "ChangeLog Entry"
+ * menu item.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void canAddChangeLogEntryUsingEditMenuIfSourceIsActive() throws Exception {
+ // Add a Java source file
+ String sourceCode = "package src;\n" +
+ "public class JavaTest {\n" +
+ "public static void main(String args[]) {\n" +
+ "//" + OFFSET_MARKER + "\n" +
+ "System.out.println(\"Hello World!\");\n" +
+ "}\n" +
+ "}\n";
+
+ assertNull(project.getTestProject().findMember( new Path(
+ "/src/JavaTest.java")));
+ InputStream newFileInputStream = new ByteArrayInputStream(
+ sourceCode.getBytes());
+ project.addFileToProject("/src", "JavaTest.java", newFileInputStream);
+
+ // Add a changelog file
+ newFileInputStream = new ByteArrayInputStream(
+ "".getBytes());
+ project.addFileToProject("/", "ChangeLog", newFileInputStream);
+
+ assertNotNull(project.getTestProject().findMember( new Path(
+ "/src/JavaTest.java")));
+ assertNotNull(project.getTestProject().findMember( new Path(
+ "/ChangeLog")));
+
+ // Open JavaTest.java in an editor
+ SWTBotTreeItem projectItem = projectExplorerViewTree.expandNode(PROJECT_NAME);
+// for (SWTBotTreeItem i: projectItem.getItems()) {
+// System.out.println(i.getText());
+// }
+ projectItem.expandNode("src").expandNode("JavaTest.java").doubleClick();
+
+ Matcher<?> editorMatcher = allOf(
+ IsInstanceOf.instanceOf(IEditorReference.class),
+ withPartName("JavaTest.java")
+ );
+ // Wait for editor to open
+ bot.waitUntil(Conditions.waitForEditor((Matcher<IEditorReference>) editorMatcher));
+ SWTBotEditor swtBoteditor = bot.editorByTitle("JavaTest.java");
+ SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
+ eclipseEditor.selectLine(getLineOfOffsetMarker(sourceCode));
+
+ // Click menu item.
+ bot.menu("Edit").menu("ChangeLog Entry").click();
+ // Wait for ChangeLog editor to open
+ editorMatcher = allOf(
+ IsInstanceOf.instanceOf(IEditorReference.class),
+ withPartName("ChangeLog")
+ );
+ bot.waitUntil(Conditions.waitForEditor((Matcher<IEditorReference>) editorMatcher));
+ swtBoteditor = bot.activeEditor();
+ swtBoteditor.save(); // save to avoid "save changes"-pop-up
+ assertEquals("ChangeLog", swtBoteditor.getTitle());
+ eclipseEditor = swtBoteditor.toTextEditor();
+ // make sure expected entry has been added.
+ assertTrue(eclipseEditor.getText().contains("\t* src/JavaTest.java (main):"));
+ }
+
+ /**
+ * FIXME: Disable menu item instead of showing it and doing nothing.
+ *
+ * This test throws WidgetNotFountException (i.e. shouldn't open any editor).
+ */
+ @Test(expected=WidgetNotFoundException.class)
+ public void shouldDoNothingIfNoEditorIsActive() {
+ assertNull(project.getTestProject().findMember( new Path("/src/dummy")));
+ try {
+ project.addFileToProject("src", "dummy", new ByteArrayInputStream("".getBytes()));
+ } catch (CoreException e) {
+ fail("Could not add /src/dummy file to project");
+ }
+ assertNotNull(project.getTestProject().findMember( new Path("/src/dummy")));
+ // Make sure we are in the project explorer view and no editors are open
+ closeAllEditors();
+ projectExplorerViewTree.expandNode(PROJECT_NAME).expandNode("src");
+ // Try to create ChangeLog
+ bot.menu("Edit").menu("ChangeLog Entry").click();
+ // Don't wait 5 secs
+ long oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 1000; // give it a full second :)
+ bot.activeEditor();
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+ }
+
+ /**
+ * @param The source text.
+ * @return The index of the first line containing the OFFSET_MARKER string in sourceCode.
+ * -1 if not found.
+ */
+ private int getLineOfOffsetMarker(String sourceCode) {
+ // select line containing the println() statement.
+ int offset = -1, i = 0;
+ for (String line: sourceCode.split("\n")) {
+ if (line.indexOf(OFFSET_MARKER) >= 0) {
+ offset = i;
+ break;
+ }
+ i++;
+ }
+ return offset;
+ }
+
+ /**
+ * Close all active editors.
+ */
+ private void closeAllEditors() {
+ SWTBotEditor currEditor;
+ try {
+ do {
+ currEditor = bot.activeEditor();
+ currEditor.close();
+ } while (currEditor != null);
+ } catch (WidgetNotFoundException e) {
+ // all closed
+ }
+ }
+
+}
diff --git a/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AllSWTBotTests.java b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AllSWTBotTests.java
new file mode 100644
index 0000000000..49e60230ae
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AllSWTBotTests.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc. and others.
+ * 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.linuxtools.changelog.ui.tests.swtbot;
+
+import org.junit.runners.Suite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * Run as SWTBot test.
+ *
+ */
+@RunWith(Suite.class)
+@SuiteClasses({
+ AddChangelogEntrySWTBotTest.class,
+ PrepareChangelogSWTBotTest.class,
+ DisabledPrepareChangelogSWTBotTest.class,
+ CreateChangeLogFromHistorySWTBotTest.class,
+ FormatChangeLogSWTBotTest.class
+ }
+)
+
+public class AllSWTBotTests {
+ // empty
+}
diff --git a/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/CreateChangeLogFromHistorySWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/CreateChangeLogFromHistorySWTBotTest.java
new file mode 100644
index 0000000000..9c84e9a9c1
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/CreateChangeLogFromHistorySWTBotTest.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc. and others.
+ * 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.linuxtools.changelog.ui.tests.swtbot;
+
+import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.ContextMenuHelper;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorer;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.SVNProject;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.SVNProjectCreatedCondition;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.TableAppearsCondition;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+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.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.IEditorReference;
+import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
+import org.hamcrest.core.IsInstanceOf;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * UI tests for creating changelogs from SVN history (commit messages).
+ *
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class CreateChangeLogFromHistorySWTBotTest {
+
+ private static SWTWorkbenchBot bot;
+ private static SWTBotTree projectExplorerViewTree;
+ private IProject project;
+ private SVNProject subversionProject;
+ // The name of the test project, we create
+ private final String PROJECT_NAME = "org.eclipse.linuxtools.changelog.tests";
+ // An available SVN repo
+ private final String SVN_PROJECT_URL = "svn://dev.eclipse.org/svnroot/technology/" +
+ "org.eclipse.linuxtools/changelog/trunk";
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // delay click speed
+ //System.setProperty("org.eclipse.swtbot.playback.delay", "200");
+ bot = new SWTWorkbenchBot();
+ try {
+ bot.viewByTitle("Welcome").close();
+ } catch (WidgetNotFoundException e) {
+ // ignore
+ }
+ // Make sure project explorer is open and tree available
+ ProjectExplorer.openView();
+ projectExplorerViewTree = ProjectExplorer.getTree();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ // Do an SVN checkout of the changelog.tests plugin
+ subversionProject = new SVNProject(bot);
+ project = subversionProject.setProjectName(PROJECT_NAME).setRepoURL(SVN_PROJECT_URL).checkoutProject();
+ bot.waitUntil(new SVNProjectCreatedCondition(PROJECT_NAME));
+ ProjectExplorer.openView();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ this.project.delete(true, null);
+ // discard existing repo from previous test runs
+ try {
+ subversionProject.discardRepositoryLocation();
+ } catch (WidgetNotFoundException e) {
+ // Ignore case if repository not existing
+ }
+ }
+
+ /**
+ * Create changelog from SVN history (commit messages).
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings({ "unchecked" })
+ @Test
+ public void canPrepareChangeLogFromSVNHistory() throws Exception {
+ // select ChangeLog file
+ String teamProviderString = "[changelog/trunk/" + PROJECT_NAME + "]";
+ SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME, teamProviderString);
+ long oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 5000;
+ bot.waitUntil(new ProjectExplorerTreeItemAppearsCondition(projectExplorerViewTree, PROJECT_NAME, teamProviderString, "ChangeLog"));
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+ SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
+ changeLogItem.select();
+
+ // open history for ChangeLog file
+ clickOnShowHistory(projectExplorerViewTree);
+ SWTBot historyViewBot = bot.viewByTitle("History").bot();
+ // wait for SVN revision table to appear
+ oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 3 * 5000;
+ historyViewBot.waitUntil(new TableAppearsCondition());
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+ SWTBotTable historyTable = historyViewBot.table();
+ historyTable.select(0); // select the first row
+
+ // right-click => Generate Changelog...
+ clickOnGenerateChangeLog(historyTable);
+ bot.waitUntil(Conditions.shellIsActive("Generate ChangeLog"));
+ SWTBotShell shell = bot.shell("Generate ChangeLog");
+
+ SWTBot generateChangelogBot = shell.bot();
+ generateChangelogBot.radio("Clipboard").click();
+ generateChangelogBot.button("OK").click();
+
+ // create and open a new file for pasting
+ String pasteFile = "newFile";
+ IFile newFile = project.getFile(new Path(pasteFile));
+ newFile.create(new ByteArrayInputStream("".getBytes()) /* empty content */, false, null);
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+
+ assertNotNull(project.findMember(new Path(pasteFile)));
+
+ ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME,
+ teamProviderString).expandNode(pasteFile).select().doubleClick();
+ Matcher<?> editorMatcher = Matchers.allOf(
+ IsInstanceOf.instanceOf(IEditorReference.class),
+ withPartName(pasteFile)
+ );
+ bot.waitUntil(Conditions.waitForEditor((Matcher<IEditorReference>) editorMatcher));
+ oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+ SWTBotEditor swtBoteditor = bot.activeEditor();
+ assertEquals(pasteFile, swtBoteditor.getTitle());
+ SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
+
+ // go to beginning of editor
+ eclipseEditor.selectRange(0, 0, 0);
+ // paste
+ eclipseEditor.pressShortcut(Keystrokes.CTRL, KeyStroke.getInstance("V"));
+ swtBoteditor.save();
+ // make sure some changelog like text was pasted
+ String text = eclipseEditor.getText();
+ assertTrue(!text.equals(""));
+ // FIXME: Add a better assertion. Not sure what would be a good one.
+// eclipseEditor.selectLine(2); // select third line
+// final String actualThirdLineContent = eclipseEditor.getSelection();
+// System.out.println(actualThirdLineContent);
+// System.out.println(text);
+// assertTrue(actualThirdLineContent.contains("\t* "));
+ }
+
+ /**
+ * Helper method for right-clicking => Generate ChangeLog in History
+ * view table.
+ *
+ * Pre: History view table row selected.
+ */
+ private void clickOnGenerateChangeLog(SWTBotTable table) {
+ String menuItem = "Generate ChangeLog...";
+ ContextMenuHelper.clickContextMenu(table, menuItem);
+ }
+
+ /**
+ * Helper method for right-click => Team => Show History.
+ */
+ private void clickOnShowHistory(SWTBotTree tree) {
+ String menuItem = "Team";
+ String subMenuItem = "Show History";
+ ContextMenuHelper.clickContextMenu(tree, menuItem, subMenuItem);
+ }
+
+}
diff --git a/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/DisabledPrepareChangelogSWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/DisabledPrepareChangelogSWTBotTest.java
new file mode 100644
index 0000000000..972f050396
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/DisabledPrepareChangelogSWTBotTest.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc. and others.
+ * 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.linuxtools.changelog.ui.tests.swtbot;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.changelog.tests.fixtures.ChangeLogTestProject;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorer;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ *
+ * UI test for "Prepare ChangeLog" when project not shared.
+ *
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class DisabledPrepareChangelogSWTBotTest {
+
+ private static SWTWorkbenchBot bot;
+ private static SWTBotTree projectExplorerViewTree;
+ private final String projectName = "not-shared";
+ private ChangeLogTestProject project;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // delay click speed
+ //System.setProperty("org.eclipse.swtbot.playback.delay", "200");
+ bot = new SWTWorkbenchBot();
+ try {
+ bot.viewByTitle("Welcome").close();
+ } catch (WidgetNotFoundException e) {
+ // ignore
+ }
+ // Make sure project explorer is open and tree available
+ ProjectExplorer.openView();
+ projectExplorerViewTree = ProjectExplorer.getTree();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ project = new ChangeLogTestProject(projectName);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ this.project.getTestProject().delete(true, null);
+ }
+
+ /**
+ * If the project is not shared by any CVS or SVN team provider, "Prepare ChangeLog"
+ * should be disabled.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void cannotPrepareChangeLogOnNonCVSOrSVNProject() throws Exception {
+ assertNull(project.getTestProject().findMember(new Path("/ChangeLog")));
+
+ final String changeLogContent = "2010-12-08 Will Probe <will@example.com>\n\n" +
+ "\t* path/to/some/non-existing/file.c: New file.\n";
+ project.addFileToProject("/", "ChangeLog", new ByteArrayInputStream(changeLogContent.getBytes()));
+
+ assertNotNull(project.getTestProject().findMember(new Path("/ChangeLog")));
+
+ // select ChangeLog file
+ String teamProviderString = "n/a";
+ SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, projectName, teamProviderString);
+ SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
+ changeLogItem.select();
+ long oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 100;
+ try {
+ bot.menu("Prepare ChangeLog").click(); // Should be disabled (throws exception)
+ fail("'Prepare ChangeLog' should be disabled");
+ } catch (TimeoutException e) {
+ assertTrue(e.getMessage().contains("The widget with mnemonic 'Prepare ChangeLog' was not enabled."));
+ }
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+ }
+
+}
diff --git a/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/FormatChangeLogSWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/FormatChangeLogSWTBotTest.java
new file mode 100644
index 0000000000..54b44fc8dd
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/FormatChangeLogSWTBotTest.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc. and others.
+ * 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.linuxtools.changelog.ui.tests.swtbot;
+
+import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.linuxtools.changelog.tests.fixtures.ChangeLogTestProject;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorer;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.IEditorReference;
+import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
+import org.hamcrest.core.IsInstanceOf;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * UI tests for formatting ChangeLog files.
+ *
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class FormatChangeLogSWTBotTest {
+
+ private static SWTWorkbenchBot bot;
+ private static SWTBotTree projectExplorerViewTree;
+ private ChangeLogTestProject project;
+ // The name of the test project, we create
+ private final String PROJECT_NAME = "org.eclipse.linuxtools.changelog.ui.formattestproject";
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // delay click speed
+ //System.setProperty("org.eclipse.swtbot.playback.delay", "200");
+ bot = new SWTWorkbenchBot();
+ try {
+ bot.viewByTitle("Welcome").close();
+ } catch (WidgetNotFoundException e) {
+ // ignore
+ }
+ // Make sure project explorer is open and tree available
+ ProjectExplorer.openView();
+ projectExplorerViewTree = ProjectExplorer.getTree();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ project = new ChangeLogTestProject(PROJECT_NAME);
+ ProjectExplorer.openView();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ this.project.getTestProject().delete(true, null);
+ }
+
+ /**
+ * Simple test for ChangeLog formatting.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings({ "unchecked" })
+ @Test
+ public void canFormatChangeLogFile() throws Exception {
+ // add a ChangeLog file
+ assertNull(project.getTestProject().findMember(new Path("/ChangeLog")));
+ final String changelogContent = "2010-12-14 Severin Gehwolf <sgehwolf@redhat.com>\n\n" +
+ "\tAdded org.eclipse.linuxtools.changelog.tests.ui plug-in.\n" +
+ "\t* .classpath: New file.\n" +
+ "\t* .project: New file.\n" +
+ "\t* .settings/org.eclipse.jdt.core.prefs: New file.\n" +
+ "\t* build.properties: New file.\n" +
+ "\t* src/log4j.xml: New file.\n" +
+ "\t* src/org/eclipse/linuxtools/changelog/tests/ui/utils/ContextMenuHelper.java: New file.\n" +
+ "\t* src/org/eclipse/linuxtools/changelog/tests/ui/utils/ProjectExplorer.java: New file.\n" +
+ "\t* src/org/eclipse/linuxtools/changelog/tests/ui/utils/ProjectExplorerTreeItemAppearsCondition.java: New file.\n";
+ project.addFileToProject("/", "ChangeLog", new ByteArrayInputStream(changelogContent.getBytes()));
+ assertNotNull(project.getTestProject().findMember(new Path("/ChangeLog")));
+
+ // select ChangeLog file
+ String teamProviderString = "n/a";
+ SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME, teamProviderString);
+ long oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 5000;
+ bot.waitUntil(new ProjectExplorerTreeItemAppearsCondition(projectExplorerViewTree, PROJECT_NAME, teamProviderString, "ChangeLog"));
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+ SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
+ changeLogItem.doubleClick(); // should open ChangeLog file
+
+ oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 3 * 5000;
+ // Wait for ChangeLog editor to open
+ Matcher<?> editorMatcher = Matchers.allOf(
+ IsInstanceOf.instanceOf(IEditorReference.class),
+ withPartName("ChangeLog")
+ );
+ bot.waitUntil(Conditions.waitForEditor((Matcher<IEditorReference>) editorMatcher));
+ SWTBotEditor swtBoteditor = bot.activeEditor();
+ assertEquals("ChangeLog", swtBoteditor.getTitle());
+
+ SWTBotEclipseEditor swtBotEclipseEditor = swtBoteditor.toTextEditor();
+
+ // Add two extra lines after the first date line
+ swtBotEclipseEditor.insertText(1, 0, "\n\n");
+ // Should have 3 empty lines between date-line and first file entry
+ swtBotEclipseEditor.selectRange(1, 0, 3);
+
+ // format: ESC CTRL+F
+ swtBotEclipseEditor.pressShortcut(Keystrokes.ESC);
+ swtBotEclipseEditor.pressShortcut(Keystrokes.CTRL, KeyStroke.getInstance("F"));
+ swtBoteditor.save();
+ String secondLine = swtBotEclipseEditor.getTextOnLine(1);
+ String thirdLine = swtBotEclipseEditor.getTextOnLine(2);
+ // FIXME: These assertions are lame.
+ assertEquals("", secondLine);
+ assertTrue(!"".equals(thirdLine));
+ }
+
+}
diff --git a/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/PrepareChangelogSWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/PrepareChangelogSWTBotTest.java
new file mode 100644
index 0000000000..8d252d093f
--- /dev/null
+++ b/changelog/org.eclipse.linuxtools.changelog.ui.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/PrepareChangelogSWTBotTest.java
@@ -0,0 +1,250 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc. and others.
+ * 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.linuxtools.changelog.ui.tests.swtbot;
+
+import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorer;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.SVNProject;
+import org.eclipse.linuxtools.changelog.ui.tests.utils.SVNProjectCreatedCondition;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.IEditorReference;
+import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
+import org.hamcrest.core.IsInstanceOf;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ *
+ * UI tests for "Prepare ChangeLog" (CTRL+ALT+P) and the clipboard magic
+ * (CTRL+ALT+V).
+ *
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class PrepareChangelogSWTBotTest {
+
+ private static SWTWorkbenchBot bot;
+ private static SWTBotTree projectExplorerViewTree;
+ private SVNProject subversionProject;
+ private IProject project;
+ // The name of the test project, we create
+ private final String PROJECT_NAME = "org.eclipse.linuxtools.changelog.tests";
+ // An available SVN repo
+ private final String SVN_PROJECT_URL = "svn://dev.eclipse.org/svnroot/technology/" +
+ "org.eclipse.linuxtools/changelog/trunk";
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // delay click speed
+ //System.setProperty("org.eclipse.swtbot.playback.delay", "200");
+ bot = new SWTWorkbenchBot();
+ try {
+ bot.viewByTitle("Welcome").close();
+ } catch (WidgetNotFoundException e) {
+ // ignore
+ }
+ // Make sure project explorer is open and tree available
+ ProjectExplorer.openView();
+ projectExplorerViewTree = ProjectExplorer.getTree();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ // Do an SVN checkout of the changelog.tests plugin
+ subversionProject = new SVNProject(bot);
+ project = subversionProject.setProjectName(PROJECT_NAME).setRepoURL(SVN_PROJECT_URL).checkoutProject();
+ bot.waitUntil(new SVNProjectCreatedCondition(PROJECT_NAME));
+ ProjectExplorer.openView();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ this.project.delete(true, null);
+ // discard existing repo from previous test runs
+ try {
+ subversionProject.discardRepositoryLocation();
+ } catch (WidgetNotFoundException e) {
+ // Ignore case if repository not existing
+ }
+ }
+
+ /**
+ * Basic prepare changelog test.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void canPrepareChangeLog() throws Exception {
+ // Find manifest file
+ IResource manifest = project.findMember(new Path("/META-INF/MANIFEST.MF"));
+ assertNotNull(manifest);
+ // delete it
+ manifest.delete(true, null);
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+
+ // select ChangeLog file
+ String teamProviderString = "[changelog/trunk/" + PROJECT_NAME + "]";
+ SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME, teamProviderString);
+ SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
+ changeLogItem.select();
+ bot.menu("Prepare ChangeLog").click(); // Should be unique
+
+ long oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 3 * 5000;
+ // Wait for ChangeLog editor to open
+ Matcher<?> editorMatcher = Matchers.allOf(
+ IsInstanceOf.instanceOf(IEditorReference.class),
+ withPartName("ChangeLog")
+ );
+ bot.waitUntil(Conditions.waitForEditor((Matcher<IEditorReference>) editorMatcher));
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+
+ SWTBotEditor swtBoteditor = bot.activeEditor();
+ swtBoteditor.save(); // save to avoid "save changes"-pop-up
+ assertEquals("ChangeLog", swtBoteditor.getTitle());
+ SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
+ // make sure expected entry has been added.
+ assertTrue(matchHead(eclipseEditor.getText(), "\t* META-INF/MANIFEST.MF:", 3));
+ }
+
+ /**
+ * Should be able to save changes to ChangeLog file in clipboard.
+ * Tests CTRL + ALT + V functionality.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void canPrepareChangeLogAndSaveChangesInChangeLogFileToClipboard() throws Exception {
+ // Find manifest file
+ IResource manifest = project.findMember(new Path("/META-INF/MANIFEST.MF"));
+ assertNotNull(manifest);
+ // delete it
+ manifest.delete(true, null);
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+
+ // select ChangeLog file
+ String teamProviderString = "[changelog/trunk/" + PROJECT_NAME + "]";
+ SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME, teamProviderString);
+ long oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 5000;
+ bot.waitUntil(new ProjectExplorerTreeItemAppearsCondition(projectExplorerViewTree, PROJECT_NAME, teamProviderString, "ChangeLog"));
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+ SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
+ changeLogItem.select();
+ // CTRL + ALT + P
+ bot.activeShell().pressShortcut(Keystrokes.CTRL, Keystrokes.ALT, KeyStroke.getInstance("P"));
+
+ oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 3 * 5000;
+ // Wait for ChangeLog editor to open
+ Matcher<?> editorMatcher = Matchers.allOf(
+ IsInstanceOf.instanceOf(IEditorReference.class),
+ withPartName("ChangeLog")
+ );
+ bot.waitUntil(Conditions.waitForEditor((Matcher<IEditorReference>) editorMatcher));
+ SWTBotEditor swtBoteditor = bot.activeEditor();
+ swtBoteditor.save(); // save to avoid "save changes"-pop-up
+ assertEquals("ChangeLog", swtBoteditor.getTitle());
+ SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
+ // make sure expected entry has been added.
+ assertTrue(matchHead(eclipseEditor.getText(), "\t* META-INF/MANIFEST.MF:", 3));
+ eclipseEditor.selectLine(0); // select first line
+ final String expectedFirstLineContent = eclipseEditor.getSelection();
+
+ // save changes to clipboard: CTRL + ALT + V
+ eclipseEditor.pressShortcut(Keystrokes.CTRL, Keystrokes.ALT, KeyStroke.getInstance("V"));
+
+ // create and open a new file for pasting
+ String pasteFile = "newFile";
+ IFile newFile = project.getFile(new Path(pasteFile));
+ newFile.create(new ByteArrayInputStream("".getBytes()) /* empty content */, false, null);
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+
+ assertNotNull(project.findMember(new Path(pasteFile)));
+
+ ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME,
+ teamProviderString).expandNode(pasteFile).select().doubleClick();
+ //bot.activeShell().pressShortcut(Keystrokes.F3); // open file
+ editorMatcher = Matchers.allOf(
+ IsInstanceOf.instanceOf(IEditorReference.class),
+ withPartName(pasteFile)
+ );
+ bot.waitUntil(Conditions.waitForEditor((Matcher<IEditorReference>) editorMatcher));
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+ swtBoteditor = bot.activeEditor();
+ assertEquals(pasteFile, swtBoteditor.getTitle());
+ eclipseEditor = swtBoteditor.toTextEditor();
+
+ // go to beginning of editor
+ eclipseEditor.selectRange(0, 0, 0);
+ // paste
+ eclipseEditor.pressShortcut(Keystrokes.CTRL, KeyStroke.getInstance("V"));
+ swtBoteditor.save();
+ // make sure proper content was pasted
+ assertTrue(matchHead(eclipseEditor.getText(), "\t* META-INF/MANIFEST.MF:", 3));
+ eclipseEditor.selectLine(0); // select first line
+ final String actualFirstLineContent = eclipseEditor.getSelection();
+ assertEquals(expectedFirstLineContent, actualFirstLineContent);
+ }
+
+ /**
+ * Determine if first <code>i</code> lines in <code>text</code> contain
+ * the string <code>matchText</code>.
+ *
+ * @param text The text to compare to.
+ * @param matchText The match string to look for.
+ * @param i The number of lines in text to consider.
+ * @return
+ *
+ * @throws IllegalArgumentException if <code>i</code> is invalid.
+ */
+ private boolean matchHead(String text, String matchText, int i) throws IllegalArgumentException {
+ if ( i < 0 ) {
+ throw new IllegalArgumentException();
+ }
+ String[] lines = text.split("\n");
+ if ( lines.length < i ) {
+ throw new IllegalArgumentException();
+ }
+ // arguments appear to be good
+ for (int j = 0; j < i; j++) {
+ if (lines[j].contains(matchText)) {
+ return true;
+ }
+ }
+ return false; // no match
+ }
+
+}

Back to the top