X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2FRuntimeTestCollector.java;fp=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2FRuntimeTestCollector.java;h=81d1ef7e7f52d7a961df8c53a2918f6b332e7382;hb=53059ca1a958697cc6235d27628614fbaa944d59;hp=0000000000000000000000000000000000000000;hpb=e87f0965679502de281692c298d66a7ae9507bd8;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeTestCollector.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeTestCollector.java new file mode 100644 index 000000000..81d1ef7e7 --- /dev/null +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeTestCollector.java @@ -0,0 +1,89 @@ +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.junit.runner.Runner; +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; + +public class RuntimeTestCollector { + + + /** + * 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 collectTestsFromGraph() { + try { + Collection suitess = Simantics.getSession().syncRequest(new UniqueRead>() { + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + + List sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE); + + Set suites = new HashSet<>(); + TestsResource TESTS = TestsResource.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + for (Resource sharedOntology : sharedOntologies) { + List stsSuites = ModelingUtils.searchByType(graph, sharedOntology, TESTS.STSSuite); + for (Resource stsSuite : stsSuites) { + try { + String suiteName = graph.getURI(stsSuite); + + Collection tests = graph.syncRequest(new ObjectsWithType(stsSuite, L0.ConsistsOf, TESTS.STSTest)); + if (tests.isEmpty()) + continue; + + RuntimeSTSSuiteRunner suite = new RuntimeSTSSuiteRunner(suiteName); + List 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 + return 1; + }); + 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 collectTests() { + return new ArrayList<>(collectTestsFromGraph()); + } +}