1 package org.simantics.tests.modelled.junit;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Collection;
\r
5 import java.util.Collections;
\r
6 import java.util.HashSet;
\r
7 import java.util.List;
\r
8 import java.util.Set;
\r
10 import org.junit.runner.Runner;
\r
11 import org.simantics.Simantics;
\r
12 import org.simantics.databoard.Bindings;
\r
13 import org.simantics.db.ReadGraph;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.common.request.ObjectsWithType;
\r
16 import org.simantics.db.common.request.UniqueRead;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
18 import org.simantics.layer0.Layer0;
\r
19 import org.simantics.modeling.ModelingUtils;
\r
20 import org.simantics.scl.runtime.tuple.Tuple0;
\r
21 import org.simantics.tests.modelled.ontology.TestsResource;
\r
23 public class RuntimeTestCollector {
\r
27 * TODO: The idea of this class was to collect all the tests from shared libraries and construct
\r
28 * JUnit tests out of them programmatically and then run them with JUnit to get results
\r
31 private static Collection<RuntimeSTSSuiteRunner> collectTestsFromGraph() {
\r
33 Collection<RuntimeSTSSuiteRunner> suitess = Simantics.getSession().syncRequest(new UniqueRead<Collection<RuntimeSTSSuiteRunner>>() {
\r
36 public Collection<RuntimeSTSSuiteRunner> perform(ReadGraph graph) throws DatabaseException {
\r
38 List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
\r
40 Set<RuntimeSTSSuiteRunner> suites = new HashSet<>();
\r
41 TestsResource TESTS = TestsResource.getInstance(graph);
\r
42 Layer0 L0 = Layer0.getInstance(graph);
\r
43 for (Resource sharedOntology : sharedOntologies) {
\r
44 List<Resource> stsSuites = ModelingUtils.searchByType(graph, sharedOntology, TESTS.STSSuite);
\r
45 for (Resource stsSuite : stsSuites) {
\r
47 String suiteName = graph.getURI(stsSuite);
\r
49 Collection<Resource> tests = graph.syncRequest(new ObjectsWithType(stsSuite, L0.ConsistsOf, TESTS.STSTest));
\r
50 if (tests.isEmpty())
\r
53 RuntimeSTSSuiteRunner suite = new RuntimeSTSSuiteRunner(suiteName);
\r
54 List<RuntimeSTSTestRunner> testRunners = new ArrayList<>();
\r
55 for (Resource test : tests) {
\r
56 String testName = graph.getRelatedValue(test, L0.HasName, Bindings.STRING);
\r
57 String code = graph.getRelatedValue(test, TESTS.STSTest_definition, Bindings.STRING);
\r
58 Integer priority = graph.getPossibleRelatedValue(test, TESTS.STSTest_executionPriority, Bindings.INTEGER);
\r
59 RuntimeSTSTestRunner testCase = new RuntimeSTSTestRunner(testName, code, priority);
\r
60 testRunners.add(testCase);
\r
63 testRunners.sort((test1, test2) -> {
\r
64 if (test1.getPriority() <= test2.getPriority())
\r
69 suite.addChildren(testRunners);
\r
71 } catch (Exception e) {
\r
72 e.printStackTrace();
\r
80 } catch (DatabaseException e) {
\r
81 e.printStackTrace();
\r
82 return Collections.emptyList();
\r
86 public static List<Runner> collectTests() {
\r
87 return new ArrayList<>(collectTestsFromGraph());
\r