Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse')
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/AbstractUITest.java261
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/ActiveSWTTestSuite.java455
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/IAbbotTestUiStarter.java24
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/PDETestFixture.java93
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/TimeoutExceededException.java36
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/WaitingFinder.java91
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/EnhancedTextMatcher.java112
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/SiblingTextMatcher.java146
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/ToolItemMatcher.java61
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/PDEUtil.java111
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/TimerUtils.java114
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/internal/UICleanupManager.java184
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/Builder.java26
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/ConflictBuilder.java28
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DescriptiveObjectBuilder.java34
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestProviderDescriptionBuilder.java35
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestinationCategoryDescriptionBuilder.java37
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestinationsProviderBuilder.java32
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/ObjectTypeDescriptionBuilder.java22
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchDestinationBuilder.java28
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchProviderBuilder.java43
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchProviderDescriptionBuilder.java52
-rw-r--r--tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SubdestinationBuilder.java54
23 files changed, 368 insertions, 1711 deletions
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/AbstractUITest.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/AbstractUITest.java
deleted file mode 100644
index bd39de8..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/AbstractUITest.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot;
-
-import org.eclipse.platform.discovery.testutils.utils.abbot.util.PDEUtil;
-import org.eclipse.platform.discovery.testutils.utils.junit.util.assertions.Assertions;
-import org.eclipse.platform.discovery.testutils.utils.junit.util.assertions.ConditionCheckException;
-import org.eclipse.platform.discovery.testutils.utils.junit.util.assertions.IWaitCondition;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.PlatformUI;
-
-import abbot.swt.finder.WidgetFinder;
-import abbot.swt.finder.WidgetFinderImpl;
-import abbot.swt.finder.WidgetHierarchy;
-import abbot.swt.finder.WidgetHierarchyImpl;
-import abbot.swt.finder.generic.HierarchyPrinter;
-import abbot.swt.tester.ButtonTester;
-import abbot.swt.tester.LabelTester;
-import abbot.swt.tester.MenuItemTester;
-import abbot.swt.tester.MenuTester;
-import abbot.swt.tester.ShellTester;
-import abbot.swt.tester.TableItemTester;
-import abbot.swt.tester.TextTester;
-import abbot.swt.tester.TreeItemTester;
-import abbot.swt.tester.WidgetTester;
-import abbot.swt.utilities.WidgetHierarchyPrinter;
-
-public abstract class AbstractUITest extends PDETestFixture {
-
- /** widget tester with specific button functionality */
- protected static final ButtonTester BUTTON_T = ButtonTester.getButtonTester();
-
- /** widget tester with specific label functionality */
- protected static final LabelTester LABEL_T = LabelTester.getLabelTester();
-
- /** widget tester with specific menu functionality */
- protected static final MenuTester MENU_T = MenuTester.getMenuTester();
-
- /** widget tester with specific shell functionality */
- protected static final ShellTester SHELL_T = ShellTester.getShellTester();
-
- /** widget tester with specific text functionality */
- protected static final TextTester TEXT_T = TextTester.getTextTester();
-
- /** widget tester with specific table item functionality */
- protected static final TableItemTester TABLE_ITEM_T = TableItemTester.getTableItemTester();
-
- /** widget tester with specific tree item functionality */
- protected static final TreeItemTester TREE_ITEM_T = TreeItemTester.getTreeItemTester();
-
- /** widget tester with specific menu item functionality */
- protected static final MenuItemTester MENU_ITEM_T = MenuItemTester.getMenuItemTester();
-
- protected static final WidgetTester TESTER = new WidgetTester(abbot.swt.Robot.getDefault());
-
- protected static final WidgetFinder FINDER = new WaitingFinder(WidgetFinderImpl.getDefault());
-
- /**
- * SWT Widget finder. The {@link AbbotUtil#FINDER} finder is an instance of {@link WaitingFinder} which makes several find
- * tries with a timeout between them. This is not convenient for tests that check whether a widget is NOT displayed because
- * test execution time increases a lot.
- */
- public static final WidgetFinder QUICK_FINDER = WidgetFinderImpl.getDefault();
-
- private static Display display;
-
- /** The code to be executed by the setUp method.
- * @see junit.extensions.PDETestFixture#setUpPDE() */
- @Override
- public Display setUpPDE() throws Exception {
- PDEUtil.prepareWorkbench();
-
- display = PlatformUI.getWorkbench().getDisplay();
-
- return display;
- }
-
- /** Deferes test execution for a certain time
- * @param delay time in milliseconds */
- protected void waitFor(int delay) {
- TESTER.actionDelay(delay);
- }
-
- /** Wait for a shell to be displayed.
- * @param title regexp for the window title */
- protected Shell waitForShell(String title) {
- return ShellTester.waitVisible(title);
- }
-
- /** The code to be executed by the tearDown method.
- * @see junit.extensions.PDETestFixture#tearDownPDE() */
- @Override
- protected void tearDownPDE() throws Exception {
- if(getUiStarter() != null)
- {
- getUiStarter().closeEnclosingDialog(display);
- }
-
- display = null;
- super.tearDownPDE();
- }
-
- /** Prints out the whole widget tree. Useful if problems arise to find a specific widget. */
- protected void printWidgets()
- {
- final WidgetHierarchy hierarchy = new WidgetHierarchyImpl(display);
- final HierarchyPrinter<?> printer = new WidgetHierarchyPrinter(hierarchy, System.out);
- display.syncExec(new Runnable()
- {
- public void run()
- {
- printer.print();
- }
- });
- }
-
- /** Checks if the given control is enabled or not.
- * @param control control to be checked
- * @return true if enabled, otherwise false */
- protected boolean isEnabled(final Control control)
- {
- assert control != null;
- final boolean[] enabled = new boolean[1];
- display.syncExec(new Runnable()
- {
- public void run()
- {
- enabled[0] = control.isEnabled();
- }
- });
- return enabled[0];
- }
-
- /**
- * Checks whether the radio button specified is selected
- * @param button the button to be checked
- * @return true in case the button is a check button and is selected, otherwise false
- */
- protected boolean isSelected(final Button button)
- {
- assert button != null;
- final boolean[] selected = new boolean[1];
- display.syncExec(new Runnable()
- {
- public void run()
- {
- if((button.getStyle() | SWT.RADIO) != 0)
- {
- selected[0] = button.getSelection();
- }
- }
- });
- return selected[0];
- }
-
- /**
- * Checks whether the text control specified is editable
- *
- * @param text
- * @return
- */
- protected boolean isEditable(final Text text)
- {
- assert text != null;
- final boolean[] editable = new boolean[1];
- display.syncExec(new Runnable()
- {
- public void run()
- {
- editable[0] = (text.getStyle() & SWT.READ_ONLY) == 0;
- }
- });
- return editable[0];
- }
-
-
- /**
- * Workaround for changing table item checkbox state. It seems that abbot does not behave correctly
- * for table item selection and pressing ' '
- * @param ti
- */
- protected void changeTableItemCheckState(TableItem ti)
- {
- TESTER.actionClick(ti, -5, 1);
- // On some machines sometimes it happens that the item is not checked/unchecked immediately and some time is required
- waitFor(1000);
- }
-
- /**
- * Extenders may implement this method in order the dialog control that contains the UI tested to be closed on tearDown
- * In case this is not required, <code>null</code> should be returned
- * @return
- */
- protected IAbbotTestUiStarter getUiStarter()
- {
- return null;
- }
-
- /**
- * Expands the tree item specified. If the tree item is expanded, the method simply returns
- * @param ti tree item
- */
- protected void expandTreeItem(final TreeItem ti)
- {
- if(TREE_ITEM_T.getExpanded(ti))
- {
- return;
- }
-
- TREE_ITEM_T.actionClick(ti);
- TREE_ITEM_T.actionKey(SWT.ARROW_RIGHT);
- }
-
- /**
- * Opens the context menu for the tree item specified. The method will click on the item and will press the right mouse button
- * @param ti tree item
- */
- protected void openTreeItemContextMenu(final TreeItem ti)
- {
- TREE_ITEM_T.actionClick(ti);
- TREE_ITEM_T.actionClick(ti, 1, 1, "BUTTON3");
- }
-
- /**
- * Waits for the widget specified to get disposed
- * @param w the widget which disposal to wait for
- * @param failMessage message to fail with in case the widget does not get disposed after some time
- */
- protected void waitForWidgetDisposed(final Widget w, final String failMessage)
- {
- Assertions.waitAssert(new IWaitCondition()
- {
- @Override
- public boolean checkCondition() throws ConditionCheckException
- {
- return w.isDisposed();
- }
- }, failMessage);
- }
-
- protected Display getDisplay()
- {
- return display;
- }
-} \ No newline at end of file
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/ActiveSWTTestSuite.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/ActiveSWTTestSuite.java
deleted file mode 100644
index b0c109e..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/ActiveSWTTestSuite.java
+++ /dev/null
@@ -1,455 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot;
-
-import java.awt.AWTException;
-import java.awt.Robot;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-
-import org.eclipse.platform.discovery.testutils.internal.plugin.TestPlugin;
-import org.eclipse.platform.discovery.testutils.utils.abbot.util.TimerUtils;
-import org.eclipse.platform.discovery.testutils.utils.abbot.util.internal.UICleanupManager;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-
-/**
- * Suite for UI tests in SWT.
- * <p>
- * Forks the test execution out of the UI thread in order to avoid that a test
- * is blocked because of modal dialogs. The suite itself has to be started in
- * the UI thread. Consequently one cannot nest <code>ActiveSWTTestSuite</code>s.
- * </p>
- * <p>
- * By default remaining dialogs will be closed by hitting escape a number of
- * times. You can change that behavior by calling
- * <code>setCloseShells(true)</code> in {@link #setUpPDE()} or earlier. As a
- * consequence all shells that were not present before the test run will be
- * closed by calling {@link Shell#close()}. This may however cause problems in
- * subsequent tests if a shell is meant to be reused (e.g. GEF holds a shell in
- * a static member).
- * </p>
- *
- * @author Richard Birenheide
- */
-public class ActiveSWTTestSuite extends TestSuite {
-
- private class RunTestSuiteTask extends TimerTask {
- private final TestResult result;
- private final ExecutorService service;
-
-
- public RunTestSuiteTask(TestResult result, ExecutorService service) {
- super();
- this.result = result;
- this.service = service;
- }
-
- @Override
- public void run() {
- this.result.addError(ActiveSWTTestSuite.this, new Throwable("Test execution terminated to avoid JDTD timeout"));
- try {
- ActiveSWTTestSuite.this.suiteTearDown();
- } catch (AssertionFailedError th) {
- this.result.addFailure(ActiveSWTTestSuite.this, th);
- } catch (Exception ex) {
- this.result.addError(ActiveSWTTestSuite.this, ex);
- }
- ActiveSWTTestSuite.this.testsFinished = true;
- ActiveSWTTestSuite.this.display.wake();
- service.shutdownNow();
- //System.exit(0);
- }
-
-
- }
-
- private final UICleanupManager cleanupManager = new UICleanupManager();
-
- // private final static long JDTD_TIME =
- // System.getProperty("testrun.activeTimeout")
- // == null ? 100000 :
- // Long.parseLong(System.getProperty("testrun.activeTimeout"));
-
- private volatile boolean testsFinished = false;
-
- /**
- * The display associated with this run.
- */
- protected Display display;
- /**
- * The shell being active when starting this run.
- */
- protected Shell rootShell;
-
- /**
- * Hold the number of tests in a test case that are already executed
- */
- protected int executedTestsCount;
-
- private TimerUtils timeController = TimerUtils.getInstance();
-
- // a little less, than 15 mins, defined by JDTD itself
- private final static long JDTD_TIMEOUT = 14 * 60 * 1000;
-
- public TimerUtils getTimeController() {
- return timeController;
- }
-
- public void setTimeController(TimerUtils timeController) {
- this.timeController = timeController;
- }
-
- /**
- * Default constructor.
- * <p/>
- * The name associated with this class is given the Class name.
- */
- public ActiveSWTTestSuite() {
- super(ActiveSWTTestSuite.class.getName());
- initJDTDExecutionTimeControlling();
- }
-
- /**
- * Constructs with a test class.
- * <p/>
- * The name associated with this class is given the Class name.
- *
- * @param theClass
- * a test class.
- */
- public ActiveSWTTestSuite(final Class<? extends TestCase> theClass) {
- super(theClass, ActiveSWTTestSuite.class.getName());
- initJDTDExecutionTimeControlling();
- }
-
- /**
- * Constructs with a name containing no test.
- * <p/>
- *
- * @param name
- * the name. This name will be given to the separate thread
- * running.
- */
- public ActiveSWTTestSuite(final String name) {
- super(name);
- initJDTDExecutionTimeControlling();
- }
-
- /**
- * Constructs with a name and containing the test class given.
- * <p/>
- *
- * @param theClass
- * a test class.
- * @param name
- * the name. This name will be given to the separate thread
- * running.
- */
- public ActiveSWTTestSuite(final Class<? extends TestCase> theClass, final String name) {
- super(theClass, name);
- initJDTDExecutionTimeControlling();
- }
-
- @Override
- public final void run(final TestResult result) {
- this.display = Display.getCurrent();
- if (this.display == null) {
- throw new IllegalStateException(
- "The TestSuite must be run from an SWT UI thread");
- }
- this.rootShell = display.getActiveShell();
- this.cleanupManager.registerUIState();
-
- final ExecutorService service = Executors.newSingleThreadScheduledExecutor();
- // handle JDTD timeout: stop the test before JDTD timeout is thrown
- Timer timeoutTimer = new Timer();
- TimerTask task = new RunTestSuiteTask(result, service);
- timeoutTimer.schedule(task, TimerUtils.getInstance().getRemainingTime());
- service.execute(new TestSuiteRunnerTask(result));
-
- waitUntilFinished();
-
- }
-
- private void initJDTDExecutionTimeControlling() {
- executedTestsCount = 0;
- if (this.timeController.getJDTD_TIME() == 0) {
- String jdtdProperty = System.getProperty("testrun.activeTimeout");
- this.timeController
- .setJDTD_TIME(jdtdProperty == null ? JDTD_TIMEOUT : Long
- .parseLong(jdtdProperty) * 1000);
- }
- System.out.println("******** Expected end of test run: "
- + this.timeController.formatNowTime(this.timeController
- .getJDTD_TIME()) + " ***********");
- this.timeController.setSTART_TIME(System.currentTimeMillis());
- }
-
- private boolean shouldSkipNextTestExecution() {
- long[] timeCheck = this.timeController.getRequiredTime(this
- .countTestCases(), this.executedTestsCount);
- return timeCheck[0] < timeCheck[1];
- }
-
- @Override
- public final void runTest(final Test test, final TestResult result) {
- try {
- // inlined due to limitation in VA/Java
- // ActiveSWTTestSuite.super.runTest(test, result);
- test.run(result);
- } finally {
- ActiveSWTTestSuite.this.runFinished();
- }
- }
-
- private void waitUntilFinished() {
- while (!this.testsFinished) {
- try {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- } catch (final SWTException ex) {
- TestPlugin
- .logError(
- "A SWTException ocurred during waiting for the tests being finished in thread: "
- + Thread.currentThread().getName(), ex);
- /*
- * Do nothing: rethrowing errors leads to premature end of the
- * WorkbenchTestable thread and the IDE subsequently not being
- * shut down.
- */
- } catch (final RuntimeException ex) {
- TestPlugin
- .logError(
- "A RuntimeException ocurred during waiting for the tests being finished in thread: "
- + Thread.currentThread().getName(), ex);
- }
- }
- }
-
- /**
- * Closes all shells when finished.
- */
- private void runFinished() {
-
- cleanupManager.cleanUp();
-
- }
-
- /**
- * Retrieves the display associated with this test run.
- * <p/>
- *
- * @return the display associated with this test run. Only valid after the
- * test has been started.
- */
- public Display getDisplay() {
- return this.display;
- }
-
- /**
- * Runs a set up prior to executing the entirety of the tests within this
- * suite.
- * <p>
- * The method will run called in the non-UI thread. The default
- * implementation does nothing.
- * </p>
- *
- * @throws Exception
- * convenience signature to ensure correct reporting on
- * Exceptions in set up.
- * {@link junit.framework.AssertionFailedError} is permissible
- * as well and will be reported accordingly as failure.
- */
- protected void suiteSetUp() throws Exception {
- }
-
- /**
- * Runs a tear down after executing all tests within this suite.
- * <p>
- * The method will run called in the non-UI thread. The default
- * implementation does nothing.
- * </p>
- *
- * @throws Exception
- * convenience signature to ensure correct reporting on
- * Exceptions in tear down.
- * {@link junit.framework.AssertionFailedError} is permissible
- * as well and will be reported accordingly as failure.
- */
- protected void suiteTearDown() throws Exception {
- }
-
- /**
- * Closes all shells and child shells of the given array recursively.
- * <p>
- * This is called after each TestCase to guarantee that no (blocking)
- * dialogs are still open. Does currently not work perfect and it is thus
- * highly recommended that this is done properly in TestCase.tearDown().
- *
- * @param shells
- * the shells to close.
- */
- public static void closeShells(final Shell[] shells) {
- for (int i = 0; i < shells.length; i++) {
- if (!shells[i].isDisposed()) {
- closeShells(shells[i].getShells());
- }
- if (!shells[i].isDisposed()) {
- shells[i].close();
- // shells[i].dispose();
- }
- }
- }
-
- /**
- * Convenience method for {@link Display#syncExec(java.lang.Runnable)}
- * catching {@link SWTException} and rethrowing {@link AssertionFailedError}
- * if appropriate.
- * <p>
- * Should be used from TestCase.testXXX() methods when asserting within the
- * SWT thread in order to guarantee that a test failure is displayed
- * correctly.
- *
- * @param display
- * the display to run the runnable in.
- * @param runnable
- * the Runnable to execute.
- * @throws AssertionFailedError
- * if an assertion failed in the display thread.
- * @throws RuntimeException
- * either a RuntimeException has been issued by the Runnable or
- * the Runnable has thrown a Throwable not being a
- * RuntimeException. In that case the RuntimeException carries
- * the original Exception as cause.
- */
- public static void syncExec(final Display display, final Runnable runnable) {
- try {
- display.syncExec(runnable);
- } catch (final SWTException swtEx) {
- if (swtEx.throwable instanceof AssertionFailedError) {
- throw (AssertionFailedError) swtEx.throwable;
- } else {
- throw swtEx;
- }
- }
- }
-
- /**
- * Convenience method for {@link Display#asyncExec(java.lang.Runnable)}
- * catching {@link SWTException} and rethrowing {@link AssertionFailedError}
- * if appropriate.
- * <p>
- * Should be used from TestCase.testXXX() methods when asserting within the
- * SWT thread in order to guarantee that a test failure is displayed
- * correctly.
- * <p/>
- * NOTE that exception handling with this method cannot be guaranteed to
- * work since exceptions are thrown asynchronously. Currently I have no idea
- * how to notify the caller of a test being failed. But generally I have no
- * idea why one should like to run _tests_ asynchronously. Possibly one
- * could introduce an ErrorListener here but I am not sure. Ideal would be
- * to have knowledge about the actual {@link Test} and {@link TestResult}
- * when this method is called. Then one could feed the result with
- * {@link TestResult#addError(junit.framework.Test, java.lang.Throwable)} or
- * {@link TestResult#addFailure(junit.framework.Test, junit.framework.AssertionFailedError)}
- * . Actually I do not know how to get the correct Test. Unfortunately it is
- * not the one issued by {@link #runTest(Test, TestResult)}.
- *
- * @param display
- * the display to run the runnable in.
- * @param runnable
- * the Runnable to execute.
- */
- public static void asyncExec(final Display display, final Runnable runnable) {
- try {
- display.asyncExec(runnable);
- } catch (final SWTException swtEx) {
- if (swtEx.throwable instanceof AssertionFailedError) {
- throw (AssertionFailedError) swtEx.throwable;
- } else {
- throw swtEx;
- }
- }
- }
-
- /**
- * Runs the test in the separate thread.
- * <p/>
- *
- * @author Richard Birenheide
- */
- private class TestSuiteRunnerTask implements Runnable {
-
- private final TestResult result;
-
- /**
- * Constructs with name and the TestResult given.
- * <p/>
- *
- * @param name
- * the threads name.
- * @param result
- * the test result.
- */
- private TestSuiteRunnerTask(final TestResult result) {
- this.result = result;
- // Prestart the AWT threads so that they will not be started in our
- // thread group
- try {
- final Robot r = new Robot();
- TestPlugin.logInfo("Robot created: " + r.toString());
- } catch (final AWTException ex) {
- TestPlugin.logError(ex);
- }
- }
-
- public void run() {
-
- // Safeguard the setting of the finish flag against errors.
- // Otherwise the Test may block infinitely.
- try {
- ActiveSWTTestSuite.this.suiteSetUp();
- if (!shouldSkipNextTestExecution()) {
- ActiveSWTTestSuite.super.run(this.result);
- } else {
- throw new TimeoutExceededException(
- "The remaining time is less than expected execution time");
- }
- } catch (final AssertionFailedError th) {
- this.result.addFailure(ActiveSWTTestSuite.this, th);
- } catch (final Exception ex) {
- this.result.addError(ActiveSWTTestSuite.this, ex);
- } finally {
- try {
- ActiveSWTTestSuite.this.suiteTearDown();
- } catch (final Exception ex) {
- this.result.addError(ActiveSWTTestSuite.this, ex);
- } catch (final AssertionFailedError th) {
- this.result.addFailure(ActiveSWTTestSuite.this, th);
- }
- ActiveSWTTestSuite.this.testsFinished = true;
- ActiveSWTTestSuite.this.display.wake();
- }
- }
- }
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/IAbbotTestUiStarter.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/IAbbotTestUiStarter.java
deleted file mode 100644
index 3c31199..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/IAbbotTestUiStarter.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot;
-
-import org.eclipse.swt.widgets.Display;
-
-public interface IAbbotTestUiStarter
-{
- /**
- * Closes the "host" dialog
- * @param display the display in which the action would be executed
- * @throws NullPointerException when display is null
- * @throws IllegalStateException when the host dialog has not been initialized
- */
- public void closeEnclosingDialog(Display display);
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/PDETestFixture.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/PDETestFixture.java
deleted file mode 100644
index 70e76cf..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/PDETestFixture.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot;
-
-import junit.framework.TestCase;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-
-import abbot.swt.Robot;
-
-
-/**
- * Provides a simple fixture for PDE testing.
- * <p/>
- * The fixture tries to close all open stuff on tearDown(). To enforce this,
- * {@link junit.framework.TestCase#tearDown()} and {@link junit.framework.TestCase#setUp()}
- * have been marked final and replaced by {@link #setUpPDE()} and {@link #tearDownPDE()}.
- * @author Richard Birenheide
- */
-public abstract class PDETestFixture extends TestCase {
- /**
- * The display as received by {@link #setUpPDE()}.
- */
- /*
- * Although this member is currently not used it might turn out that it is
- * needed for proper tearDown() later. In order to not break API later on
- * it is introduced now.
- */
- protected Display display = null;
- /**
- * Sets up the fixture.
- * <p/>
- * Is marked as final to enforce usage of {@link #setUpPDE()} instead.
- * Comment from overridden method:<br/>
- * {@inheritDoc}
- * @throws Exception {@inheritDoc}
- * @see junit.framework.TestCase#setUp()
- */
- protected final void setUp() throws Exception {
- this.display = this.setUpPDE();
- if (this.display == null) {
- throw new NullPointerException("Method PDETestFixture.setUpPDE() must not return null");
- }
- }
- /**
- * Tears down the fixture.
- * <p/>
- * Is marked as final to enforce usage of {@link #tearDownPDE()} instead.
- * The method tries to close any open blocking UI elements.
- * Comment from overridden method:<br/>
- * {@inheritDoc}
- * @throws Exception {@inheritDoc}
- * @see junit.framework.TestCase#tearDown()
- */
- protected final void tearDown() throws Exception {
- this.tearDownPDE();
- //This is in order to close cleanly any stuff (eg. menues, modal dialogues) which puts
- //the UI thread in blocking mode.
- //FIXME This is a crude workaround. Search for open stuff instead
- //and close these.
- Robot robot = new Robot(this.display);
- for (int i = 0; i < 25; i++) {
- robot.key(SWT.ESC);
- }
- }
- /**
- * Replaces the {@link TestCase#setUp()} method.
- * <p/>
- * Will be called as self call within setUp().
- * @return a Display to invoke calls on. Must be not null and should be the
- * primary display of the application.
- * @throws Exception any Exception indicating setUp() failure.
- */
- protected abstract Display setUpPDE() throws Exception;
- /**
- * Replaces the {@link TestCase#tearDown()} method.
- * <p/>
- * Will be called as first self call from tearDown().
- * @throws Exception any Exception indicating tearDown() failure.
- */
- protected void tearDownPDE() throws Exception {
-
- }
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/TimeoutExceededException.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/TimeoutExceededException.java
deleted file mode 100644
index 6e9acf8..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/TimeoutExceededException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot;
-
-public final class TimeoutExceededException extends Exception {
-
- public TimeoutExceededException() {
- super();
- }
-
- public TimeoutExceededException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public TimeoutExceededException(String message) {
- super(message);
- }
-
- public TimeoutExceededException(Throwable cause) {
- super(cause);
- }
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/WaitingFinder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/WaitingFinder.java
deleted file mode 100644
index fcd6e79..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/WaitingFinder.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot;
-
-import org.eclipse.platform.discovery.testutils.utils.junit.util.assertions.Assertions;
-import org.eclipse.platform.discovery.testutils.utils.junit.util.assertions.ConditionCheckException;
-import org.eclipse.platform.discovery.testutils.utils.junit.util.assertions.IWaitCondition;
-import org.eclipse.swt.widgets.Widget;
-
-import abbot.swt.finder.WidgetFinder;
-import abbot.swt.finder.generic.Matcher;
-import abbot.swt.finder.generic.MultipleFoundException;
-import abbot.swt.finder.generic.NotFoundException;
-
-
-/**
- * A finder implementation which would perform several attempts to find a widget prior failing
- *
- * @author Danail Branekov
- */
-public class WaitingFinder implements WidgetFinder
-{
- private final WidgetFinder delegate;
-
- public WaitingFinder(final WidgetFinder delegate)
- {
- this.delegate = delegate;
- }
-
- @Override
- public Widget find(final Matcher<Widget> matcher) throws NotFoundException, MultipleFoundException
- {
- final Widget[] result = new Widget[1];
- final IWaitCondition condition = new FindWaitCondition()
- {
- @Override
- protected void find() throws NotFoundException, MultipleFoundException
- {
- result[0] = delegate.find(matcher);
- }
- };
- Assertions.waitAssert(condition, "Widget not found");
- return result[0];
- }
-
- @Override
- public Widget find(final Widget node, final Matcher<Widget> matcher) throws NotFoundException, MultipleFoundException
- {
- final Widget[] result = new Widget[1];
- final IWaitCondition condition = new FindWaitCondition()
- {
- @Override
- protected void find() throws NotFoundException, MultipleFoundException
- {
- result[0] = delegate.find(node, matcher);
- }
- };
- Assertions.waitAssert(condition, "Widget not found");
- return result[0];
- }
-
- private abstract class FindWaitCondition implements IWaitCondition
- {
- @Override
- public boolean checkCondition() throws ConditionCheckException
- {
- try
- {
- find();
- return true;
- } catch (NotFoundException e)
- {
- return false;
- } catch (MultipleFoundException e)
- {
- throw new ConditionCheckException(e);
- }
- }
-
- protected abstract void find() throws NotFoundException, MultipleFoundException;
- }
-
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/EnhancedTextMatcher.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/EnhancedTextMatcher.java
deleted file mode 100644
index 61a9f8b..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/EnhancedTextMatcher.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot.matchers;
-
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.widgets.Link;
-import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.forms.widgets.Hyperlink;
-
-import abbot.swt.finder.matchers.WidgetTextMatcher;
-
-/**
- * Text matcher which extends {@link WidgetTextMatcher} and adds support for some unsupported controls (e.g. CLabel)
- * @author Danail Branekov
- */
-@SuppressWarnings("rawtypes")
-public class EnhancedTextMatcher extends WidgetTextMatcher
-{
- private final String text;
-
- public EnhancedTextMatcher(String text, boolean mustBeShowing, Class clazz)
- {
- super(text, clazz, mustBeShowing);
- this.text = text;
- }
-
- public EnhancedTextMatcher(String text, boolean mustBeShowing)
- {
- super(text, mustBeShowing);
- this.text = text;
- }
-
- public EnhancedTextMatcher(String text, Class clazz)
- {
- super(text, clazz);
- this.text = text;
- }
-
- public EnhancedTextMatcher(String text)
- {
- super(text);
- this.text = text;
- }
-
- @Override
- public boolean matches(Widget w)
- {
- if(w instanceof CLabel)
- {
- return handleCLabel((CLabel)w);
- }
-
- if(w instanceof Link)
- {
- return handleLink((Link)w);
- }
-
- if(w instanceof Hyperlink)
- {
- return handleImageHyperlink((Hyperlink)w);
- }
-
- return super.matches(w);
- }
-
- private boolean handleCLabel(final CLabel clabel)
- {
- final boolean[] result = new boolean[]{false};
- clabel.getDisplay().syncExec(new Runnable(){
- @Override
- public void run()
- {
- result[0] = text.equals(clabel.getText());
- }});
-
- return result[0];
- }
-
- private boolean handleLink(final Link link)
- {
- final boolean[] result = new boolean[]{false};
- link.getDisplay().syncExec(new Runnable(){
- @Override
- public void run()
- {
- result[0] = text.equals(link.getText());
- }});
-
- return result[0];
- }
-
- private boolean handleImageHyperlink(final Hyperlink link)
- {
- final boolean[] result = new boolean[]{false};
- link.getDisplay().syncExec(new Runnable(){
- @Override
- public void run()
- {
- result[0] = text.equals(link.getText());
- }});
-
- return result[0];
- }
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/SiblingTextMatcher.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/SiblingTextMatcher.java
deleted file mode 100644
index d3621e8..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/SiblingTextMatcher.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot.matchers;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.PlatformUI;
-
-import abbot.swt.finder.generic.Matcher;
-import abbot.swt.finder.matchers.WidgetTextMatcher;
-
-/**
- * To find a widget by another labeled widget beneath. Labeled widget has to be placed before the widget to be searched.
- *
- * @author Joerg Dehmel, Danail Branekov
- */
-public final class SiblingTextMatcher implements Matcher<Widget>
-{
- private Matcher<Widget> textMatcher;
-
- private Widget parent;
-
- private boolean labelFound;
-
- private boolean widgetFound;
-
- private Class<?> targetWidgetClass;
-
- /**
- * Constructor
- *
- * @param pLabel
- * the label of the labeled widget
- */
- public SiblingTextMatcher(final String pLabel)
- {
- assert pLabel != null;
- labelFound = false;
- widgetFound = false;
- textMatcher = new WidgetTextMatcher(pLabel);
- }
-
- /**
- * Constructor
- *
- * @param pLabel
- * the label of the labeled widget
- * @param pParent
- * the parent of the widget searched or <code>null</code> in case parent check is not desired
- * @param targetWidgetClazz
- * the class of the widget to be found or <code>null</code> in case class check is not desired
- */
- public SiblingTextMatcher(final String pLabel, final Widget pParent, final Class<?> targetWidgetClazz)
- {
- this(pLabel);
- parent = pParent;
- this.targetWidgetClass = targetWidgetClazz;
- }
-
- /**
- * Constructor
- *
- * @param pLabel
- * the label of the labeled widget
- * @param pParent
- * the parent of the widget searched or <code>null</code> in case parent check is not desired
- * @param targetWidgetClazz
- * the class of the widget to be found or <code>null</code> in case class check is not desired
- * @param textMatcher custom {@link Matcher} implementation
- */
- public SiblingTextMatcher(final String pLabel, final Widget pParent, final Class<?> targetWidgetClazz, final Matcher<Widget> textM)
- {
- this(pLabel, pParent, targetWidgetClazz);
- textMatcher = textM;
- }
-
- public boolean matches(final Widget w)
- {
- final boolean[] ret = new boolean[1];
- PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable()
- {
- public void run()
- {
- if (belongsToParent(w) && !labelFound)
- {
- if (textMatcher.matches(w))
- {
- labelFound = true;
- }
- } else if (labelFound && !widgetFound && isOfTargetClass(w))
- {
- widgetFound = true;
- ret[0] = true;
- }
- }
- });
- return ret[0];
- }
-
- private boolean belongsToParent(final Widget widget)
- {
- assert widget != null;
- if (parent == null)
- {
- return true;
- }
- if (!(widget instanceof Control))
- {
- return false;
- }
- final Control control = (Control) widget;
- Control directParent = control.getParent();
- while (directParent != null)
- {
- if (directParent == parent)
- {
- return true;
- }
- directParent = directParent.getParent();
- }
- return false;
- }
-
- private boolean isOfTargetClass(final Widget widget)
- {
- assert widget != null;
- if (targetWidgetClass == null)
- {
- return true;
- }
-
- if (!(widget instanceof Control))
- {
- return false;
- }
-
- return widget.getClass().equals(targetWidgetClass);
- }
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/ToolItemMatcher.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/ToolItemMatcher.java
deleted file mode 100644
index acf84bd..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/matchers/ToolItemMatcher.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot.matchers;
-
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.ToolItem;
-import org.eclipse.swt.widgets.Widget;
-
-import abbot.swt.finder.generic.Matcher;
-
-public class ToolItemMatcher implements Matcher<Widget>
-{
- private final Widget parent;
- private Display display;
-
- public ToolItemMatcher(final Widget parent, final Display testDisplay)
- {
- this.parent = parent;
- this.display = testDisplay;
- }
-
- private boolean belongsToParent(final ToolItem toolItem, final Widget parent)
- {
- final boolean result[] = new boolean[] { false };
- display.syncExec(new Runnable()
- {
- public void run()
- {
- Control parentControl = toolItem.getParent();
- while (parentControl != null)
- {
- if (parentControl == parent)
- {
- result[0] = true;
- }
- parentControl = parentControl.getParent();
- }
- }
- });
-
- return result[0];
- }
-
- public boolean matches(Widget w)
- {
- if(w instanceof ToolItem)
- {
- return belongsToParent((ToolItem) w, this.parent);
- }
- return false;
- }
-} \ No newline at end of file
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/PDEUtil.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/PDEUtil.java
deleted file mode 100644
index 9a6438a..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/PDEUtil.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot.util;
-
-import junit.framework.AssertionFailedError;
-
-public class PDEUtil
-{
- private PDEUtil()
- {
- // prevent instantiation
- }
-
- /**
- * Checks whether the calling application is in foreground.
- * <p/>
- *
- * @return true if the calling application currently is the active window in OS terms.
- */
- private static boolean isDisplayShellActiveWindow()
- {
- // TODO invent implementation which works on all platforms
-
- // Bellow is a Windows implementation
- // final boolean[] b = new boolean[1];
- // if (Platform.getOS().equals(Platform.OS_WIN32)) {
- // Display.getDefault().syncExec(new Runnable() {
- // public void run() {
- // IWorkbench wb = PlatformUI.getWorkbench();
- // IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
- //
- // int winCount = wb.getWorkbenchWindowCount();
- // if (window == null && winCount > 0) {
- // window = wb.getWorkbenchWindows()[0];
- // }
- // Shell shell = window.getShell();
- // // shell.layout(true, true); // gain focus
- // // maximize window TODO remove ?
- //
- // int hWnd = shell.handle;
- // int activeHwnd = OS.GetForegroundWindow();
- // b[0] = hWnd == activeHwnd;
- // }
- // });
- // return b[0];
- // }
- // else {
- // System.err.println(Platform.getOS() + " " + Platform.OS_WIN32);
- // return true;
- // }
-
- return true;
- }
-
- /**
- * Does anything one could think about to prepare for UI tests.
- * <p/>
- * Currently calls consecutive:
- * <ol>
- * <li>{@link #assertDisplayIsActiveWindow()}</li>
- * <li>{@link #closeWelcomePage()}</li>
- * <li>{@link #restoreActivePage()}</li>
- * </ol>
- */
- public static void prepareWorkbench()
- {
- assertDisplayIsActiveWindow();
- }
-
- /**
- * Asserts that the calling application is the active application in OS terms.
- * <p/>
- *
- * @throws AssertionFailedError
- * if the application is not in foreground. In that case the message of the error contains the title of the currently active
- * application.
- */
- private static void assertDisplayIsActiveWindow()
- {
- if (!isDisplayShellActiveWindow())
- {
- final String activeWindowTitle = getActiveWindowTitle();
- throw new AssertionFailedError("The active window[" + activeWindowTitle + "] is not the test window");
- }
- }
-
- private static String getActiveWindowTitle()
- {
- // TODO implement something that gets active window title on all platforms
-
- // Below is an example of windows implementation
- // int WM_GETTEXT = 13;
- // int WM_GETTEXTLENGTH = 14;
- // int hWnd = OS.GetForegroundWindow();
- // int length = OS.GetWindowTextLength(hWnd);
- // length = OS.SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0);
- // TCHAR lpString = new TCHAR(0, length);
- // OS.SendMessage(hWnd, WM_GETTEXT, length + 1, lpString);
- // return lpString.toString();
-
- return "";
- }
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/TimerUtils.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/TimerUtils.java
deleted file mode 100644
index 4834158..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/TimerUtils.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot.util;
-
-import java.lang.reflect.Constructor;
-import java.text.DateFormat;
-
-public class TimerUtils {
-
- /**
- * Holds the initial time before started the test execution to have the time
- * over the complete test run
- */
- private long JDTD_TIME;
- private long START_TIME;
-
- private static TimerUtils instance = null;
-
- public static TimerUtils getInstance() {
- if (instance == null) {
- instance = new TimerUtils();
- }
- return instance;
- }
-
- public void setSTART_TIME(long pStart_time) {
- START_TIME = pStart_time;
- }
-
- public long getJDTD_TIME() {
- return JDTD_TIME;
- }
-
- public void setJDTD_TIME(long pJdtd_time) {
- //throw timeout before JDTD
- double precaution = pJdtd_time * 0.1;
- JDTD_TIME = (System.currentTimeMillis() + pJdtd_time - (long)precaution);
- }
-
- public final String formatNowTime(final long pNow) {
-
- DateFormat dataformat = DateFormat.getTimeInstance(DateFormat.LONG);
- return dataformat.format(pNow);
-
- }
-
- public final long getRemainingTime() {
- long remTime = JDTD_TIME - System.currentTimeMillis();
- return remTime;
- }
-
- @SuppressWarnings("unchecked")
- public final <T extends Number> T getMaxExecutionTime(final T pTimeout) {
- T result = pTimeout;
-
- if (JDTD_TIME == 0) {
- return pTimeout;
- } else {
- long remainingTime = getRemainingTime();
- if (remainingTime < pTimeout.longValue()) {
- System.out.println("Change delay time from . " + pTimeout
- + " sec. to " + remainingTime + " sec.");
- result = remainingTime < 0 || pTimeout.longValue() < 0 ? (T) convert(
- 0, pTimeout.getClass())
- : (T) convert(new Long(remainingTime), pTimeout
- .getClass());
- }
- return result;
- }
-
- }
-
- private <T> T convert(Object value, Class<T> to) {
- try { // first try valueOf Method...
- return to.cast(to.getDeclaredMethod("valueOf",
- new Class[] { String.class })
- .invoke(null, value.toString()));
- } catch (Exception e) { // if that fails
- try { // try String based Constructor
- Constructor<T> constructor = to
- .getDeclaredConstructor(String.class);
- return constructor.newInstance(value.toString());
- } catch (Exception ee) {
- throw new RuntimeException(String.format(
- "Conversion from %s to %s failed for value %s", value
- .getClass(), to, value));
- }
- }
- }
-
- public long[] getRequiredTime(int pTestCount, int pExecutedTestsCount) {
- long ret[] = new long[2];
- long remTime = getRemainingTime();
- long reqTime;
- if (pExecutedTestsCount > 0)
- reqTime = (System.currentTimeMillis() - START_TIME)
- / pExecutedTestsCount;
- else
- reqTime = pTestCount == 0 ? remTime : remTime / pTestCount;
-
- ret[0] = remTime;
- ret[1] = reqTime;
- return ret;
- }
-
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/internal/UICleanupManager.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/internal/UICleanupManager.java
deleted file mode 100644
index 80ec21a..0000000
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/abbot/util/internal/UICleanupManager.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
- * 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:
- * SAP AG - initial API and implementation
- *******************************************************************************/
-package org.eclipse.platform.discovery.testutils.utils.abbot.util.internal;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.platform.discovery.testutils.internal.plugin.TestPlugin;
-import org.eclipse.platform.discovery.testutils.utils.abbot.ActiveSWTTestSuite;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-
-import abbot.swt.Robot;
-
-/**
- * Tool class providing the functionality to clean up the UI after a test has
- * been called. A typical scenario is to close all modal dialogs (which may have
- * not been expected by the test and hence have made it fail) to ensure that the
- * UI thread is not blocked and that following UI tests can start in a defined
- * state. Note that however there is no mean to avoid all interference between
- * UI test, just for the sheer complexity of the UI.
- * <p>
- * For the possible cleanup actions, see the
- * {@link UICleanupManager.CleanupMethod} constants.
- * </p>
- * <p>
- * This class is not public since it has inherited design flaws from legacy
- * classes using this class. Specifically, the fact that calls to
- * <code>setCleanupMethod</code> must be permitted after
- * <code>registerUIState</code> entails a potentially inefficient
- * implementation. However, not being public it can be easily refactored if
- * functionality of this class shall be made available in other projects.
- * </p>
- *
- * @see ActiveSWTTestSuite
- */
-public class UICleanupManager /* implements ISideEffectCleanupManager */{
- /** Selected cleanup method. */
- private CleanupMethod cleanupMethod;
- /** List of shells that were open before the test. */
- private Set<Shell> shellsBeforeExecution = null;
- /** Name of test using this manager (for debug output). */
- private String testDebugName;
-
- /**
- * Approaches for cleaning up spurious UI elements (modal dialogs, context
- * menus, etc.) after the test execution.
- */
- public static enum CleanupMethod {
- /**
- * Register open shells before the test is executed and call
- * <code>close()</code> on every shell that has been left open by the
- * test, in addition to sending escapes.
- * <p>
- * Warning: This method is known to cause problems with the Graphical
- * Editing Framework (GEF) as of Eclipse version 3.3, since GEF stores a
- * shell in a static member.
- * </p>
- */
- SHELL_CLOSE_AND_ESCAPES,
- /**
- * Send escape keys as a heuristic to close dialogs and context menus
- * after the test execution.
- */
- ESCAPES
- }
-
- /**
- * Constructs a manager instance using the most widely applicable cleanup
- * method.
- */
- public UICleanupManager() {
- this(CleanupMethod.ESCAPES);
- }
-
- /**
- * Constructs a manager instance with the specified cleanup method.
- *
- * @param the
- * cleanup method to use. Must not be <code>null</code>.
- */
- public UICleanupManager(final CleanupMethod method) {
- if (method == null) {
- throw new NullPointerException("The method parameter must not be null.");
- }
- this.cleanupMethod = method;
- }
-
- /**
- * Call this method before executing a test.
- */
- public void registerUIState() {
- // register currently open shells; NB: this step must be done
- // irrespective of the active cleanup method because users of this
- // class require that setCleanupMethod may still be called after
- // calling this method
- final Display display = Display.getDefault();
- display.syncExec(new Runnable() {
- public void run() {
- UICleanupManager.this.registerOpenShells(display);
- }
- });
- }
-
- /**
- * Call this method after executing a test in order to provide a "clean" UI
- * before the next test is started.
- *
- * @throws IllegalStateException
- * if {@link #registerUIState()} has not yet been called.
- */
- public void cleanUp() throws IllegalStateException {
- if (shellsBeforeExecution == null)
- throw new IllegalStateException("registerUIState() must be called before cleanUp().");
-
- if (cleanupMethod == CleanupMethod.SHELL_CLOSE_AND_ESCAPES) {
- // explicitly close those shells that were not open before the test method was run
- final Display display = Display.getDefault();
- display.syncExec(new Runnable() {
- public void run() {
- UICleanupManager.this.closeLeftOverShells(display);
- }
- });
- }
-
- switch (cleanupMethod) {
- case SHELL_CLOSE_AND_ESCAPES:
- case ESCAPES:
- // attempt to close dialogs and context menus
- final Robot robot = new Robot(PlatformUI.getWorkbench().getDisplay());
- for (int i = 0; i < 25; i++) {
- robot.key(SWT.ESC);
- }
- }
- }
-
- /**
- * Stores the currently open shells. Must be called within the UI thread.
- *
- * @param display
- * the default display.
- */
- private void registerOpenShells(final Display display) {
- final Shell[] currentShells = display.getShells();
- shellsBeforeExecution = new HashSet<Shell>(Arrays.asList(currentShells));
- }
-
- /**
- * Closes shells that were not open when {@link #registerUIState()} was
- * called. Must be called within the UI thread.
- *
- * @param display
- * the default display.
- */
- private void closeLeftOverShells(final Display display) {
- final Shell[] openShells = display.getShells();
- for (final Shell s : openShells) {
- if (!shellsBeforeExecution.contains(s)) {
- TestPlugin.logWarning("WARNING: " + testDebugName
- + ": There is a shell open which has not been open when the test was started: " + s);
- ActiveSWTTestSuite.closeShells(new Shell[] { s });
- }
- }
- }
-
- public CleanupMethod getCleanupMethod() {
- return cleanupMethod;
- }
-
- public void setCleanupMethod(final CleanupMethod method) throws IllegalStateException {
- this.cleanupMethod = method;
- }
-}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/Builder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/Builder.java
new file mode 100644
index 0000000..eb586be
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/Builder.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+class Builder<T>
+{
+ private final T object;
+
+ Builder(T object)
+ {
+ this.object = object;
+ }
+
+ public T object()
+ {
+ return this.object;
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/ConflictBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/ConflictBuilder.java
new file mode 100644
index 0000000..0e8a755
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/ConflictBuilder.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+import org.eclipse.platform.discovery.runtime.api.IConflict;
+import org.mockito.Mockito;
+
+public class ConflictBuilder extends Builder<IConflict>
+{
+ public ConflictBuilder()
+ {
+ super(Mockito.mock(IConflict.class));
+ }
+
+ public ConflictBuilder conflictsToSubdestination(final String subdestinationId)
+ {
+ Mockito.stub(object().getconflictingSubdID()).toReturn(subdestinationId);
+ return this;
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DescriptiveObjectBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DescriptiveObjectBuilder.java
new file mode 100644
index 0000000..72be8ea
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DescriptiveObjectBuilder.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+import org.eclipse.platform.discovery.runtime.api.IDescriptiveObject;
+import org.mockito.Mockito;
+
+public abstract class DescriptiveObjectBuilder<T extends IDescriptiveObject> extends Builder<T>
+{
+ public DescriptiveObjectBuilder(T object)
+ {
+ super(object);
+ }
+
+ public DescriptiveObjectBuilder<T> withId(final String id)
+ {
+ Mockito.stub(object().getId()).toReturn(id);
+ return this;
+ }
+
+ public DescriptiveObjectBuilder<T> withName(final String name)
+ {
+ Mockito.stub(object().getDisplayName()).toReturn(name);
+ return this;
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestProviderDescriptionBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestProviderDescriptionBuilder.java
new file mode 100644
index 0000000..e3f2cb1
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestProviderDescriptionBuilder.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+import org.eclipse.platform.discovery.runtime.api.IDestinationsProvider;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationsProviderDescription;
+import org.mockito.Mockito;
+
+public class DestProviderDescriptionBuilder extends DescriptiveObjectBuilder<IDestinationsProviderDescription>
+{
+ public DestProviderDescriptionBuilder()
+ {
+ super(Mockito.mock(IDestinationsProviderDescription.class));
+ }
+
+ public DestProviderDescriptionBuilder withProvider(final IDestinationsProvider destProviderInstance)
+ {
+ Mockito.stub(object().createProvider()).toReturn(destProviderInstance);
+ return this;
+ }
+
+ public DestProviderDescriptionBuilder withParefPageId(final String prefPageId)
+ {
+ Mockito.stub(object().getPreferencePageId()).toReturn(prefPageId);
+ return this;
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestinationCategoryDescriptionBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestinationCategoryDescriptionBuilder.java
new file mode 100644
index 0000000..f2dae32
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestinationCategoryDescriptionBuilder.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+import java.util.Arrays;
+
+import org.eclipse.platform.discovery.runtime.api.ISearchDestination;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationCategoryDescription;
+import org.mockito.Mockito;
+
+public class DestinationCategoryDescriptionBuilder extends DescriptiveObjectBuilder<IDestinationCategoryDescription>
+{
+ public DestinationCategoryDescriptionBuilder()
+ {
+ super(Mockito.mock(IDestinationCategoryDescription.class));
+ }
+
+ public DestinationCategoryDescriptionBuilder withDestinationProviders(final String... providersIds)
+ {
+ Mockito.stub(object().getDestinationProviderIds()).toReturn(Arrays.asList(providersIds));
+ return this;
+ }
+
+ public DestinationCategoryDescriptionBuilder withDestinationClass(final Class<ISearchDestination> destClass)
+ {
+ Mockito.stub(object().getDestinationsClass()).toReturn(destClass);
+ return this;
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestinationsProviderBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestinationsProviderBuilder.java
new file mode 100644
index 0000000..fe8bf62
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/DestinationsProviderBuilder.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import org.eclipse.platform.discovery.runtime.api.IDestinationsProvider;
+import org.eclipse.platform.discovery.runtime.api.ISearchDestination;
+import org.mockito.Mockito;
+
+public class DestinationsProviderBuilder extends Builder<IDestinationsProvider>
+{
+ public DestinationsProviderBuilder()
+ {
+ super(Mockito.mock(IDestinationsProvider.class));
+ }
+
+ public DestinationsProviderBuilder withDestinations(final ISearchDestination... destinations)
+ {
+ Mockito.stub(object().getSearchDestinations()).toReturn(new HashSet<ISearchDestination>(Arrays.asList(destinations)));
+ return this;
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/ObjectTypeDescriptionBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/ObjectTypeDescriptionBuilder.java
new file mode 100644
index 0000000..4e22703
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/ObjectTypeDescriptionBuilder.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IObjectTypeDescription;
+import org.mockito.Mockito;
+
+public class ObjectTypeDescriptionBuilder extends DescriptiveObjectBuilder<IObjectTypeDescription>
+{
+ public ObjectTypeDescriptionBuilder()
+ {
+ super(Mockito.mock(IObjectTypeDescription.class));
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchDestinationBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchDestinationBuilder.java
new file mode 100644
index 0000000..ace74b4
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchDestinationBuilder.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+import org.eclipse.platform.discovery.runtime.api.ISearchDestination;
+import org.mockito.Mockito;
+
+public class SearchDestinationBuilder extends Builder<ISearchDestination>
+{
+ public SearchDestinationBuilder()
+ {
+ super(Mockito.mock(ISearchDestination.class));
+ }
+
+ public SearchDestinationBuilder withDisplayName(final String displayName)
+ {
+ Mockito.stub(object().getDisplayName()).toReturn(displayName);
+ return this;
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchProviderBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchProviderBuilder.java
new file mode 100644
index 0000000..d2454a6
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchProviderBuilder.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import org.eclipse.platform.discovery.runtime.api.GroupingHierarchy;
+import org.eclipse.platform.discovery.runtime.api.ISearchDestination;
+import org.eclipse.platform.discovery.runtime.api.ISearchParameters;
+import org.eclipse.platform.discovery.runtime.api.ISearchProvider;
+import org.eclipse.platform.discovery.runtime.api.ISearchQuery;
+import org.mockito.Mockito;
+
+public class SearchProviderBuilder extends Builder<ISearchProvider>
+{
+ public SearchProviderBuilder()
+ {
+ super(Mockito.mock(ISearchProvider.class));
+ }
+
+ public SearchProviderBuilder createsQuery(final ISearchQuery query)
+ {
+ Mockito.stub(object().createQuery(Mockito.any(ISearchParameters.class))).toReturn(query);
+ return this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public SearchProviderBuilder withGroupingHierarchies(final GroupingHierarchy... hierarchies)
+ {
+ Mockito.stub(object().getGroupingHierarchies(Mockito.any(ISearchDestination.class), Mockito.anySet())).toReturn(new HashSet<GroupingHierarchy>(Arrays.asList(hierarchies)));
+ return this;
+ }
+
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchProviderDescriptionBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchProviderDescriptionBuilder.java
new file mode 100644
index 0000000..5cdb6e7
--- /dev/null
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SearchProviderDescriptionBuilder.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG, Walldorf.
+ * 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:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.platform.discovery.testutils.utils.model;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import org.eclipse.platform.discovery.runtime.api.ISearchProvider;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationCategoryDescription;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IObjectTypeDescription;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.ISearchProviderDescription;
+import org.mockito.Mockito;
+
+public class SearchProviderDescriptionBuilder extends DescriptiveObjectBuilder<ISearchProviderDescription>
+{
+ public SearchProviderDescriptionBuilder()
+ {
+ super(Mockito.mock(ISearchProviderDescription.class));
+ }
+
+ public SearchProviderDescriptionBuilder supportsTextSearch(final boolean supportsTextSearch)
+ {
+ Mockito.stub(object().supportsTextSearch()).toReturn(supportsTextSearch);
+ return this;
+ }
+
+ public SearchProviderDescriptionBuilder withSearchProviderInstance(final ISearchProvider searchProvider)
+ {
+ Mockito.stub(object().createInstance()).toReturn(searchProvider);
+ return this;
+ }
+
+ public SearchProviderDescriptionBuilder withDestinationCategories(final IDestinationCategoryDescription... categories)
+ {
+ Mockito.stub(object().getSupportedDestinationCategories()).toReturn(new HashSet<IDestinationCategoryDescription>(Arrays.asList(categories)));
+ return this;
+ }
+
+ public SearchProviderDescriptionBuilder supportsObjectType(final IObjectTypeDescription objectType)
+ {
+ Mockito.stub(object().getObjectType()).toReturn(objectType);
+ return this;
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SubdestinationBuilder.java b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SubdestinationBuilder.java
index 5a2d3d7..8a79065 100644
--- a/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SubdestinationBuilder.java
+++ b/tests/org.eclipse.platform.discovery.test.testutils/src/org/eclipse/platform/discovery/testutils/utils/model/SubdestinationBuilder.java
@@ -1,42 +1,50 @@
/*******************************************************************************
- * Copyright (c) 2011 SAP AG, Walldorf
+ * Copyright (c) 2011 SAP AG, Walldorf.
* 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:
- * SAP AG - initial API and implementation
+ * SAP AG - initial API and implementation
*******************************************************************************/
package org.eclipse.platform.discovery.testutils.utils.model;
+import java.util.Arrays;
import java.util.HashSet;
-import java.util.Set;
import org.eclipse.platform.discovery.runtime.api.IConflict;
import org.eclipse.platform.discovery.runtime.api.ISearchSubdestination;
-import static org.mockito.Mockito.*;
+import org.mockito.Mockito;
-public class SubdestinationBuilder {
-
- public ISearchSubdestination buildSubdestination(String id, String categoryId, String objectTypeId, String... conflicts) {
- ISearchSubdestination result = mock(ISearchSubdestination.class);
- when(result.getId()).thenReturn(id);
- when(result.getDestinationCategoryId()).thenReturn(categoryId);
- when(result.getObjectTypeId()).thenReturn(objectTypeId);
- Set<IConflict> conflictsSet = buildConflicts(conflicts);
- when(result.getConflictingSubd()).thenReturn(conflictsSet);
- return result;
+public class SubdestinationBuilder extends DescriptiveObjectBuilder<ISearchSubdestination>
+{
+ public SubdestinationBuilder()
+ {
+ super(Mockito.mock(ISearchSubdestination.class));
}
-
- private Set<IConflict> buildConflicts(String[] conflictIds) {
- Set<IConflict> result = new HashSet<IConflict>();
- for(String conflictId:conflictIds) {
- IConflict conflict = mock(IConflict.class);
- when(conflict.getconflictingSubdID()).thenReturn(conflictId);
- result.add(conflict);
- }
- return result;
+
+ public SubdestinationBuilder withDestCategoryId(final String destCategoryId)
+ {
+ Mockito.stub(object().getDestinationCategoryId()).toReturn(destCategoryId);
+ return this;
+ }
+
+ public SubdestinationBuilder forObjectType(final String objectTypeId)
+ {
+ Mockito.stub(object().getObjectTypeId()).toReturn(objectTypeId);
+ return this;
}
+ public SubdestinationBuilder defaultSelected(final boolean defaultSelected)
+ {
+ Mockito.stub(object().isDefaultSelected()).toReturn(defaultSelected);
+ return this;
+ }
+
+ public SubdestinationBuilder conflictsTo(IConflict... conflicts)
+ {
+ Mockito.stub(object().getConflictingSubd()).toReturn(new HashSet<IConflict>(Arrays.asList(conflicts)));
+ return this;
+ }
}

Back to the top