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.layer0.util.Layer0Utils;
17 import org.simantics.db.testing.common.AcornTests;
18 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
19 import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
25 private static final Logger LOGGER = LoggerFactory.getLogger(ModelledSTSRunner.class);
27 public static final String INCLUSION_FILTER = "org.simantics.tests.modelled.singleTestIncludeFilter";
28 public static final String EXCLUSION_FILTER = "org.simantics.tests.modelled.excludeFilter";
30 private final List<ModelledSTSSuiteRunner> children;
32 public ModelledSTSRunner(Class<?> testClass) throws InitializationError {
37 Collection<ModelledSTSSuite> suites = STSSuiteTestCollector.collectTests();
40 String exclusionFilter = System.getProperty(EXCLUSION_FILTER);
41 Collection<ModelledSTSSuite> filtered;
42 if (exclusionFilter != null) {
43 String[] filters = exclusionFilter.split(",");
44 filtered = suites.stream().filter(s -> !startsWithAny(s, filters)).collect(Collectors.toList());
49 // String inclusionFilter = System.getProperty(INCLUSION_FILTER);
50 // Collection<ModelledSTSSuite> included;
51 // if (inclusionFilter != null) {
52 // String[] filters = inclusionFilter.split(",");
53 // included = filtered.stream().filter(s -> startsWithAny(s, filters)).collect(Collectors.toList());
55 // included = filtered;
59 // List<ModelledSTSSuite> sorted = included.stream().sorted((o1, o2) -> Integer.compare(o1.getPriority(), o2.getPriority())).collect(Collectors.toList());
60 List<ModelledSTSSuite> sorted = filtered.stream().sorted((o1, o2) -> Integer.compare(o1.getPriority(), o2.getPriority())).collect(Collectors.toList());
63 children = new ArrayList<>(sorted.size());
64 for (ModelledSTSSuite suite : sorted) {
65 children.add(new ModelledSTSSuiteRunner(suite));
67 } catch (Exception e) {
68 throw new InitializationError(e);
72 private static boolean startsWithAny(ModelledSTSSuite suite, String[] filters) {
73 for (String filter : filters) {
74 if (suite.getName().contains(filter)) {
82 protected List<ModelledSTSSuiteRunner> getChildren() {
87 protected Description describeChild(ModelledSTSSuiteRunner child) {
88 return child.getDescription();
92 public void run(RunNotifier notifier) {
93 notifier.addListener(new RunListener() {
96 public void testRunFinished(Result result) throws Exception {
104 protected void runChild(ModelledSTSSuiteRunner child, RunNotifier notifier) {
109 Layer0Utils.queryDebugSupport("QueryControl.flush");
111 // TODO: Add coverage reporting to ModelledSTSRunner
112 // CombinedCoverage cover = child.getCoverage();
113 // CoverageBuilder b = new CoverageBuilder();
116 public void initialize() throws InitializationError {
119 public void deinitialize() throws Exception {
122 private void initialize0() throws Exception {
123 AcornTests.newSimanticsWorkspace(null, null);
124 org.simantics.debug.browser.internal.Activator.getDefault().startDebugServer();
128 private void deinitialize0() throws Exception {
130 org.simantics.debug.browser.internal.Activator.getDefault().stopDebugServer();
131 Simantics.shutdown(new NullProgressMonitor());