KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > junit > runtime > LegacyUITestApplication


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
26  * A Workbench that runs a test suite specified in the
27  * command line arguments.
28  */

29 public class LegacyUITestApplication implements IPlatformRunnable, ITestHarness {
30     
31     private static final String JavaDoc DEFAULT_APP_3_0 = "org.eclipse.ui.ide.workbench"; //$NON-NLS-1$
32

33     private TestableObject fTestableObject;
34     
35     /* (non-Javadoc)
36      * @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
37      */

38     public Object JavaDoc run(final Object JavaDoc args) throws Exception JavaDoc {
39         IPlatformRunnable application = getApplication((String JavaDoc[]) args);
40
41         Assert.assertNotNull(application);
42
43         fTestableObject = PlatformUI.getTestableObject();
44         fTestableObject.setTestHarness(this);
45         return application.run(args);
46     }
47     
48
49     /*
50      * return the application to run, or null if not even the default application
51      * is found.
52      */

53     private IPlatformRunnable getApplication(String JavaDoc[] args) throws CoreException {
54         // Find the name of the application as specified by the PDE JUnit launcher.
55
// If no application is specified, the 3.0 default workbench application
56
// is returned.
57
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         // If the extension does not have the correct grammar, return null.
67
// Otherwise, return the application object.
68
IConfigurationElement[] elements = extension.getConfigurationElements();
69         if (elements.length > 0) {
70             IConfigurationElement[] runs = elements[0].getChildren("run"); //$NON-NLS-1$
71
if (runs.length > 0) {
72                 Object JavaDoc runnable = runs[0].createExecutableExtension("class"); //$NON-NLS-1$
73
if (runnable instanceof IPlatformRunnable)
74                     return (IPlatformRunnable) runnable;
75             }
76         }
77         return null;
78     }
79     
80     /*
81      * The -testApplication argument specifies the application to be run.
82      * If the PDE JUnit launcher did not set this argument, then return
83      * the name of the default application.
84      * In 3.0, the default is the "org.eclipse.ui.ide.worbench" application.
85      *
86      */

87     private String JavaDoc getApplicationToRun(String JavaDoc[] 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) //$NON-NLS-1$
93
return args[i+1];
94         }
95         return DEFAULT_APP_3_0;
96     }
97     
98     /* (non-Javadoc)
99      * @see org.eclipse.ui.testing.ITestHarness#runTests()
100      */

101     public void runTests() {
102         fTestableObject.testingStarting();
103         fTestableObject.runTest(new Runnable JavaDoc() {
104             public void run() {
105                 RemotePluginTestRunner.main(Platform.getCommandLineArgs());
106             }
107         });
108         fTestableObject.testingFinished();
109     }
110         
111 }
112
Popular Tags