From: Tuukka Lehtonen Date: Tue, 20 Dec 2016 12:41:08 +0000 (+0200) Subject: Merge changes Ib86a41bb,I4fed12d3 X-Git-Tag: v1.26.0~17 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=4bf8562ab7cbb3747f9c5844a07469291d43e905;hp=a8758de5bc19e5adb3f618d3038743a164f09912 Merge changes Ib86a41bb,I4fed12d3 * changes: Show modelled STS tests in model browser in execution order Run modelled STS tests in alphanumeric order --- diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg b/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg index 862131139..7935f8a67 100644 Binary files a/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg and b/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg differ diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph b/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph index b51213dc8..ecebcf8fa 100644 --- a/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph +++ b/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph @@ -33,6 +33,13 @@ MBC @VP.namedRelationChildRule TestsUI.Contributions.STSTests L0.Entity L0.ConsistsOf TESTS.STSTest @VP.namedConstantImageRule TestsUI.Contributions.TestImage TESTS.STSTest TestsUI.testImage +MBC + VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution + VP.VisualsContribution.HasNodeType TESTS.STSSuite + VP.VisualsContribution.HasRule MBC.STSSuiteSorterRule + +MBC.STSSuiteSorterRule : VP.SorterRule + MAC = TestsUI.ModelingActionContext : VP.BrowseContext VP.BrowseContext.IsIncludedIn PROJECT.ProjectActionContext diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java b/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java index 897d42c9d..752d44620 100644 --- a/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java +++ b/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java @@ -11,6 +11,7 @@ import org.simantics.db.service.QueryControl; public class TestsUIResource { public final Resource BrowseContext; + public final Resource BrowseContext_STSSuiteSorterRule; public final Resource Contributions; public final Resource Contributions_NewSTSSuite; public final Resource Contributions_NewSTSTest; @@ -29,6 +30,7 @@ public class TestsUIResource { public static class URIs { public static final String BrowseContext = "http://www.simantics.org/TestsUI-1.0/BrowseContext"; + public static final String BrowseContext_STSSuiteSorterRule = "http://www.simantics.org/TestsUI-1.0/BrowseContext/STSSuiteSorterRule"; public static final String Contributions = "http://www.simantics.org/TestsUI-1.0/Contributions"; public static final String Contributions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSSuite"; public static final String Contributions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSTest"; @@ -57,6 +59,7 @@ public class TestsUIResource { public TestsUIResource(ReadGraph graph) { BrowseContext = getResourceOrNull(graph, URIs.BrowseContext); + BrowseContext_STSSuiteSorterRule = getResourceOrNull(graph, URIs.BrowseContext_STSSuiteSorterRule); Contributions = getResourceOrNull(graph, URIs.Contributions); Contributions_NewSTSSuite = getResourceOrNull(graph, URIs.Contributions_NewSTSSuite); Contributions_NewSTSTest = getResourceOrNull(graph, URIs.Contributions_NewSTSTest); diff --git a/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF index 0e787d233..776eea39e 100644 --- a/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF @@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.ui, org.simantics.tests.modelled.ui.ontology;bundle-version="1.0.0", org.simantics.tests.modelled;bundle-version="1.0.0", org.eclipse.e4.ui.model.workbench, - org.simantics.scl.osgi + org.simantics.scl.osgi, + org.simantics.browsing.ui.model Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Bundle-Vendor: Semantum Oy diff --git a/bundles/org.simantics.tests.modelled.ui/adapters.xml b/bundles/org.simantics.tests.modelled.ui/adapters.xml new file mode 100644 index 000000000..d68f46686 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/adapters.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSSuiteSorterRule.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSSuiteSorterRule.java new file mode 100644 index 000000000..bdb55b6a2 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSSuiteSorterRule.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.tests.modelled.ui; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.model.browsecontexts.BrowseContext; +import org.simantics.browsing.ui.model.sorters.Sorter; +import org.simantics.browsing.ui.model.sorters.SorterRule; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.RuntimeDatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.tests.modelled.ontology.TestsResource; +import org.simantics.utils.datastructures.Pair; +import org.simantics.utils.strings.AlphanumComparator; + +public class STSSuiteSorterRule implements SorterRule, Sorter { + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Sorter getSorter(ReadGraph graph, Object content) throws DatabaseException { + return this; + } + + @Override + public void sort(ReadGraph graph, BrowseContext context, List nodes) throws DatabaseException + { + try { + STSTestComparator stc = new STSTestComparator(); + stc.graph = graph; + Collections.sort(nodes, stc); + } catch (RuntimeDatabaseException e) { + if (e.getCause()!=null && e.getCause() instanceof DatabaseException) throw (DatabaseException) e.getCause(); + throw e; + } + } + + static class STSTestQuery extends ResourceRead> { + + public STSTestQuery(Resource resource) { + super(resource); + } + + @Override + public Pair perform(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + TestsResource TESTS = TestsResource.getInstance(graph); + + String name = graph.getRelatedValue2(resource, L0.HasName, Bindings.STRING); + Integer priority = graph.getRelatedValue2(resource, TESTS.STSTest_executionPriority, Bindings.INTEGER); + + return new Pair(priority, name); + } + + } + + static class STSTestComparator implements Comparator { + ReadGraph graph; + + @Override + public int compare(NodeContext nc1, NodeContext nc2) { + Resource r1 = (Resource) nc1.getConstant(BuiltinKeys.INPUT); + Resource r2 = (Resource) nc2.getConstant(BuiltinKeys.INPUT); + + try { + Pair test1 = graph.sync(new STSTestQuery(r1)); + Pair test2 = graph.sync(new STSTestQuery(r2)); + + if (test1.first < test2.first) + return -1; + else if (test1.first > test2.first) + return 1; + else return AlphanumComparator.COMPARATOR.compare(test1.second, test2.second); + + } catch (DatabaseException e) { + throw new RuntimeDatabaseException(e); + } + } + } +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java index 188574e54..ad1e29531 100644 --- a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java @@ -30,6 +30,7 @@ import org.simantics.scl.compiler.runtime.RuntimeModule; import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler; import org.simantics.tests.modelled.ontology.TestsResource; +import org.simantics.utils.strings.AlphanumComparator; public class STSTestSuiteModel { @@ -435,9 +436,9 @@ public class STSTestSuiteModel { Collections.sort(tests, (o1, o2) -> { if (o1.priority < o2.priority) return -1; - if (o1.priority > o2.priority) + else if (o1.priority > o2.priority) return 1; - return 0; + else return AlphanumComparator.COMPARATOR.compare(o1.name, o2.name); }); suite.children(tests.toArray(new STSTest[tests.size()])); } else { diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java index c0a5ac342..a86aa41d3 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java @@ -63,6 +63,10 @@ public class RuntimeSTSTestRunner extends Runner { } } + public String getName() { + return name; + } + public Integer getPriority() { return priority; } 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..0ab31b3f0 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 @@ -18,6 +18,7 @@ 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; public class RuntimeTestCollector { @@ -60,10 +61,11 @@ public class RuntimeTestCollector { } testRunners.sort((test1, test2) -> { - if (test1.getPriority() <= test2.getPriority()) + if (test1.getPriority() < test2.getPriority()) return -1; - else + else if (test1.getPriority() > test2.getPriority()) return 1; + else return AlphanumComparator.COMPARATOR.compare(test1.getName(), test2.getName()); }); suite.addChildren(testRunners); suites.add(suite);