]> gerrit.simantics Code Review - simantics/platform.git/blob
c74f6efaea0fb0485f377177eba45ecfe26191d2
[simantics/platform.git] /
1 package org.simantics.tests.modelled.junit.v2;
2
3 import java.util.List;
4 import java.util.stream.Collectors;
5
6 import org.eclipse.core.runtime.NullProgressMonitor;
7 import org.junit.runner.Description;
8 import org.junit.runner.Result;
9 import org.junit.runner.notification.RunListener;
10 import org.junit.runner.notification.RunNotifier;
11 import org.junit.runners.ParentRunner;
12 import org.junit.runners.model.InitializationError;
13 import org.simantics.Simantics;
14 import org.simantics.db.testing.common.AcornTests;
15 import org.simantics.scl.compiler.commands.CommandSession;
16 import org.simantics.scl.osgi.SCLOsgi;
17 import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
18
19 public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
20
21     private CommandSession commandSession;
22
23     public ModelledSTSRunner(Class<?> testClass) throws Exception {
24         super(testClass);
25         initialize0();
26     }
27
28     @Override
29     protected List<ModelledSTSSuiteRunner> getChildren() {
30         return STSSuiteTestCollector.collectTests().stream().map(suite -> {
31             try {
32                 return new ModelledSTSSuiteRunner(suite);
33             } catch (Exception e) {
34                 throw new RuntimeException(e);
35             }
36         }).collect(Collectors.toList());
37     }
38
39     @Override
40     protected Description describeChild(ModelledSTSSuiteRunner child) {
41         return child.getDescription();
42     }
43
44     @Override
45     public void run(RunNotifier notifier) {
46         notifier.addListener(new RunListener() {
47
48             @Override
49             public void testRunFinished(Result result) throws Exception {
50                 deinitialize0();
51             }
52         });
53         super.run(notifier);
54     }
55
56     @Override
57     protected void runChild(ModelledSTSSuiteRunner child, RunNotifier notifier) {
58         child.setCommandSesssion(commandSession);
59         child.run(notifier);
60         // TODO: Add coverage reporting to ModelledSTSRunner
61 //        CombinedCoverage cover = child.getCoverage();
62 //        CoverageBuilder b = new CoverageBuilder();
63     }
64
65     public void initialize() throws InitializationError {
66     }
67
68     public void deinitialize() throws Exception {
69     }
70
71     private void initialize0() throws Exception {
72         AcornTests.newSimanticsWorkspace(null, null);
73         this.commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
74         initialize();
75     }
76
77     private void deinitialize0() throws Exception {
78         deinitialize();
79         Simantics.shutdown(new NullProgressMonitor());
80     }
81 }