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;h=733cea952025c0ad2122dbf4621f25891d77a85d;hb=refs%2Fchanges%2F13%2F513%2F3;hp=06b81687ec025f1cc17a1bbf5cbb0dbf8155589f;hpb=ada4db363b15212dbfa34953b03b2d9dbaafa8c6;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 index 06b81687e..733cea952 100644 --- 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 @@ -1,88 +1,97 @@ -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; - -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(RuntimeSTSSuiteRunner.class, 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()); - } -} +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 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); + if (LOGGER.isInfoEnabled()) + LOGGER.info("Found {} shared ontologies from graph", sharedOntologies.size()); + Set 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 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(RuntimeSTSSuiteRunner.class, 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 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 collectTests() { + return new ArrayList<>(collectTestsFromGraph()); + } +}