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.equinox.app.IApplication; 22 import org.eclipse.equinox.app.IApplicationContext; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.testing.ITestHarness; 25 import org.eclipse.ui.testing.TestableObject; 26 27 31 public class UITestApplication implements IApplication, ITestHarness { 32 33 private static final String DEFAULT_APP_3_0 = "org.eclipse.ui.ide.workbench"; 35 private TestableObject fTestableObject; 36 private IApplication fApplication; 37 38 42 public Object start(IApplicationContext context) throws Exception { 43 String [] args = (String []) context.getArguments().get(IApplicationContext.APPLICATION_ARGS); 44 Object app = getApplication(args); 45 46 Assert.assertNotNull(app); 47 48 fTestableObject = PlatformUI.getTestableObject(); 49 fTestableObject.setTestHarness(this); 50 if (app instanceof IApplication) { 51 fApplication = (IApplication) app; 52 return fApplication.start(context); 53 } 54 return ((IPlatformRunnable) app).run(args); 55 } 56 57 61 public void stop() { 62 if (fApplication != null) 63 fApplication.stop(); 64 } 65 66 70 private Object getApplication(String [] args) throws CoreException { 71 IExtension extension = 75 Platform.getExtensionRegistry().getExtension( 76 Platform.PI_RUNTIME, 77 Platform.PT_APPLICATIONS, 78 getApplicationToRun(args)); 79 80 Assert.assertNotNull(extension); 81 82 IConfigurationElement[] elements = extension.getConfigurationElements(); 85 if (elements.length > 0) { 86 IConfigurationElement[] runs = elements[0].getChildren("run"); if (runs.length > 0) { 88 Object runnable = runs[0].createExecutableExtension("class"); if (runnable instanceof IPlatformRunnable || runnable instanceof IApplication) 90 return runnable; 91 } 92 } 93 return null; 94 } 95 96 103 private String getApplicationToRun(String [] args) { 104 IProduct product = Platform.getProduct(); 105 if (product != null) 106 return product.getApplication(); 107 for (int i = 0; i < args.length; i++) { 108 if (args[i].equals("-testApplication") && i < args.length -1) return args[i+1]; 110 } 111 return DEFAULT_APP_3_0; 112 } 113 114 118 public void runTests() { 119 fTestableObject.testingStarting(); 120 fTestableObject.runTest(new Runnable () { 121 public void run() { 122 RemotePluginTestRunner.main(Platform.getCommandLineArgs()); 123 } 124 }); 125 fTestableObject.testingFinished(); 126 } 127 128 } 129 | Popular Tags |