1 package org.simantics.tests.modelled.junit.v2;
3 import java.util.ArrayList;
4 import java.util.Collection;
6 import java.util.stream.Collectors;
8 import org.eclipse.core.runtime.NullProgressMonitor;
9 import org.junit.runner.Description;
10 import org.junit.runner.Result;
11 import org.junit.runner.notification.RunListener;
12 import org.junit.runner.notification.RunNotifier;
13 import org.junit.runners.ParentRunner;
14 import org.junit.runners.model.InitializationError;
15 import org.simantics.Simantics;
16 import org.simantics.db.testing.common.AcornTests;
17 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
18 import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
20 public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
22 public static final String INCLUSION_FILTER = "org.simantics.tests.modelled.singleTestIncludeFilter";
23 public static final String EXCLUSION_FILTER = "org.simantics.tests.modelled.excludeFilter";
25 private final List<ModelledSTSSuiteRunner> children;
27 public ModelledSTSRunner(Class<?> testClass) throws InitializationError {
31 Collection<ModelledSTSSuite> suites = STSSuiteTestCollector.collectTests();
34 String exclusionFilter = System.getProperty(EXCLUSION_FILTER);
35 Collection<ModelledSTSSuite> filtered;
36 if (exclusionFilter != null) {
37 String[] filters = exclusionFilter.split(",");
38 filtered = suites.stream().filter(s -> !startsWithAny(s, filters)).collect(Collectors.toList());
43 // String inclusionFilter = System.getProperty(INCLUSION_FILTER);
44 // Collection<ModelledSTSSuite> included;
45 // if (inclusionFilter != null) {
46 // String[] filters = inclusionFilter.split(",");
47 // included = filtered.stream().filter(s -> startsWithAny(s, filters)).collect(Collectors.toList());
49 // included = filtered;
53 // List<ModelledSTSSuite> sorted = included.stream().sorted((o1, o2) -> Integer.compare(o1.getPriority(), o2.getPriority())).collect(Collectors.toList());
54 List<ModelledSTSSuite> sorted = filtered.stream().sorted((o1, o2) -> Integer.compare(o1.getPriority(), o2.getPriority())).collect(Collectors.toList());
57 children = new ArrayList<>(sorted.size());
58 for (ModelledSTSSuite suite : sorted) {
59 children.add(new ModelledSTSSuiteRunner(suite));
61 } catch (Exception e) {
62 throw new InitializationError(e);
66 private static boolean startsWithAny(ModelledSTSSuite suite, String[] filters) {
67 for (String filter : filters) {
68 if (suite.getName().contains(filter)) {
76 protected List<ModelledSTSSuiteRunner> getChildren() {
81 protected Description describeChild(ModelledSTSSuiteRunner child) {
82 return child.getDescription();
86 public void run(RunNotifier notifier) {
87 notifier.addListener(new RunListener() {
90 public void testRunFinished(Result result) throws Exception {
98 protected void runChild(ModelledSTSSuiteRunner child, RunNotifier notifier) {
100 // TODO: Add coverage reporting to ModelledSTSRunner
101 // CombinedCoverage cover = child.getCoverage();
102 // CoverageBuilder b = new CoverageBuilder();
105 public void initialize() throws InitializationError {
108 public void deinitialize() throws Exception {
111 private void initialize0() throws Exception {
112 AcornTests.newSimanticsWorkspace(null, null);
113 org.simantics.debug.browser.internal.Activator.getDefault().startDebugServer();
117 private void deinitialize0() throws Exception {
119 org.simantics.debug.browser.internal.Activator.getDefault().stopDebugServer();
120 Simantics.shutdown(new NullProgressMonitor());