Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2015-02-08 23:26:32 +0000
committerChristian W. Damus2015-02-08 23:26:32 +0000
commitc6128168bb854cbcf001139bb9bf7a6dc67eccec (patch)
tree1329e4aa3fb377ba7a7aa794eaa1b27a0961f10f /tests/junit/plugins/junit
parentf88c47d042015e59bfef4f923d9cb142574d3c54 (diff)
downloadorg.eclipse.papyrus-c6128168bb854cbcf001139bb9bf7a6dc67eccec.tar.gz
org.eclipse.papyrus-c6128168bb854cbcf001139bb9bf7a6dc67eccec.tar.xz
org.eclipse.papyrus-c6128168bb854cbcf001139bb9bf7a6dc67eccec.zip
451230: Modeling assistants customization for profiles
https://bugs.eclipse.org/bugs/show_bug.cgi?id=451230 Infrastructure for dynamically provisionable modeled Diagram Assistants in Papyrus diagrams, based on the element types described by Element Type Configuration models. Includes: - common model for filters - UML-specific filters - Modeling Assistant Providers model - dynamic registry of modeled assistant providers, with extension point for static registrations - GMF modeling assistant provider extension that delegates to modeled providers - Element Type Configurations and Diagram Assistants model generators with wizards, generating models based on UML Profiles targeting specific element-type config models (for a diagram or for UML generally) - Assistants model generation from a GMFGen model for a particular UML diagram - refactoring of JUnit test suite framework for better partitioning of the All-Tests suite-of-suites - automated tests for the filters model, assistants model, assistant provider extension, and model transformations
Diffstat (limited to 'tests/junit/plugins/junit')
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/META-INF/MANIFEST.MF3
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/classification/ClassificationConfig.java157
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/AllTestsRunner.java111
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/FragmentTestSuiteClass.java67
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/ITestSuiteClass.java28
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/PluginTestSuiteClass.java46
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/SuiteSpot.java29
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.classpath14
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF2
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/pom.xml13
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java15
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/JUnitUtils.java116
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractModelFixture.java32
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java33
15 files changed, 588 insertions, 84 deletions
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/META-INF/MANIFEST.MF b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/META-INF/MANIFEST.MF
index 31c43c5ac6d..331a5ff19c3 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/META-INF/MANIFEST.MF
@@ -1,7 +1,8 @@
Manifest-Version: 1.0
Export-Package: org.eclipse.papyrus.junit.framework.classification,
org.eclipse.papyrus.junit.framework.classification.rules,
- org.eclipse.papyrus.junit.framework.classification.tests
+ org.eclipse.papyrus.junit.framework.classification.tests,
+ org.eclipse.papyrus.junit.framework.runner
Require-Bundle: org.junit;bundle-version="4.11.0",
org.eclipse.papyrus.infra.tools;bundle-version="1.1.0",
org.eclipse.emf.edit;bundle-version="2.10.0",
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/classification/ClassificationConfig.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/classification/ClassificationConfig.java
index f5bc93d0a9e..904106b6d40 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/classification/ClassificationConfig.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/classification/ClassificationConfig.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 451230
*****************************************************************************/
package org.eclipse.papyrus.junit.framework.classification;
@@ -21,37 +22,52 @@ import static org.eclipse.papyrus.junit.framework.classification.TestCategory.St
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.papyrus.infra.tools.util.ListHelper;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
/**
- * This class is used to configure the Classification Annotations which should be
- * excluded from a test job.
- *
+ * <p>
+ * This class is used to configure the Classification Annotations which should be excluded from a test job. A classification configuration is an immutable set of {@linkplain TestCategory test categories} that are included in the test configuration.
+ * </p>
+ * <p>
* Usage:
- *
+ * </p>
+ *
+ * <pre>
* ClassificationConfig.setExcludedTestCategories(TestCategory.InvalidTest, TestCategory.NotImplemented);
- *
- * or
- *
+ *
+ * // or
+ *
* ClassificationConfig.setIncludedTestCategories(TestCategory.Standard, TestCategory.NotImplemented);
- *
+ *
+ * // or
+ *
+ * ClassificationConfig.setExcludedTestCategories(ClassificationConfig.FAILING_TESTS_CONFIG);
+ *
+ * // or
+ *
+ * ClassificationConfig.setIncludedTestCategories(ClassificationConfig.FULL_CI_TESTS_CONFIG);
+ *
+ * // or
+ *
+ * ClassificationConfig.setTestsConfiguration(ClassificationConfig.CI_TESTS_CONFIG);
+ * </pre>
+ *
* @author Camille Letavernier
*
* @see {@link TestCategory}
* @see {@link ClassificationRunner}
*
*/
-public class ClassificationConfig {
-
- public static final Set<TestCategory> excludedTestCategories = new HashSet<TestCategory>();
+public enum ClassificationConfig implements Set<TestCategory> {
/**
* Default tests configuration for Continuous Integration (Hudson): Excludes the tests which are
@@ -59,7 +75,7 @@ public class ClassificationConfig {
*
* This configuration may require a couple of hours to run
*/
- public static final Set<TestCategory> CI_TESTS_CONFIG = ImmutableSet.copyOf(new TestCategory[]{ NotImplemented, InvalidTest, FailingTest, InteractiveTest });
+ CI_TESTS_CONFIG(NotImplemented, InvalidTest, FailingTest, InteractiveTest),
/**
* This tests configuration runs all tests which are already identified as failing.
@@ -67,37 +83,47 @@ public class ClassificationConfig {
*
* InteractiveTests are excluded as well, as this configuration is supposed to be executed on Hudson
*/
- public static final Set<TestCategory> FAILING_TESTS_CONFIG = ImmutableSet.copyOf(new TestCategory[]{ Standard, InteractiveTest });
+ FAILING_TESTS_CONFIG(Standard, InteractiveTest),
/**
* This tests configuration is expected to run in ~15 minutes. This is useful for quick testing,
* and validation through Gerrit
*/
- public static final Set<TestCategory> LIGTHWEIGHT_TESTS_CONFIG = ImmutableSet.copyOf(new TestCategory[]{ InteractiveTest, NotImplemented, FailingTest, InvalidTest, ExpensiveTest });
+ LIGTHWEIGHT_TESTS_CONFIG(InteractiveTest, NotImplemented, FailingTest, InvalidTest, ExpensiveTest),
/**
* This tests configuration is meant to execute all tests in an automated environment
* It includes all tests which are known to be failing, but excludes tests which
* require a user interaction
*/
- public static final Set<TestCategory> FULL_CI_TESTS_CONFIG = ImmutableSet.copyOf(new TestCategory[]{ InteractiveTest });
+ FULL_CI_TESTS_CONFIG(InteractiveTest),
/**
* Executes all tests
*/
- public static final Set<TestCategory> FULL_TESTS_CONFIG = Collections.emptySet();
+ FULL_TESTS_CONFIG();
+
+ public static final Set<TestCategory> excludedTestCategories = new HashSet<TestCategory>();
+
+ private final Set<TestCategory> categories;
static {
- //Default on Hudson: exclude everything which is already identified as an issue (i.e. is not a (new) regression)
+ // Default on Hudson: exclude everything which is already identified as an issue (i.e. is not a (new) regression)
setTestsConfiguration(CI_TESTS_CONFIG);
- //Check whether identified regressions are still failing
- //setIncludedTestCategories(FailingTest);
+ // Check whether identified regressions are still failing
+ // setIncludedTestCategories(FailingTest);
}
- //Same as setExcludedTestsCategories, but renamed for clarity (To be used with predefined configurations)
+ private ClassificationConfig(TestCategory... exclusions) {
+ Set<TestCategory> categories = Sets.newHashSet(TestCategory.values());
+ categories.removeAll(Arrays.asList(exclusions));
+ this.categories = ImmutableSet.copyOf(categories);
+ }
+
+ // Same as setExcludedTestsCategories, but renamed for clarity (To be used with predefined configurations)
public static void setTestsConfiguration(Set<TestCategory> predefinedConfiguration) {
- setExcludedTestCategories(predefinedConfiguration);
+ setIncludedTestCategories(predefinedConfiguration);
}
/**
@@ -144,26 +170,26 @@ public class ClassificationConfig {
* Tests whether a method containing the given set of Annotations should be executed
*
* @param annotations
- * The annotations applied to the Method
+ * The annotations applied to the Method
* @return
* True if the test method should be executed, false if it should be ignored
*/
public static boolean shouldRun(Annotation[] annotations) {
- for(Annotation annotation : annotations) {
+ for (Annotation annotation : annotations) {
Class<? extends Annotation> annotationClass = annotation.annotationType();
- if(isExcluded(annotationClass)) {
+ if (isExcluded(annotationClass)) {
return false;
}
}
- if(excludedTestCategories.contains(TestCategory.Standard)) {
- for(TestCategory testCategory : TestCategory.values()) {
- if(testCategory == TestCategory.Standard) {
+ if (excludedTestCategories.contains(TestCategory.Standard)) {
+ for (TestCategory testCategory : TestCategory.values()) {
+ if (testCategory == TestCategory.Standard) {
continue;
}
- for(Annotation annotation : annotations) {
- if(testCategory.match(annotation.annotationType())) {
+ for (Annotation annotation : annotations) {
+ if (testCategory.match(annotation.annotationType())) {
return true;
}
}
@@ -182,8 +208,8 @@ public class ClassificationConfig {
* @return
*/
public static boolean isExcluded(Class<? extends Annotation> annotationClass) {
- for(TestCategory testCategory : excludedTestCategories) {
- if(testCategory.match(annotationClass)) {
+ for (TestCategory testCategory : excludedTestCategories) {
+ if (testCategory.match(annotationClass)) {
return true;
}
}
@@ -191,4 +217,69 @@ public class ClassificationConfig {
return false;
}
+ @Override
+ public int size() {
+ return categories.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return categories.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return categories.contains(o);
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ return categories.containsAll(c);
+ }
+
+ @Override
+ public Iterator<TestCategory> iterator() {
+ return categories.iterator();
+ }
+
+ @Override
+ public Object[] toArray() {
+ return categories.toArray();
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ return categories.toArray(a);
+ }
+
+ @Override
+ public boolean add(TestCategory e) {
+ throw new UnsupportedOperationException("add"); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ throw new UnsupportedOperationException("remove"); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends TestCategory> c) {
+ throw new UnsupportedOperationException("addAll"); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ throw new UnsupportedOperationException("retainAll"); //$NON-NLS-1$
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ throw new UnsupportedOperationException("removeAll"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException("clear"); //$NON-NLS-1$
+ }
+
}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/AllTestsRunner.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/AllTestsRunner.java
new file mode 100644
index 00000000000..e0353d2da8e
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/AllTestsRunner.java
@@ -0,0 +1,111 @@
+/*****************************************************************************
+ * Copyright (c) 2010, 2015 CEA LIST, Christian W. Damus, 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bugs 402525, 323802, 431953, 433310, 434993
+ * Christian W. Damus - bug 399859
+ * Christian W. Damus - bug 451230
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.junit.framework.runner;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.junit.framework.classification.ClassificationConfig;
+import org.eclipse.papyrus.junit.framework.classification.TestCategory;
+import org.junit.runners.Suite;
+import org.junit.runners.model.FrameworkField;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.TestClass;
+
+/**
+ * Finds and runs tests.
+ */
+public class AllTestsRunner extends Suite {
+
+ /**
+ * Constructor.
+ *
+ * @param clazz
+ * the suite class � AllTests2
+ * @throws InitializationError
+ * if there's a problem
+ * @throws org.junit.runners.model.InitializationError
+ */
+ public AllTestsRunner(final Class<?> clazz) throws InitializationError {
+ super(clazz, getSuites(clazz));
+
+ for (String arg : Platform.getApplicationArgs()) {
+ if (arg.contains("-testConfig=")) {
+ String configName = arg.substring("-testConfig=".length());
+ Set<TestCategory> testsConfig = ClassificationConfig.valueOf(configName);
+ if (testsConfig != null) {
+ ClassificationConfig.setTestsConfiguration(testsConfig);
+ }
+ break;
+ }
+ }
+ }
+
+ /**
+ * Returns the list of test classes
+ *
+ * @return the list of test classes
+ */
+ static Class<?>[] getSuites(final Class<?> clazz) {
+ // retrieve all test suites.
+ final Collection<Class<?>> suites = new ArrayList<Class<?>>();
+
+ TestClass testClass = new TestClass(clazz);
+ List<ITestSuiteClass> suiteClassSpecs = new ArrayList<ITestSuiteClass>();
+ List<FrameworkField> suiteSpots = testClass.getAnnotatedFields(SuiteSpot.class);
+ for (FrameworkField spot : suiteSpots) {
+ if (spot.isStatic()) {
+ try {
+ Object value = spot.get(null);
+ Iterable<?> listValue;
+ if (value instanceof Object[]) {
+ listValue = Arrays.asList((Object[]) value);
+ } else if (value instanceof Iterable<?>) {
+ listValue = (Iterable<?>) value;
+ } else {
+ listValue = Collections.emptyList();
+ }
+ for (Object next : listValue) {
+ if (next instanceof ITestSuiteClass) {
+ suiteClassSpecs.add((ITestSuiteClass) next);
+ }
+ }
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ if (suiteClassSpecs.isEmpty()) {
+ System.err.println("No suite classes specified in class " + clazz.getName());
+ } else {
+ for (final ITestSuiteClass testSuiteClass : suiteClassSpecs) {
+ final Class<?> class_ = testSuiteClass.getMainTestSuiteClass();
+ if (class_ != null) {
+ suites.add(class_);
+ } else {
+ System.err.println(testSuiteClass + " does not give a correct test suite class");
+ }
+ }
+ }
+ return suites.toArray(new Class<?>[] {});
+ }
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/FragmentTestSuiteClass.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/FragmentTestSuiteClass.java
new file mode 100644
index 00000000000..f397b6c0038
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/FragmentTestSuiteClass.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2010, 2015 CEA LIST, Christian W. Damus, 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 451230
+ *****************************************************************************/
+package org.eclipse.papyrus.junit.framework.runner;
+
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+
+
+/**
+ * Test Suite class entry for a test fragment
+ */
+public class FragmentTestSuiteClass implements ITestSuiteClass {
+
+ /** unique identifier of the bundle host */
+ private final String hostBundleId;
+
+ /** qualified name of the test suite class */
+ private final String classQualifiedName;
+
+ /**
+ * Constructor.
+ *
+ * @param hostBundleId
+ * unique identifier of the bundle host
+ * @param classQualifiedName
+ * qualified name of the test suite class
+ */
+ public FragmentTestSuiteClass(String hostBundleId, String classQualifiedName) {
+ this.hostBundleId = hostBundleId;
+ this.classQualifiedName = classQualifiedName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Class<?> getMainTestSuiteClass() {
+ Bundle bundle = Platform.getBundle(hostBundleId);
+ if(bundle == null) {
+ System.err.println("Impossible to find bundle: " + hostBundleId);
+ } else {
+ try {
+ Class<?> class_ = bundle.loadClass(classQualifiedName);
+ return class_;
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("FragmentTestSuite %s/%s", hostBundleId, classQualifiedName);
+ }
+
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/ITestSuiteClass.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/ITestSuiteClass.java
new file mode 100644
index 00000000000..0f83845111a
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/ITestSuiteClass.java
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * Copyright (c) 2010, 2015 CEA LIST, Christian W. Damus, 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 451230
+ *****************************************************************************/
+package org.eclipse.papyrus.junit.framework.runner;
+
+
+/**
+ * Interface for all suite classes.
+ */
+public interface ITestSuiteClass {
+
+ /**
+ * Returns the main test suite class for this entry
+ *
+ * @return the main test suite class for this entry
+ */
+ public Class<?> getMainTestSuiteClass();
+
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/PluginTestSuiteClass.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/PluginTestSuiteClass.java
new file mode 100644
index 00000000000..e559a54d3cc
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/PluginTestSuiteClass.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2010, 2015 CEA LIST, Christian W. Damus, 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 451230
+ *****************************************************************************/
+package org.eclipse.papyrus.junit.framework.runner;
+
+
+/**
+ * Entry for a test suite in a test plugin
+ */
+public class PluginTestSuiteClass implements ITestSuiteClass {
+
+ /** main test suite class */
+ private final Class<?> testClass;
+
+ /**
+ * Constructor.
+ *
+ * @param testClass
+ * the main test suite class
+ */
+ public PluginTestSuiteClass(Class<?> testClass) {
+ this.testClass = testClass;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Class<?> getMainTestSuiteClass() {
+ return testClass;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("PluginTestSuite %s", testClass);
+ }
+
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/SuiteSpot.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/SuiteSpot.java
new file mode 100644
index 00000000000..a745af89a16
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.framework/src/org/eclipse/papyrus/junit/framework/runner/SuiteSpot.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.junit.framework.runner;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation on a static field of an all-tests suite class using the {@link AllTestsRunner} that
+ * provides a collection or array of {@link ITestSuiteClass}es to run.
+ */
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface SuiteSpot {
+ // Empty annotation
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.classpath b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.classpath
index 2d1a4302f04..098194ca4b7 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.classpath
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.classpath
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.settings/org.eclipse.jdt.core.prefs b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.settings/org.eclipse.jdt.core.prefs
index 4759947300a..9ca8e68231b 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.settings/org.eclipse.jdt.core.prefs
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/.settings/org.eclipse.jdt.core.prefs
@@ -1,10 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
index 687f52dd874..7df24de1376 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
@@ -35,5 +35,5 @@ Bundle-Name: %Bundle-Name
Bundle-ManifestVersion: 2
Bundle-Activator: org.eclipse.papyrus.junit.utils.Activator
Bundle-SymbolicName: org.eclipse.papyrus.junit.utils
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/pom.xml b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/pom.xml
index 19f8c23fc24..19a38f4b10a 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/pom.xml
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/pom.xml
@@ -12,4 +12,17 @@
<artifactId>org.eclipse.papyrus.junit.utils</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
+ <build>
+ <plugins>
+ <!-- Tell Tycho to use the JDT project settings for source and target compatibility instead of what the parent POM specifies. -->
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-compiler-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ <useProjectSettings>true</useProjectSettings>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java
index 6d87a16b113..fe1592fad4f 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/MoreMatchers.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 Christian W. Damus and others.
+ * Copyright (c) 2014, 2015 Christian W. Damus and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -41,6 +41,19 @@ public class MoreMatchers {
};
}
+ public static <N extends Number & Comparable<N>> Matcher<N> lessThan(final N maximum) {
+ return new BaseMatcher<N>() {
+ public void describeTo(Description description) {
+ description.appendText("less than ").appendValue(maximum);
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matches(Object item) {
+ return ((N) item).compareTo(maximum) < 0;
+ }
+ };
+ }
+
public static Matcher<Iterable<?>> isEmpty() {
return new BaseMatcher<Iterable<?>>() {
public void describeTo(Description description) {
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/JUnitUtils.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/JUnitUtils.java
new file mode 100644
index 00000000000..17bfadc190c
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/JUnitUtils.java
@@ -0,0 +1,116 @@
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.junit.utils;
+
+import java.lang.annotation.Annotation;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+
+/**
+ * Utilities for working with the JUnit data model.
+ */
+public class JUnitUtils {
+
+ /**
+ * Not instantiable by clients.
+ */
+ private JUnitUtils() {
+ super();
+ }
+
+ /**
+ * Obtains the test class implied by a {@code description} that is supplied to a {@link TestRule}.
+ *
+ * @param description
+ * a rule's owning description, which generally would be a test method or a test class
+ * (as these are the contexts in which rules are invoked)
+ *
+ * @return the test class, or {@code null} in the unlikely event that none can be found
+ */
+ public static Class<?> getTestClass(Description description) {
+ Class<?> result = description.getTestClass();
+
+ if (result == null) {
+ for (Description child : description.getChildren()) {
+ result = getTestClass(child);
+ if (result != null) {
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Obtains the annotation of the specified {@code type} applicable to a {@code description} that is supplied to a {@link TestRule}.
+ * If the description is for a test method, then if that method doesn't have the requested annotation, its owning class is searched
+ * for the annotation.
+ *
+ * @param description
+ * a rule's owning description, which generally would be a test method or a test class
+ * (as these are the contexts in which rules are invoked)
+ * @param type
+ * the annotation type to look for
+ *
+ * @return the requested annotation, or {@code null} if none was found
+ */
+ public static <A extends Annotation> A getAnnotation(Description description, Class<A> type) {
+ A result = description.getAnnotation(type);
+
+ if ((result == null) && (description.getTestClass() != null)) {
+ result = description.getTestClass().getAnnotation(type);
+ }
+
+ return result;
+ }
+
+ /**
+ * Obtains the annotation of any one of the specified {@code types} applicable to a {@code description} that is supplied to a {@link TestRule}.
+ * If the description is for a test method, then if that method doesn't have any of the requested annotations, its owning class is searched
+ * for the annotations.
+ *
+ * @param description
+ * a rule's owning description, which generally would be a test method or a test class
+ * (as these are the contexts in which rules are invoked)
+ * @param types
+ * the annotation types to look for
+ *
+ * @return the first available of the requested annotations, or {@code null} if none was found
+ */
+ @SafeVarargs
+ public static Annotation getAnyAnnotation(Description description, final Class<? extends Annotation>... types) {
+ Annotation result = null;
+
+ for (Class<? extends Annotation> next : types) {
+ result = description.getAnnotation(next);
+ if (result != null) {
+ break;
+ }
+ }
+
+ if ((result == null) && (description.getTestClass() != null)) {
+ Class<?> testClass = description.getTestClass();
+ for (Class<? extends Annotation> next : types) {
+ result = testClass.getAnnotation(next);
+ if (result != null) {
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractModelFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractModelFixture.java
index dd5fc65b021..fcde2341388 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractModelFixture.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/AbstractModelFixture.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 CEA, Christian W. Damus, and others.
+ * Copyright (c) 2014, 2015 CEA, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,6 +9,7 @@
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
* Christian W. Damus - bug 399859
+ * Christian W. Damus - bug 451230
*
*/
package org.eclipse.papyrus.junit.utils.rules;
@@ -21,7 +22,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
@@ -49,6 +49,7 @@ import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
+import org.eclipse.papyrus.junit.utils.JUnitUtils;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Profile;
@@ -105,7 +106,7 @@ public abstract class AbstractModelFixture<T extends EditingDomain> extends Test
@Override
public Statement apply(Statement base, Description description) {
- testClass = description.getTestClass();
+ testClass = JUnitUtils.getTestClass(description);
// Wrap myself in the project rule so that the project exists when I start
Statement result = super.apply(base, description);
@@ -450,30 +451,7 @@ public abstract class AbstractModelFixture<T extends EditingDomain> extends Test
}
private Annotation getResourceAnnotation(Description description) {
- Annotation result = null;
-
- Class<?> testClass = description.getTestClass();
-
- Method testMethod = null;
- try {
- testMethod = testClass.getDeclaredMethod(description.getMethodName());
- } catch (Exception e) {
- e.printStackTrace();
- fail("Could not access test method via JUnit framework.");
- }
-
- if (testMethod.isAnnotationPresent(JavaResource.class)) {
- result = testMethod.getAnnotation(JavaResource.class);
- } else if (testMethod.isAnnotationPresent(PluginResource.class)) {
- result = testMethod.getAnnotation(PluginResource.class);
- } else {
- // The class must have an annotation
- if (testClass.isAnnotationPresent(JavaResource.class)) {
- result = testClass.getAnnotation(JavaResource.class);
- } else if (testClass.isAnnotationPresent(PluginResource.class)) {
- result = testClass.getAnnotation(PluginResource.class);
- }
- }
+ Annotation result = JUnitUtils.getAnyAnnotation(description, JavaResource.class, PluginResource.class);
assertThat("No JavaResource or PluginResource annotation found on test.", result, notNullValue());
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java
index 1cdd9f45c72..9d10afe09f5 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 CEA and others.
+ * Copyright (c) 2014, 2015 CEA, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
+ * Christian W. Damus - bug 451230
*
*/
package org.eclipse.papyrus.junit.utils.rules;
@@ -60,12 +61,22 @@ public class ProjectFixture implements TestRule {
return !uri.isPlatformResource() ? null : project.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
}
- public Statement apply(final Statement base, final Description description) {
+ public Statement apply(final Statement base, Description description) {
+ String name = description.getMethodName();
+ if (name == null) {
+ // We are used as a class rule, then
+ name = description.getClassName();
+ if (name != null) {
+ name = name.substring(name.lastIndexOf('.') + 1);
+ }
+ }
+
+ final String projectName = name;
return new Statement() {
@Override
public void evaluate() throws Throwable {
- createProject(description.getMethodName());
+ createProject(projectName);
try {
base.evaluate();
@@ -79,16 +90,16 @@ public class ProjectFixture implements TestRule {
protected void createProject(String name) throws CoreException {
project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
- if(project.exists()) {
+ if (project.exists()) {
// Start clean, if we can
deleteProject();
}
- if(!project.exists()) {
+ if (!project.exists()) {
project.create(null);
}
- if(!project.isOpen()) {
+ if (!project.isOpen()) {
project.open(null);
}
@@ -103,7 +114,7 @@ public class ProjectFixture implements TestRule {
project.accept(new IResourceVisitor() {
public boolean visit(IResource resource) throws CoreException {
- switch(resource.getType()) {
+ switch (resource.getType()) {
case IResource.FILE:
case IResource.FOLDER:
ensureWritable(resource);
@@ -117,13 +128,13 @@ public class ProjectFixture implements TestRule {
project.delete(true, null);
} catch (CoreException e) {
e.printStackTrace();
- // leave the project. We may end up re-using it, who knows?
+ // leave the project. We may end up re-using it, who knows?
}
}
protected void ensureWritable(IResource resource) throws CoreException {
ResourceAttributes attr = resource.getResourceAttributes();
- if(attr.isReadOnly()) {
+ if (attr.isReadOnly()) {
attr.setReadOnly(false);
resource.setResourceAttributes(attr);
}
@@ -142,7 +153,7 @@ public class ProjectFixture implements TestRule {
assertThat("Cannot set non-workspace resource read-only", file, notNullValue());
setReadOnly(file);
}
-
+
public void setReadOnly(IResource resource) {
setReadOnly(resource, true);
}
@@ -150,7 +161,7 @@ public class ProjectFixture implements TestRule {
public void setReadOnly(IResource resource, boolean readOnly) {
ResourceAttributes attr = resource.getResourceAttributes();
- if(attr.isReadOnly() != readOnly) {
+ if (attr.isReadOnly() != readOnly) {
attr.setReadOnly(readOnly);
try {

Back to the top