1 11 package org.eclipse.pde.internal.junit.runtime; 12 13 import junit.framework.Assert; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExtension; 18 import org.eclipse.core.runtime.IPlatformRunnable; 19 import org.eclipse.core.runtime.IProduct; 20 import org.eclipse.core.runtime.Platform; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.testing.ITestHarness; 23 import org.eclipse.ui.testing.TestableObject; 24 25 29 public class LegacyUITestApplication implements IPlatformRunnable, ITestHarness { 30 31 private static final String DEFAULT_APP_3_0 = "org.eclipse.ui.ide.workbench"; 33 private TestableObject fTestableObject; 34 35 38 public Object run(final Object args) throws Exception { 39 IPlatformRunnable application = getApplication((String []) args); 40 41 Assert.assertNotNull(application); 42 43 fTestableObject = PlatformUI.getTestableObject(); 44 fTestableObject.setTestHarness(this); 45 return application.run(args); 46 } 47 48 49 53 private IPlatformRunnable getApplication(String [] args) throws CoreException { 54 IExtension extension = 58 Platform.getExtensionRegistry().getExtension( 59 Platform.PI_RUNTIME, 60 Platform.PT_APPLICATIONS, 61 getApplicationToRun(args)); 62 63 64 Assert.assertNotNull(extension); 65 66 IConfigurationElement[] elements = extension.getConfigurationElements(); 69 if (elements.length > 0) { 70 IConfigurationElement[] runs = elements[0].getChildren("run"); if (runs.length > 0) { 72 Object runnable = runs[0].createExecutableExtension("class"); if (runnable instanceof IPlatformRunnable) 74 return (IPlatformRunnable) runnable; 75 } 76 } 77 return null; 78 } 79 80 87 private String getApplicationToRun(String [] args) { 88 IProduct product = Platform.getProduct(); 89 if (product != null) 90 return product.getApplication(); 91 for (int i = 0; i < args.length; i++) { 92 if (args[i].equals("-testApplication") && i < args.length -1) return args[i+1]; 94 } 95 return DEFAULT_APP_3_0; 96 } 97 98 101 public void runTests() { 102 fTestableObject.testingStarting(); 103 fTestableObject.runTest(new Runnable () { 104 public void run() { 105 RemotePluginTestRunner.main(Platform.getCommandLineArgs()); 106 } 107 }); 108 fTestableObject.testingFinished(); 109 } 110 111 } 112 | Popular Tags |