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.simantics.Simantics;
\r
11 import org.simantics.databoard.Bindings;
\r
12 import org.simantics.db.ReadGraph;
\r
13 import org.simantics.db.Resource;
\r
14 import org.simantics.db.common.request.ObjectsWithType;
\r
15 import org.simantics.db.common.request.UniqueRead;
\r
16 import org.simantics.db.exception.DatabaseException;
\r
17 import org.simantics.layer0.Layer0;
\r
18 import org.simantics.modeling.ModelingUtils;
\r
19 import org.simantics.scl.runtime.tuple.Tuple0;
\r
20 import org.simantics.tests.modelled.ontology.TestsResource;
\r
22 public class RuntimeTestCollector {
\r
26 * TODO: The idea of this class was to collect all the tests from shared libraries and construct
\r
27 * JUnit tests out of them programmatically and then run them with JUnit to get results
\r
30 private static Collection<RuntimeSTSSuiteRunner> collectTestsFromGraph() {
\r
32 Collection<RuntimeSTSSuiteRunner> suitess = Simantics.getSession().syncRequest(new UniqueRead<Collection<RuntimeSTSSuiteRunner>>() {
\r
35 public Collection<RuntimeSTSSuiteRunner> perform(ReadGraph graph) throws DatabaseException {
\r
37 List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
\r
39 Set<RuntimeSTSSuiteRunner> suites = new HashSet<>();
\r
40 TestsResource TESTS = TestsResource.getInstance(graph);
\r
41 Layer0 L0 = Layer0.getInstance(graph);
\r
42 for (Resource sharedOntology : sharedOntologies) {
\r
43 List<Resource> stsSuites = ModelingUtils.searchByType(graph, sharedOntology, TESTS.STSSuite);
\r
44 for (Resource stsSuite : stsSuites) {
\r
46 String suiteName = graph.getURI(stsSuite);
\r
48 Collection<Resource> tests = graph.syncRequest(new ObjectsWithType(stsSuite, L0.ConsistsOf, TESTS.STSTest));
\r
49 if (tests.isEmpty())
\r
52 RuntimeSTSSuiteRunner suite = new RuntimeSTSSuiteRunner(RuntimeSTSSuiteRunner.class, suiteName);
\r
53 List<RuntimeSTSTestRunner> testRunners = new ArrayList<>();
\r
54 for (Resource test : tests) {
\r
55 String testName = graph.getRelatedValue(test, L0.HasName, Bindings.STRING);
\r
56 String code = graph.getRelatedValue(test, TESTS.STSTest_definition, Bindings.STRING);
\r
57 Integer priority = graph.getPossibleRelatedValue(test, TESTS.STSTest_executionPriority, Bindings.INTEGER);
\r
58 RuntimeSTSTestRunner testCase = new RuntimeSTSTestRunner(testName, code, priority);
\r
59 testRunners.add(testCase);
\r
62 testRunners.sort((test1, test2) -> {
\r
63 if (test1.getPriority() <= test2.getPriority())
\r
68 suite.addChildren(testRunners);
\r
70 } catch (Exception e) {
\r
71 e.printStackTrace();
\r
79 } catch (DatabaseException e) {
\r
80 e.printStackTrace();
\r
81 return Collections.emptyList();
\r
85 public static List<RuntimeSTSSuiteRunner> collectTests() {
\r
86 return new ArrayList<>(collectTestsFromGraph());
\r