diff options
author | Severin Gehwolf | 2010-12-14 21:07:59 +0000 |
---|---|---|
committer | Severin Gehwolf | 2010-12-14 21:07:59 +0000 |
commit | 0b72f585eea7b1eedc858c50b4cf32a119707765 (patch) | |
tree | 9ed9674c265fd78c377eac35c7b93377d8b10fad /changelog/org.eclipse.linuxtools.changelog.tests | |
parent | 2e302c2eb079216aad7ab9f13fecc8ba614b027d (diff) | |
download | org.eclipse.linuxtools-0b72f585eea7b1eedc858c50b4cf32a119707765.tar.gz org.eclipse.linuxtools-0b72f585eea7b1eedc858c50b4cf32a119707765.tar.xz org.eclipse.linuxtools-0b72f585eea7b1eedc858c50b4cf32a119707765.zip |
2010-12-14 Severin Gehwolf <sgehwolf@redhat.com>
* Remove SWTBot tests (moved to separate plug-in).
Diffstat (limited to 'changelog/org.eclipse.linuxtools.changelog.tests')
17 files changed, 21 insertions, 1769 deletions
diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/ChangeLog b/changelog/org.eclipse.linuxtools.changelog.tests/ChangeLog index d2ffb7acca..88f3a1d089 100644 --- a/changelog/org.eclipse.linuxtools.changelog.tests/ChangeLog +++ b/changelog/org.eclipse.linuxtools.changelog.tests/ChangeLog @@ -1,4 +1,22 @@ 2010-12-14 Severin Gehwolf <sgehwolf@redhat.com> + + * src/log4j.xml: Removed. + * src/org/eclipse/linuxtools/changelog/tests/helpers/ContextMenuHelper.java: Removed. + * src/org/eclipse/linuxtools/changelog/tests/helpers/ProjectExplorer.java: Removed. + * src/org/eclipse/linuxtools/changelog/tests/helpers/ProjectExplorerTreeItemAppearsCondition.java: Removed. + * src/org/eclipse/linuxtools/changelog/tests/helpers/SVNProject.java: Removed. + * src/org/eclipse/linuxtools/changelog/tests/helpers/SVNProjectCreatedCondition.java: Removed. + * src/org/eclipse/linuxtools/changelog/tests/helpers/SVNReporsitoriesView.java: Removed. + * src/org/eclipse/linuxtools/changelog/tests/helpers/TableAppearsCondition.java: Removed. + * src/org/eclipse/linuxtools/changelog/tests/helpers/TreeItemAppearsCondition.java: Removed. + * src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AddChangelogEntrySWTBotTest.java: Removed. + * src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AllSWTBotTests.java: Removed. + * src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/CreateChangeLogFromHistorySWTBotTest.java: Removed. + * src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/DisabledPrepareChangelogSWTBotTest.java: Removed. + * src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/FormatChangeLogSWTBotTest.java: Removed. + * src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/PrepareChangelogSWTBotTest.java: Removed. + +2010-12-14 Severin Gehwolf <sgehwolf@redhat.com> * src/log4j.xml: New file. * src/org/eclipse/linuxtools/changelog/tests/helpers/ContextMenuHelper.java: New file. diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/META-INF/MANIFEST.MF b/changelog/org.eclipse.linuxtools.changelog.tests/META-INF/MANIFEST.MF index d7aab3123b..36b4276710 100644 --- a/changelog/org.eclipse.linuxtools.changelog.tests/META-INF/MANIFEST.MF +++ b/changelog/org.eclipse.linuxtools.changelog.tests/META-INF/MANIFEST.MF @@ -7,14 +7,7 @@ Bundle-Activator: org.eclipse.linuxtools.changelog.core.tests.TestsPluginActivat Bundle-Vendor: Eclipse.org Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, - org.junit4;bundle-version="4.8.1", - org.eclipse.swtbot.eclipse.core, - org.eclipse.swtbot.eclipse.finder, - org.eclipse.swtbot.junit4_x, - org.hamcrest, - org.apache.log4j, - org.eclipse.swtbot.go -Eclipse-RegisterBuddy: org.apache.log4j + org.junit4;bundle-version="4.8.1" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Import-Package: org.eclipse.cdt.core, @@ -43,3 +36,5 @@ Import-Package: org.eclipse.cdt.core, org.eclipse.ui.ide, org.eclipse.ui.part, org.eclipse.ui.texteditor +Export-Package: org.eclipse.linuxtools.changelog.tests.fixtures;x-friends:=org.eclipse.linuxtools.changelog.tests.ui, + org.eclipse.linuxtools.changelog.tests.helpers;x-friends:=org.eclipse.linuxtools.changelog.tests.ui diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/log4j.xml b/changelog/org.eclipse.linuxtools.changelog.tests/src/log4j.xml deleted file mode 100644 index 87414d37ef..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/log4j.xml +++ /dev/null @@ -1,60 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> -<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" - debug="false"> - - <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender"> - <param name="Target" value="System.out" /> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" - value="%d{dd MMM yyyy HH:mm:ss.SSS} - %25t - %-5p - %30c{1} - (%C{1}.java:%L) - %m%n" /> - </layout> - </appender> - - <appender name="fileAppender" class="org.apache.log4j.FileAppender"> - <param name="File" value="swtbot_tests.log" /> - <param name="Append" value="false" /> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" - value="%d{dd MMM yyyy HH:mm:ss.SSS} - %25t - %-5p - %30c{1} - (%C{1}.java:%L) - %m%n" /> - </layout> - </appender> - - <appender name="asyncAppender" class="org.apache.log4j.AsyncAppender"> - <!-- appender-ref ref="consoleAppender" / --> - <appender-ref ref="fileAppender" /> - </appender> - - <!-- don't log matchers, this is very high amount of chatter --> - <category name="org.eclipse.swtbot.swt.finder.matchers"> - <priority value="OFF" /> - </category> - - <!-- - don't log widget notification events, this is moderately high chatter - --> - <category name="org.eclipse.swtbot.swt.finder.widgets"> - <priority value="DEBUG" /> - </category> - - <!-- don't log finders, this is moderate chatter --> - <category name="org.eclipse.swtbot.swt.finder.finders"> - <priority value="DEBUG" /> - </category> - - <category name="org.eclipse.swtbot.swt.finder.keyboard"> - <!-- set to a value higher than debug to turn on. --> - <priority value="DEBUG" /> - </category> - - <category name="org.eclipse.swtbot"> - <priority value="ALL" /> - </category> - - <root> - <priority value="INFO" /> - <appender-ref ref="consoleAppender" /> - <appender-ref ref="fileAppender" /> - </root> - -</log4j:configuration>
\ No newline at end of file diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/ContextMenuHelper.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/ContextMenuHelper.java deleted file mode 100644 index 643445c1c0..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/ContextMenuHelper.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * 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: - * Stefan Seelmann - initial implementation posted to - * http://www.eclipse.org/forums/index.php?t=msg&th=11863&start=2 - *******************************************************************************/ -package org.eclipse.linuxtools.changelog.tests.helpers; - -import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withMnemonic; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.instanceOf; - -import java.util.Arrays; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.SWTException; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; -import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; -import org.eclipse.swtbot.swt.finder.results.VoidResult; -import org.eclipse.swtbot.swt.finder.results.WidgetResult; -import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot; -import org.hamcrest.Matcher; - -public class ContextMenuHelper { - - /** - * Clicks the context menu matching the text. - * - * @param bot - * - * @param texts - * the text on the context menu. - * @throws WidgetNotFoundException - * if the widget is not found. - * @throws SWTException - * if the menu item is disabled (the root cause being an - * {@link IllegalStateException}) - */ - public static void clickContextMenu(final AbstractSWTBot<?> bot, - final String... texts) { - - // show - final MenuItem menuItem = UIThreadRunnable - .syncExec(new WidgetResult<MenuItem>() { - public MenuItem run() { - MenuItem theItem = getMenuItem(bot, texts); - if (theItem != null && !theItem.isEnabled()) - throw new IllegalStateException( - "Menu item is diabled"); - - return theItem; - } - }); - if (menuItem == null) { - throw new WidgetNotFoundException("Could not find menu: " - + Arrays.asList(texts)); - } - - // click - click(menuItem); - - // hide - UIThreadRunnable.syncExec(new VoidResult() { - public void run() { - if (menuItem.isDisposed()) - return; // menu already gone - hide(menuItem.getParent()); - } - }); - } - - @SuppressWarnings("unchecked") - private static MenuItem getMenuItem(final AbstractSWTBot<?> bot, - final String... texts) { - MenuItem theItem = null; - Control control = (Control) bot.widget; - // for dynamic menus, we need to issue this event - control.notifyListeners(SWT.MenuDetect, new Event()); - Menu menu = control.getMenu(); - for (String text : texts) { - Matcher<?> matcher = allOf(instanceOf(MenuItem.class), - withMnemonic(text)); - theItem = show(menu, matcher); - if (theItem != null) { - menu = theItem.getMenu(); - } else { - hide(menu); - break; - } - } - return theItem; - } - - /** - * Checks if the context menu matching the text is enabled - * - * @param bot - * - * @param texts - * the text on the context menu. - * @return true if the context menu is enabled - * @throws WidgetNotFoundException - * if the widget is not found. - */ - public static boolean isContextMenuItemEnabled(final AbstractSWTBot<?> bot, - final String... texts) { - - final AtomicBoolean enabled = new AtomicBoolean(false); - // show - final MenuItem menuItem = UIThreadRunnable - .syncExec(new WidgetResult<MenuItem>() { - public MenuItem run() { - MenuItem theItem = getMenuItem(bot, texts); - if (theItem != null && theItem.isEnabled()) - enabled.set(true); - return theItem; - } - }); - if (menuItem == null) { - throw new WidgetNotFoundException("Could not find menu: " - + Arrays.asList(texts)); - } - // hide - UIThreadRunnable.syncExec(new VoidResult() { - public void run() { - if (menuItem.isDisposed()) - return; // menu already gone - hide(menuItem.getParent()); - } - }); - return enabled.get(); - } - - private static MenuItem show(final Menu menu, final Matcher<?> matcher) { - if (menu != null) { - menu.notifyListeners(SWT.Show, new Event()); - MenuItem[] items = menu.getItems(); - for (final MenuItem menuItem : items) { - if (matcher.matches(menuItem)) { - return menuItem; - } - } - menu.notifyListeners(SWT.Hide, new Event()); - } - return null; - } - - private static void click(final MenuItem menuItem) { - final Event event = new Event(); - event.time = (int) System.currentTimeMillis(); - event.widget = menuItem; - event.display = menuItem.getDisplay(); - event.type = SWT.Selection; - - UIThreadRunnable.asyncExec(menuItem.getDisplay(), new VoidResult() { - public void run() { - menuItem.notifyListeners(SWT.Selection, event); - } - }); - } - - private static void hide(final Menu menu) { - menu.notifyListeners(SWT.Hide, new Event()); - if (menu.getParentMenu() != null) { - hide(menu.getParentMenu()); - } - } -} diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/ProjectExplorer.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/ProjectExplorer.java deleted file mode 100644 index 800c77a4a1..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/ProjectExplorer.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers; - -import java.util.StringTokenizer; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; - -/** - * Project Explorer abstraction for SWTBot tests. - * - */ -public class ProjectExplorer { - - private static SWTWorkbenchBot bot = new SWTWorkbenchBot(); - - /** - * Opens the Project Explorer view. - */ - public static void openView() throws Exception { - bot.menu("Window").menu("Show View").menu("Project Explorer").click(); - } - - /** - * Assumes Project Explorer view is shown. - * - * @return The tree of the Project Explorer view - */ - public static SWTBotTree getTree() { - SWTBotView projectExplorer = bot.viewByTitle("Project Explorer"); - projectExplorer.show(); - Composite projectExplorerComposite = (Composite) projectExplorer.getWidget(); - Tree swtTree = (Tree) bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), projectExplorerComposite); - return new SWTBotTree(swtTree); - } - - /** - * @param projectItem The tree item corresponding to the project. - * @param name - * name of an item - * @return the project item pertaining to the project - */ - public static SWTBotTreeItem getProjectItem(SWTBotTreeItem projectItem, - String file) { - for (SWTBotTreeItem item : projectItem.getItems()) { - String itemText = item.getText(); - if (itemText.contains(file)) { - if (itemText.contains(" ")) { - StringTokenizer tok = new StringTokenizer(itemText, " "); - String name = tok.nextToken(); - if (file.equals(name)) - return item; - } else if (itemText.equals(file)) { - return item; - } - } - } - return null; - } - - /** - * Expand the given project (optionally stripping off the team provider bits) - * - * @param projectName - * @param teamProviderString - * @return - */ - public static SWTBotTreeItem expandProject(SWTBotTree projectExplorerTree, String projectName, String teamProviderString) { - String itemName; - for (SWTBotTreeItem item: projectExplorerTree.getAllItems()) { - itemName = item.getText(); - if (itemName.contains(projectName)) { // may also contain repo info - if (itemName.contains(teamProviderString)) { - return projectExplorerTree.expandNode(projectName + " " - + teamProviderString); - } else { - return projectExplorerTree.expandNode(projectName); - } - } - } - // nothing appropriate found - return null; - } -} diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/ProjectExplorerTreeItemAppearsCondition.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/ProjectExplorerTreeItemAppearsCondition.java deleted file mode 100644 index 0eafbe601c..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/ProjectExplorerTreeItemAppearsCondition.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers; - -import org.eclipse.swtbot.swt.finder.SWTBot; -import org.eclipse.swtbot.swt.finder.waits.ICondition; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; - -/** - * Condition to wait until a certain item appears in the - * Project Explorer tree. - * - */ -public class ProjectExplorerTreeItemAppearsCondition implements ICondition { - - private SWTBotTreeItem treeItem; - private String itemName; - private String parent; - private String teamDirt; - private SWTBotTree projectExplorerTree; - - public ProjectExplorerTreeItemAppearsCondition(SWTBotTree projectExplorerTree, String parent, String teamDirt, String treeItemName) { - this.itemName = treeItemName; - this.parent = parent; - this.teamDirt = teamDirt; - this.projectExplorerTree = projectExplorerTree; - } - - @Override - public boolean test() throws Exception { - treeItem = ProjectExplorer.expandProject(projectExplorerTree, parent, teamDirt); - for (SWTBotTreeItem i : treeItem.getItems()) { - if (i.getText().contains(itemName)) { - return true; - } - } - return false; - } - - @Override - public void init(SWTBot bot) { - // no initialization - } - - @Override - public String getFailureMessage() { - return null; - } - -} diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/SVNProject.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/SVNProject.java deleted file mode 100644 index fce9c37827..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/SVNProject.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers; - -import static org.junit.Assert.assertNotNull; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; -import org.eclipse.linuxtools.changelog.ui.tests.swtbot.PrepareChangelogSWTBotTest; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.waits.Conditions; -import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; - -/** - * Subversion project abstraction for SWTBot tests. See - * {@link PrepareChangelogSWTBotTest#setUp()} for a usage example. - * - */ -public class SVNProject { - - private SWTWorkbenchBot bot; - private String repoURL; - private String projectName; - private IProject project; // available after checkout - - public SVNProject(SWTWorkbenchBot bot) { - this.bot = bot; - } - - /** - * @return the repoURL - */ - public String getRepoURL() { - return repoURL; - } - - /** - * @param repoURL the repoURL to set - */ - public SVNProject setRepoURL(String repoURL) { - this.repoURL = repoURL; - return this; - } - - /** - * @return the projectName - */ - public String getProjectName() { - return projectName; - } - - /** - * @param projectName the projectName to set - */ - public SVNProject setProjectName(String projectName) { - this.projectName = projectName; - return this; - } - - /** - * @return the project - */ - public IProject getProject() { - return project; - } - - /** - * @param project the project to set - */ - public SVNProject setProject(IProject project) { - this.project = project; - return this; - } - - /** - * Use File => Import => SVN to create a svn-backed project. - */ - public IProject checkoutProject() throws IllegalStateException { - if (repoURL == null || projectName == null) { - // need to have url and project set - throw new IllegalStateException(); - } - bot.menu("File").menu("Import...").click(); - - SWTBotShell shell = bot.shell("Import"); - shell.activate(); - bot.tree().expandNode("SVN").select("Checkout Projects from SVN"); - bot.button("Next >").click(); - - // create new repo - shell = bot.shell("Checkout from SVN"); - shell.activate(); - bot.button("Next >").click(); - - shell = bot.shell("Checkout from SVN"); - shell.activate(); - // Enter url - bot.comboBoxWithLabelInGroup("Url:", "Location").setText(repoURL); - bot.button("Next >").click(); - - // the next few operation can take quite a while, adjust - // timout accordingly. - long oldTimeout = SWTBotPreferences.TIMEOUT; - SWTBotPreferences.TIMEOUT = 3 * 5000; - - bot.waitUntil(Conditions.shellIsActive("Progress Information")); - shell = bot.shell("Progress Information"); - bot.waitUntil(Conditions.shellCloses(shell)); - bot.waitUntil(Conditions.shellIsActive("Checkout from SVN")); - shell = bot.shell("Checkout from SVN"); - bot.waitUntil(new TreeItemAppearsCondition(repoURL, projectName)); - SWTBotTreeItem projectTree = bot.tree().expandNode(repoURL); - projectTree.expandNode(projectName).select(); - bot.button("Finish").click(); - // Wait for import operation to finish - bot.waitUntil(Conditions.shellCloses(shell)); - bot.waitUntil(Conditions.shellIsActive("SVN Checkout")); - SWTBotShell svnCheckoutPopup = bot.shell("SVN Checkout"); - bot.waitUntil(Conditions.shellCloses(svnCheckoutPopup)); - // need a little delay - bot.waitUntil(new SVNProjectCreatedCondition(projectName)); - - // Set timout back what it was. - SWTBotPreferences.TIMEOUT = oldTimeout; - - // A quick sanity check - IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); - IProject changelogTestsProject = (IProject)wsRoot.findMember(new Path(projectName)); - assertNotNull(changelogTestsProject); - try { - changelogTestsProject.refreshLocal(IResource.DEPTH_INFINITE, null); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - IResource manifest = changelogTestsProject.findMember(new Path("/META-INF/MANIFEST.MF")); - assertNotNull(manifest); - return changelogTestsProject; - } - - /** - * Discard the automatically created SVN repo URL from the list. - */ - public void discardRepositoryLocation() throws Exception { - if (repoURL == null) { // need to have repoURL set - throw new IllegalStateException(); - } - new SVNReporsitoriesView(bot).open().discardRepository(repoURL); - } -} diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/SVNProjectCreatedCondition.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/SVNProjectCreatedCondition.java deleted file mode 100644 index a28a1d635d..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/SVNProjectCreatedCondition.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.swtbot.swt.finder.SWTBot; -import org.eclipse.swtbot.swt.finder.waits.ICondition; - -/** - * Condition returns true if and only if a project with - * name <code>projectName</code> exists in the current - * workspace. - * - */ -public class SVNProjectCreatedCondition implements ICondition { - - private String projectName; - - public SVNProjectCreatedCondition(String projectName) { - this.projectName = projectName; - } - - @Override - public boolean test() throws Exception { - IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); - IProject project = (IProject)wsRoot.findMember(new Path(projectName)); - if (project == null) - return false; - else - return true; - } - - @Override - public void init(SWTBot bot) { - // no initialization; don't need bot - } - - @Override - public String getFailureMessage() { - return null; - } - -} diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/SVNReporsitoriesView.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/SVNReporsitoriesView.java deleted file mode 100644 index 226ed7ce7f..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/SVNReporsitoriesView.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers; - -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; - -/** - * SWTBot abstraction for the SVNRepositoriesView. - */ -public class SVNReporsitoriesView { - - private SWTWorkbenchBot bot; - - public SVNReporsitoriesView(SWTWorkbenchBot bot) { - this.bot = bot; - } - - /** - * Open the SVNRepositoriesView - */ - public SVNReporsitoriesView open() { - bot.menu("Window").menu("Show View").menu("Other...").click(); - SWTBotShell shell = bot.shell("Show View"); - shell.activate(); - bot.tree().expandNode("SVN").select("SVN Repositories"); - bot.button("OK").click(); - return this; - } - - /** - * Select repository - */ - public void discardRepository(String repo) throws Exception { - SWTBotView svnRepoView = bot.viewByTitle("SVN Repositories"); - svnRepoView.show(); - svnRepoView.setFocus(); - SWTBotTree tree = svnRepoView.bot().tree(); - tree.select(repo); - clickOnDiscardRepo(tree); // discard - } - - /** - * Context menu click helper. Click on "Add to existing sources". - * - * @param Tree of Package Explorer view. - * @throws Exception - */ - private void clickOnDiscardRepo(SWTBotTree svnReposTree) throws Exception { - String menuItem = "Discard location"; - ContextMenuHelper.clickContextMenu(svnReposTree, menuItem); - } -} diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/TableAppearsCondition.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/TableAppearsCondition.java deleted file mode 100644 index a5fa6124d1..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/TableAppearsCondition.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers; - -import org.eclipse.swtbot.swt.finder.SWTBot; -import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; -import org.eclipse.swtbot.swt.finder.waits.ICondition; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; - -/** - * Condition for an appearing table (SWTBot tests). - * - */ -public class TableAppearsCondition implements ICondition { - - private SWTBot bot; - - @Override - public boolean test() throws Exception { - try { - SWTBotTable table = bot.table(); - // table available - // make sure rowcount > 0 - if (table.rowCount() > 0) { - return true; - } - } catch (WidgetNotFoundException e) { - // ignore - } - return false; - } - - @Override - public void init(SWTBot bot) { - this.bot = bot; - } - - @Override - public String getFailureMessage() { - return null; - } - -} diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/TreeItemAppearsCondition.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/TreeItemAppearsCondition.java deleted file mode 100644 index 7301e70410..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/tests/helpers/TreeItemAppearsCondition.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers; - -import org.eclipse.swtbot.swt.finder.SWTBot; -import org.eclipse.swtbot.swt.finder.waits.ICondition; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; - -/** - * Expands the <code>parent</code> node, and returns true if - * and only if tree items of the expanded parent node contains - * the item given by <code>treeItemName</code>. - * - */ -public class TreeItemAppearsCondition implements ICondition { - - private SWTBot bot; - private SWTBotTreeItem treeItem; - private String itemName; - private String parent; - - public TreeItemAppearsCondition(String parent, String treeItemName) { - this.itemName = treeItemName; - this.parent = parent; - } - - @Override - public boolean test() throws Exception { - for (SWTBotTreeItem i : treeItem.getItems()) { - if (i.getText().contains(itemName)) { - return true; - } - } - return false; - } - - @Override - public void init(SWTBot bot) { - this.bot = bot; - treeItem = this.bot.tree().expandNode(parent); - } - - @Override - public String getFailureMessage() { - return null; - } - -} diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AddChangelogEntrySWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AddChangelogEntrySWTBotTest.java deleted file mode 100644 index e713b6d7a5..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AddChangelogEntrySWTBotTest.java +++ /dev/null @@ -1,275 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers.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.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AllSWTBotTests.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AllSWTBotTests.java deleted file mode 100644 index 49e60230ae..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/AllSWTBotTests.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * 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.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/CreateChangeLogFromHistorySWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/CreateChangeLogFromHistorySWTBotTest.java deleted file mode 100644 index d09c761e90..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/CreateChangeLogFromHistorySWTBotTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers.ContextMenuHelper; -import org.eclipse.linuxtools.changelog.tests.helpers.ProjectExplorerTreeItemAppearsCondition; -import org.eclipse.linuxtools.changelog.tests.helpers.ProjectExplorer; -import org.eclipse.linuxtools.changelog.tests.helpers.SVNProject; -import org.eclipse.linuxtools.changelog.tests.helpers.SVNProjectCreatedCondition; -import org.eclipse.linuxtools.changelog.tests.helpers.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.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/DisabledPrepareChangelogSWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/DisabledPrepareChangelogSWTBotTest.java deleted file mode 100644 index fd35130d92..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/DisabledPrepareChangelogSWTBotTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers.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.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/FormatChangeLogSWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/FormatChangeLogSWTBotTest.java deleted file mode 100644 index e5f8873138..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/FormatChangeLogSWTBotTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * 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.assertTrue; - - -import org.eclipse.core.resources.IProject; -import org.eclipse.jface.bindings.keys.KeyStroke; -import org.eclipse.linuxtools.changelog.tests.helpers.ProjectExplorerTreeItemAppearsCondition; -import org.eclipse.linuxtools.changelog.tests.helpers.ProjectExplorer; -import org.eclipse.linuxtools.changelog.tests.helpers.SVNProject; -import org.eclipse.linuxtools.changelog.tests.helpers.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 formatting ChangeLog files. - * - */ -@RunWith(SWTBotJunit4ClassRunner.class) -public class FormatChangeLogSWTBotTest { - - 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 - } - } - - /** - * Simple test for ChangeLog formatting. - * - * @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.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); - String threeLines = swtBotEclipseEditor.getSelection(); - assertEquals("\n\n\n", threeLines); - - // 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); - assertEquals("", secondLine); - assertTrue(!"".equals(thirdLine)); - } - -} diff --git a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/PrepareChangelogSWTBotTest.java b/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/PrepareChangelogSWTBotTest.java deleted file mode 100644 index 899796cd46..0000000000 --- a/changelog/org.eclipse.linuxtools.changelog.tests/src/org/eclipse/linuxtools/changelog/ui/tests/swtbot/PrepareChangelogSWTBotTest.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * 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.tests.helpers.ProjectExplorer; -import org.eclipse.linuxtools.changelog.tests.helpers.ProjectExplorerTreeItemAppearsCondition; -import org.eclipse.linuxtools.changelog.tests.helpers.SVNProject; -import org.eclipse.linuxtools.changelog.tests.helpers.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 - } - -} |