Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2006-01-11 13:52:04 +0000
committeratikhomirov2006-01-11 13:52:04 +0000
commitee29f51ed574b0767f9cbee1490d001197b5bb13 (patch)
tree4826f723016655a34714d21504ef7a82eb779949
parent638d7a58f7bc95c5f874092f85b7dc9c90e6189b (diff)
downloadorg.eclipse.gmf-tooling-ee29f51ed574b0767f9cbee1490d001197b5bb13.tar.gz
org.eclipse.gmf-tooling-ee29f51ed574b0767f9cbee1490d001197b5bb13.tar.xz
org.eclipse.gmf-tooling-ee29f51ed574b0767f9cbee1490d001197b5bb13.zip
refactor test configuration framework to be generic and useful not only for SessionSetup
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java46
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/ConfiguredTestCase.java2
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/NeedsSetup.java15
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/TestConfiguration.java19
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java3
5 files changed, 73 insertions, 12 deletions
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java
index a1f0a87a5..ae1565098 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java
@@ -11,6 +11,8 @@
*/
package org.eclipse.gmf.tests;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Enumeration;
import junit.framework.Test;
@@ -77,14 +79,48 @@ public class AllTests {
return suite;
}
- private static TestSuite feed(Class theClass, SessionSetup setup) {
+ private static Test feed(Class theClass, TestConfiguration config) {
TestSuite suite = new TestSuite(theClass);
- for (Enumeration en = suite.tests(); en.hasMoreElements(); ) {
- Object nextTest = en.nextElement();
- if (nextTest instanceof NeedsSetup) {
- ((NeedsSetup) nextTest).setSetup(setup);
+ if (!NeedsSetup.class.isAssignableFrom(theClass)) {
+ return suite;
+ }
+ try {
+ Method m = null;
+ Class configClass = config.getClass();
+ while (m == null && configClass != null) {
+ try {
+ m = theClass.getMethod(NeedsSetup.METHOD_NAME, new Class[] { configClass });
+ } catch (NoSuchMethodException ex) {
+ configClass = configClass.getSuperclass();
+ }
+ }
+ if (m == null) {
+ String methodInvocation = NeedsSetup.METHOD_NAME + "(" + config.getClass().getSimpleName() + " arg);";
+ return new ConfigurationFailedCase(theClass.getCanonicalName() + " has no method compatible with " + methodInvocation);
+ }
+ final Object[] args = new Object[] { config };
+ for (Enumeration en = suite.tests(); en.hasMoreElements(); ) {
+ Object nextTest = en.nextElement();
+ m.invoke(nextTest, args);
}
+ } catch (SecurityException ex) {
+ return new ConfigurationFailedCase(theClass.getCanonicalName() + ": " + ex.getMessage());
+ } catch (IllegalAccessException ex) {
+ return new ConfigurationFailedCase(theClass.getCanonicalName() + ": " + ex.getMessage());
+ } catch (InvocationTargetException ex) {
+ return new ConfigurationFailedCase(theClass.getCanonicalName() + ": " + ex.getMessage());
}
return suite;
}
+
+ private static class ConfigurationFailedCase extends TestCase {
+ private final String cause;
+ ConfigurationFailedCase(String aCause) {
+ super(ConfigurationFailedCase.class.getName());
+ cause = aCause;
+ }
+ protected void runTest() throws Throwable {
+ fail(cause);
+ }
+ }
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/ConfiguredTestCase.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/ConfiguredTestCase.java
index 11e9d18e9..aa88385c6 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/ConfiguredTestCase.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/ConfiguredTestCase.java
@@ -27,7 +27,7 @@ public abstract class ConfiguredTestCase extends TestCase implements NeedsSetup
super(name);
}
- public final void setSetup(SessionSetup sessionSetup) {
+ public final void configure(SessionSetup sessionSetup) {
assertNotNull(sessionSetup);
mySessionSetup = sessionSetup;
mySessionSetup.oneUp();
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/NeedsSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/NeedsSetup.java
index 357290055..b0e17ecbc 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/NeedsSetup.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/NeedsSetup.java
@@ -11,13 +11,18 @@
*/
package org.eclipse.gmf.tests;
-import org.eclipse.gmf.tests.setup.SessionSetup;
-
/**
+ * Marker interface used in conjunction with {@link TestConfiguration} class.
+ * Test that needs some configuration object (i.e. one which implements {@link TestConfiguration})
+ * should add this interface to the <code>implements</code> list <b>AND</b>
+ * define method named <em>configure</em> ({@link #METHOD_NAME}) taking its favourite
+ * TestConfiguration subclass as a single argument.
+ *
* @author artem
- *
*/
public interface NeedsSetup {
-
- void setSetup(SessionSetup sessionSetup);
+ /**
+ * Name of the method to be invoked via reflection (value: <em>configure</em>)
+ */
+ String METHOD_NAME = "configure";
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/TestConfiguration.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/TestConfiguration.java
new file mode 100644
index 000000000..5b193d23f
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/TestConfiguration.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2005 Borland Software Corporation
+ *
+ * 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.tests;
+
+/**
+ * Marker interface to denote objects to be used as test initialization
+ * @author artem
+ */
+public interface TestConfiguration {
+}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java
index 5131a32fa..636bc1282 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/SessionSetup.java
@@ -11,12 +11,13 @@
*/
package org.eclipse.gmf.tests.setup;
+import org.eclipse.gmf.tests.TestConfiguration;
import org.osgi.framework.BundleException;
/**
* @author artem
*/
-public class SessionSetup {
+public class SessionSetup implements TestConfiguration {
private DomainModelSource myDomainModel;
private DiaGenSource myGenModel;

Back to the top