-package org.simantics.tests.modelled.junit;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.simantics.Simantics;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ModelingUtils;\r
-import org.simantics.scl.runtime.tuple.Tuple0;\r
-import org.simantics.tests.modelled.ontology.TestsResource;\r
-import org.simantics.utils.strings.AlphanumComparator;\r
-\r
-public class RuntimeTestCollector {\r
-\r
- \r
- /**\r
- * TODO: The idea of this class was to collect all the tests from shared libraries and construct\r
- * JUnit tests out of them programmatically and then run them with JUnit to get results\r
- * \r
- */\r
- private static Collection<RuntimeSTSSuiteRunner> collectTestsFromGraph() {\r
- try {\r
- Collection<RuntimeSTSSuiteRunner> suitess = Simantics.getSession().syncRequest(new UniqueRead<Collection<RuntimeSTSSuiteRunner>>() {\r
-\r
- @Override\r
- public Collection<RuntimeSTSSuiteRunner> perform(ReadGraph graph) throws DatabaseException {\r
- \r
- List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);\r
-\r
- Set<RuntimeSTSSuiteRunner> suites = new HashSet<>();\r
- TestsResource TESTS = TestsResource.getInstance(graph);\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- for (Resource sharedOntology : sharedOntologies) {\r
- List<Resource> stsSuites = ModelingUtils.searchByType(graph, sharedOntology, TESTS.STSSuite);\r
- for (Resource stsSuite : stsSuites) {\r
- try {\r
- String suiteName = graph.getURI(stsSuite);\r
- \r
- Collection<Resource> tests = graph.syncRequest(new ObjectsWithType(stsSuite, L0.ConsistsOf, TESTS.STSTest));\r
- if (tests.isEmpty())\r
- continue;\r
- \r
- RuntimeSTSSuiteRunner suite = new RuntimeSTSSuiteRunner(RuntimeSTSSuiteRunner.class, suiteName);\r
- List<RuntimeSTSTestRunner> testRunners = new ArrayList<>();\r
- for (Resource test : tests) {\r
- String testName = graph.getRelatedValue(test, L0.HasName, Bindings.STRING);\r
- String code = graph.getRelatedValue(test, TESTS.STSTest_definition, Bindings.STRING);\r
- Integer priority = graph.getPossibleRelatedValue(test, TESTS.STSTest_executionPriority, Bindings.INTEGER);\r
- RuntimeSTSTestRunner testCase = new RuntimeSTSTestRunner(testName, code, priority);\r
- testRunners.add(testCase);\r
- }\r
- \r
- testRunners.sort((test1, test2) -> {\r
- if (test1.getPriority() < test2.getPriority())\r
- return -1;\r
- else if (test1.getPriority() > test2.getPriority())\r
- return 1;\r
- else return AlphanumComparator.COMPARATOR.compare(test1.getName(), test2.getName());\r
- });\r
- suite.addChildren(testRunners);\r
- suites.add(suite);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
- return suites;\r
- }\r
- });\r
- return suitess;\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- return Collections.emptyList();\r
- }\r
- }\r
-\r
- public static List<RuntimeSTSSuiteRunner> collectTests() {\r
- return new ArrayList<>(collectTestsFromGraph());\r
- }\r
-}\r
+package org.simantics.tests.modelled.junit;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingUtils;
+import org.simantics.scl.runtime.tuple.Tuple0;
+import org.simantics.tests.modelled.ontology.TestsResource;
+import org.simantics.utils.strings.AlphanumComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Deprecated
+public class RuntimeTestCollector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeTestCollector.class);
+
+ /**
+ * TODO: The idea of this class was to collect all the tests from shared libraries and construct
+ * JUnit tests out of them programmatically and then run them with JUnit to get results
+ *
+ */
+ private static Collection<RuntimeSTSSuiteRunner> collectTestsFromGraph() {
+ try {
+ Collection<RuntimeSTSSuiteRunner> suitess = Simantics.getSession().syncRequest(new UniqueRead<Collection<RuntimeSTSSuiteRunner>>() {
+
+ @Override
+ public Collection<RuntimeSTSSuiteRunner> perform(ReadGraph graph) throws DatabaseException {
+
+ List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+ if (LOGGER.isInfoEnabled())
+ LOGGER.info("Found {} shared ontologies from graph", sharedOntologies.size());
+ Set<RuntimeSTSSuiteRunner> suites = new HashSet<>();
+ TestsResource TESTS = TestsResource.getInstance(graph);
+ Layer0 L0 = Layer0.getInstance(graph);
+ for (Resource sharedOntology : sharedOntologies) {
+ if (LOGGER.isInfoEnabled())
+ LOGGER.info("Searching {} for modelled tests", graph.getURI(sharedOntology));
+ List<Resource> stsSuites = ModelingUtils.searchByType(graph, sharedOntology, TESTS.STSSuite);
+ for (Resource stsSuite : stsSuites) {
+ try {
+ String suiteName = graph.getURI(stsSuite);
+
+ Collection<Resource> tests = graph.syncRequest(new ObjectsWithType(stsSuite, L0.ConsistsOf, TESTS.STSTest));
+ if (tests.isEmpty())
+ continue;
+
+ RuntimeSTSSuiteRunner suite = new RuntimeSTSSuiteRunner(RuntimeSTSSuiteRunner.class, suiteName);
+ List<RuntimeSTSTestRunner> testRunners = new ArrayList<>();
+ for (Resource test : tests) {
+ String testName = graph.getRelatedValue(test, L0.HasName, Bindings.STRING);
+ String code = graph.getRelatedValue(test, TESTS.STSTest_definition, Bindings.STRING);
+ Integer priority = graph.getPossibleRelatedValue(test, TESTS.STSTest_executionPriority, Bindings.INTEGER);
+ RuntimeSTSTestRunner testCase = new RuntimeSTSTestRunner(testName, code, priority);
+ testRunners.add(testCase);
+ }
+
+ testRunners.sort((test1, test2) -> {
+ if (test1.getPriority() < test2.getPriority())
+ return -1;
+ else if (test1.getPriority() > test2.getPriority())
+ return 1;
+ else return AlphanumComparator.COMPARATOR.compare(test1.getName(), test2.getName());
+ });
+ suite.addChildren(testRunners);
+ suites.add(suite);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return suites;
+ }
+ });
+ return suitess;
+ } catch (DatabaseException e) {
+ e.printStackTrace();
+ return Collections.emptyList();
+ }
+ }
+
+ public static List<RuntimeSTSSuiteRunner> collectTests() {
+ return new ArrayList<>(collectTestsFromGraph());
+ }
+}