From: n.hoffmann Date: Fri, 1 Apr 2011 13:17:16 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rcp.ss-first-working-version~137 X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/commitdiff_plain/28b8707ab9ba25261dffabec24b6f63e19a176ec --- diff --git a/.gitattributes b/.gitattributes index 822309330..11acf97db 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1192,6 +1192,17 @@ eu.etaxonomy.taxeditor.store/src/test/resources/eu/etaxonomy/taxeditor/store/Cdm eu.etaxonomy.taxeditor.store/src/test/resources/eu/etaxonomy/taxeditor/store/ConcurrentSessionTest.xml -text eu.etaxonomy.taxeditor.store/src/test/resources/log4j.properties -text eu.etaxonomy.taxeditor.store/src/test/resources/unitils.properties -text +eu.etaxonomy.taxeditor.test/.classpath -text +eu.etaxonomy.taxeditor.test/.project -text +eu.etaxonomy.taxeditor.test/.settings/org.eclipse.jdt.core.prefs -text +eu.etaxonomy.taxeditor.test/META-INF/MANIFEST.MF -text +eu.etaxonomy.taxeditor.test/build.properties -text +eu.etaxonomy.taxeditor.test/ide/eclipse/EDITor[!!-~]Tests.launch -text +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/AbstractEditorTest.java -text +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/ClassificationTest.java -text +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/ContextMenuHelper.java -text +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/LoginTest.java -text +eu.etaxonomy.taxeditor.test/src/test/java/log4j.xml -text /pom.xml -text src/changes/changes.xml -text src/site/apt/download.apt -text diff --git a/eu.etaxonomy.taxeditor.test/.classpath b/eu.etaxonomy.taxeditor.test/.classpath new file mode 100644 index 000000000..0d3204205 --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/eu.etaxonomy.taxeditor.test/.project b/eu.etaxonomy.taxeditor.test/.project new file mode 100644 index 000000000..ef718ade6 --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/.project @@ -0,0 +1,28 @@ + + + eu.etaxonomy.taxeditor.test + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/eu.etaxonomy.taxeditor.test/.settings/org.eclipse.jdt.core.prefs b/eu.etaxonomy.taxeditor.test/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..b61e872f7 --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Thu Mar 31 16:21:36 CEST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/eu.etaxonomy.taxeditor.test/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.test/META-INF/MANIFEST.MF new file mode 100644 index 000000000..da9867a5e --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: eu.etaxonomy.taxeditor.test +Bundle-SymbolicName: eu.etaxonomy.taxeditor.test;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-ActivationPolicy: lazy +Bundle-Vendor: EDIT +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.apache.log4j;bundle-version="1.2.13", + org.eclipse.core.runtime;bundle-version="3.6.0", + org.eclipse.swt;bundle-version="3.6.2", + org.eclipse.swtbot.eclipse.core;bundle-version="2.0.4", + org.eclipse.swtbot.eclipse.finder;bundle-version="2.0.4", + org.eclipse.swtbot.junit4_x;bundle-version="2.0.4", + org.junit;bundle-version="4.8.1", + org.eclipse.ui.ide;bundle-version="3.6.2", + org.hamcrest;bundle-version="1.1.0" diff --git a/eu.etaxonomy.taxeditor.test/build.properties b/eu.etaxonomy.taxeditor.test/build.properties new file mode 100644 index 000000000..dbd5f74b8 --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/build.properties @@ -0,0 +1,4 @@ +source.. = src_/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/eu.etaxonomy.taxeditor.test/ide/eclipse/EDITor Tests.launch b/eu.etaxonomy.taxeditor.test/ide/eclipse/EDITor Tests.launch new file mode 100644 index 000000000..b1625329f --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/ide/eclipse/EDITor Tests.launch @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/AbstractEditorTest.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/AbstractEditorTest.java new file mode 100644 index 000000000..ff28acb41 --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/AbstractEditorTest.java @@ -0,0 +1,65 @@ +/** + * + */ +package eu.etaxonomy.taxeditor.test; + +import java.util.List; + +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory; +import org.eclipse.swtbot.eclipse.finder.waits.Conditions; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.finders.ChildrenControlFinder; +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.junit.Before; +import org.junit.runner.RunWith; + +/** + * @author n.hoffmann + * + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public abstract class AbstractEditorTest { + + protected SWTWorkbenchBot bot; + + @Before + public void setup() { + bot = new SWTWorkbenchBot(); + SWTBotPreferences.TIMEOUT = 300000; + + String activeText = bot.activeShell().getText(); + if(activeText.equals("Connecting to datasource: cdm")){ + bot.waitUntil(Conditions.shellIsActive("Login")); + bot.button("Cancel").click(); + } + } + + + /** + * @return + * @throws WidgetNotFoundException + */ + public SWTBotTree tree(Widget widget) throws WidgetNotFoundException { + List controls = new ChildrenControlFinder(widget).findControls(WidgetMatcherFactory.widgetOfType(Tree.class)); + if (controls.isEmpty()) + throw new WidgetNotFoundException("Could not find any tree"); + SWTBotTree tree = new SWTBotTree((Tree) controls.get(0)); + return tree; + } + + /** + * @return + * @throws WidgetNotFoundException + */ + public SWTBotView view(String title) throws WidgetNotFoundException { + return bot.viewByTitle(title); + } + + +} diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/ClassificationTest.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/ClassificationTest.java new file mode 100644 index 000000000..3d826618e --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/ClassificationTest.java @@ -0,0 +1,29 @@ +/** + * + */ +package eu.etaxonomy.taxeditor.test; + +import org.eclipse.swtbot.eclipse.finder.waits.Conditions; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; +import org.junit.Test; + +/** + * @author n.hoffmann + * + */ +public class ClassificationTest extends AbstractEditorTest { + + @Test + public void canDeleteClassification() throws Exception { + SWTBotView navigatorView = view("Taxon Navigator"); + SWTBotTree tree = tree(navigatorView.getWidget()); + tree.select(0); + + +// SWTBotTreeItem treeItem = tree.getTreeItem("TestFolder 01").select(); + ContextMenuHelper.clickContextMenu(tree, "Delete"); + bot.waitUntil(Conditions.shellIsActive("Confirm Deletion")); + bot.button("OK").click(); + } +} diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/ContextMenuHelper.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/ContextMenuHelper.java new file mode 100644 index 000000000..37371d05c --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/ContextMenuHelper.java @@ -0,0 +1,106 @@ +package eu.etaxonomy.taxeditor.test; + +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 org.eclipse.swt.SWT; +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 text + * the text on the context menu. + * @throws WidgetNotFoundException + * if the widget is not found. + */ + public static void clickContextMenu(final AbstractSWTBot bot, + final String... texts) { + + // show + final MenuItem menuItem = UIThreadRunnable + .syncExec(new WidgetResult() { + public MenuItem run() { + MenuItem menuItem = null; + Control control = (Control) bot.widget; + Menu menu = control.getMenu(); + for (String text : texts) { + Matcher matcher = allOf(instanceOf(MenuItem.class), + withMnemonic(text)); + menuItem = show(menu, matcher); + if (menuItem != null) { + menu = menuItem.getMenu(); + } else { + hide(menu); + break; + } + } + + return menuItem; + } + }); + if (menuItem == null) { + throw new WidgetNotFoundException("Could not find menu: " + + Arrays.asList(texts)); + } + + // click + click(menuItem); + + // hide + UIThreadRunnable.syncExec(new VoidResult() { + public void run() { + hide(menuItem.getParent()); + } + }); + } + + 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/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/LoginTest.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/LoginTest.java new file mode 100644 index 000000000..e9ac066fa --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/LoginTest.java @@ -0,0 +1,18 @@ +package eu.etaxonomy.taxeditor.test; + +import org.eclipse.swtbot.eclipse.finder.waits.Conditions; +import org.junit.Test; + + +public class LoginTest extends AbstractEditorTest{ + + @Test + public void canLoginAsAdmin() throws Exception { + bot.menu("General").menu("Login").click(); + bot.waitUntil(Conditions.shellIsActive("Login")); + bot.textWithLabel("Username").setText("admin"); + bot.textWithLabel("Password").setText("0000"); + bot.button("Cancel").click(); + } + +} diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/log4j.xml b/eu.etaxonomy.taxeditor.test/src/test/java/log4j.xml new file mode 100644 index 000000000..ea16d1383 --- /dev/null +++ b/eu.etaxonomy.taxeditor.test/src/test/java/log4j.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file