summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis Windatt2013-04-19 18:15:23 (EDT)
committer Curtis Windatt2013-04-19 18:15:43 (EDT)
commitbc6ecd8814725cb315d8a4e9a21589fbb94d3194 (patch)
treea590533c5d8e89b85bfa4e019c3230345e99c004
parentb164ca854eea3063fffb21e29e4c92c42d1ec119 (diff)
downloadeclipse.pde.ui-bc6ecd8814725cb315d8a4e9a21589fbb94d3194.zip
eclipse.pde.ui-bc6ecd8814725cb315d8a4e9a21589fbb94d3194.tar.gz
eclipse.pde.ui-bc6ecd8814725cb315d8a4e9a21589fbb94d3194.tar.bz2
Bug 296599 - Add ability to run e4 based tests using PDE's JUnit Plug-in
-rw-r--r--ui/org.eclipse.pde.junit.runtime/META-INF/MANIFEST.MF2
-rw-r--r--ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/NonUIThreadTestApplication.java30
-rw-r--r--ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/PDEJUnitRuntimePlugin.java91
-rw-r--r--ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/UITestApplication.java13
4 files changed, 123 insertions, 13 deletions
diff --git a/ui/org.eclipse.pde.junit.runtime/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.junit.runtime/META-INF/MANIFEST.MF
index d4c0225..de16a38 100644
--- a/ui/org.eclipse.pde.junit.runtime/META-INF/MANIFEST.MF
+++ b/ui/org.eclipse.pde.junit.runtime/META-INF/MANIFEST.MF
@@ -11,3 +11,5 @@ Require-Bundle: org.eclipse.jdt.junit.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional
Export-Package: org.eclipse.pde.internal.junit.runtime;x-internal:=true
Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Bundle-Activator: org.eclipse.pde.internal.junit.runtime.PDEJUnitRuntimePlugin
+Bundle-ActivationPolicy: lazy
diff --git a/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/NonUIThreadTestApplication.java b/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/NonUIThreadTestApplication.java
index 840b5bf..682593c 100644
--- a/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/NonUIThreadTestApplication.java
+++ b/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/NonUIThreadTestApplication.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 EclipseSource Corporation and others.
+ * Copyright (c) 2009, 2013 EclipseSource Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -56,17 +56,27 @@ public class NonUIThreadTestApplication implements IApplication {
return ((IPlatformRunnable) app).run(args);
}
+ /**
+ * the non-UI thread test application also supports launching headless applications;
+ * this may mean that no UI bundle will be available; thus, in order to not
+ * introduce any dependency on UI code we first attempt to get the harness via service.
+ * If that doesn't work, we use reflection to call the workbench code, but don't fail
+ * if Platform UI is not available.
+ *
+ * @throws Exception
+ */
private void installPlatformUITestHarness() throws Exception {
- // the non-UI thread test application also supports launching headless applications;
- // this may mean that no UI bundle will be available; thus, in order to not
- // introduce any dependency on UI code we use reflection but don't fail when Platform UI
- // is not available
- try {
- Class platformUIClass = Class.forName("org.eclipse.ui.PlatformUI", true, getClass().getClassLoader()); //$NON-NLS-1$
- Object testableObject = platformUIClass.getMethod("getTestableObject", null).invoke(null, null); //$NON-NLS-1$
+ Object testableObject = PDEJUnitRuntimePlugin.getDefault().getTestableObject();
+ if (testableObject == null) {
+ try {
+ Class platformUIClass = Class.forName("org.eclipse.ui.PlatformUI", true, getClass().getClassLoader()); //$NON-NLS-1$
+ testableObject = platformUIClass.getMethod("getTestableObject", null).invoke(null, null); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ // PlatformUI is not available
+ }
+ }
+ if (testableObject != null) {
fTestHarness = new PlatformUITestHarness(testableObject, true);
- } catch (ClassNotFoundException e) {
- // PlatformUI is not available
}
}
diff --git a/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/PDEJUnitRuntimePlugin.java b/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/PDEJUnitRuntimePlugin.java
new file mode 100644
index 0000000..e996721
--- /dev/null
+++ b/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/PDEJUnitRuntimePlugin.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.junit.runtime;
+
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.Workbench;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.testing.TestableObject;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * The plug-in activator for the PDE JUnit Runtime plug-in
+ * @since 4.3
+ */
+public class PDEJUnitRuntimePlugin extends AbstractUIPlugin {
+
+ /**
+ * Default instance of the receiver
+ */
+ private static PDEJUnitRuntimePlugin inst;
+
+ /**
+ * The context within which this plugin was started.
+ */
+ private BundleContext bundleContext;
+
+ private ServiceTracker testableTracker = null;
+
+ public PDEJUnitRuntimePlugin() {
+ super();
+ inst = this;
+ }
+
+ /**
+ * Return the default instance of this plug-in activator. This represents the runtime plug-in.
+ * @return PdeJUnitRuntimePlugin the runtime plug-in or <code>null</code> if the plug-in isn't started
+ * @see AbstractUIPlugin for the typical implementation pattern for plug-in classes.
+ */
+ public static PDEJUnitRuntimePlugin getDefault() {
+ return inst;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ bundleContext = context;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ if (testableTracker != null) {
+ testableTracker.close();
+ testableTracker = null;
+ }
+ super.stop(context);
+ }
+
+ /**
+ * Returns a {@link TestableObject} provided by a TestableObject
+ * service or <code>null</code> if a service implementation cannot
+ * be found. The TestableObject is used to hook tests into the
+ * application lifecycle.
+ * <p>
+ * It is recommended the testable object is obtained via service
+ * over {@link Workbench#getWorkbenchTestable()} to avoid the
+ * tests having a dependency on the Workbench.
+ * </p>
+ * @see PlatformUI#getTestableObject()
+ * @return TestableObject provided via service or <code>null</code>
+ */
+ public TestableObject getTestableObject() {
+ if (bundleContext == null)
+ return null;
+ if (testableTracker == null) {
+ testableTracker = new ServiceTracker(bundleContext, TestableObject.class.getName(), null);
+ testableTracker.open();
+ }
+ return (TestableObject) testableTracker.getService();
+ }
+
+}
diff --git a/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/UITestApplication.java b/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/UITestApplication.java
index 5a787e8..e20464f 100644
--- a/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/UITestApplication.java
+++ b/ui/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/UITestApplication.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,6 +13,7 @@ package org.eclipse.pde.internal.junit.runtime;
import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.testing.TestableObject;
/**
* A Workbench that runs a test suite specified in the
@@ -34,8 +35,14 @@ public class UITestApplication extends NonUIThreadTestApplication {
* @see org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication#runApp(java.lang.Object, org.eclipse.equinox.app.IApplicationContext, java.lang.String[])
*/
protected Object runApp(Object app, IApplicationContext context, String[] args) throws Exception {
- // create UI test harness
- fTestHarness = new PlatformUITestHarness(PlatformUI.getTestableObject(), false);
+ // Get the testable object from the service
+ TestableObject testableObject = PDEJUnitRuntimePlugin.getDefault().getTestableObject();
+ // If the service doesn't return a testable object ask PlatformUI directly
+ // Unlike in NonUIThreadTestApplication if the platform dependency is not available we will fail here
+ if (testableObject == null) {
+ testableObject = PlatformUI.getTestableObject();
+ }
+ fTestHarness = new PlatformUITestHarness(testableObject, false);
// continue application launch
return super.runApp(app, context, args);