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