]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge changes Ib86a41bb,I4fed12d3
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 20 Dec 2016 12:41:08 +0000 (14:41 +0200)
committerGerrit Code Review <gerrit2@www.simantics.org>
Tue, 20 Dec 2016 12:41:08 +0000 (14:41 +0200)
* changes:
  Show modelled STS tests in model browser in execution order
  Run modelled STS tests in alphanumeric order

bundles/org.simantics.tests.modelled.ui.ontology/graph.tg
bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph
bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java
bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF
bundles/org.simantics.tests.modelled.ui/adapters.xml [new file with mode: 0644]
bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSSuiteSorterRule.java [new file with mode: 0644]
bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeTestCollector.java

index 862131139dfd500072221ac32ba7b194cd28064c..7935f8a67dbcc34681cf0040100c7ae759666b6d 100644 (file)
Binary files a/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg and b/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg differ
index b51213dc8475a00c1eab2cc62bb09d9245948367..ecebcf8fa3d5524a25146fded17dd874ef9b4750 100644 (file)
@@ -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
 
index 897d42c9dbc9198c6f5de7299a195a058ba6494d..752d4462015702f9e0b9def89dffb3788306bc89 100644 (file)
@@ -11,6 +11,7 @@ import org.simantics.db.service.QueryControl;
 public class TestsUIResource {\r
     \r
     public final Resource BrowseContext;\r
+    public final Resource BrowseContext_STSSuiteSorterRule;\r
     public final Resource Contributions;\r
     public final Resource Contributions_NewSTSSuite;\r
     public final Resource Contributions_NewSTSTest;\r
@@ -29,6 +30,7 @@ public class TestsUIResource {
         \r
     public static class URIs {\r
         public static final String BrowseContext = "http://www.simantics.org/TestsUI-1.0/BrowseContext";\r
+        public static final String BrowseContext_STSSuiteSorterRule = "http://www.simantics.org/TestsUI-1.0/BrowseContext/STSSuiteSorterRule";\r
         public static final String Contributions = "http://www.simantics.org/TestsUI-1.0/Contributions";\r
         public static final String Contributions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSSuite";\r
         public static final String Contributions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSTest";\r
@@ -57,6 +59,7 @@ public class TestsUIResource {
     \r
     public TestsUIResource(ReadGraph graph) {\r
         BrowseContext = getResourceOrNull(graph, URIs.BrowseContext);\r
+        BrowseContext_STSSuiteSorterRule = getResourceOrNull(graph, URIs.BrowseContext_STSSuiteSorterRule);\r
         Contributions = getResourceOrNull(graph, URIs.Contributions);\r
         Contributions_NewSTSSuite = getResourceOrNull(graph, URIs.Contributions_NewSTSSuite);\r
         Contributions_NewSTSTest = getResourceOrNull(graph, URIs.Contributions_NewSTSTest);\r
index 0e787d233303517dc0361e7b3057889fb26fdeb5..776eea39ef2df99d34f5e3eba561233ce2c539c3 100644 (file)
@@ -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 (file)
index 0000000..d68f466
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<adapters>\r
\r
+       <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">\r
+               <resource\r
+                       uri="http://www.simantics.org/TestsUI-0.0/BrowseContext/STSSuiteSorterRule"\r
+                       class="org.simantics.tests.modelled.ui.STSSuiteSorterRule" />\r
+       </target>\r
+\r
+</adapters>
\ 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 (file)
index 0000000..bdb55b6
--- /dev/null
@@ -0,0 +1,101 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.tests.modelled.ui;\r
+\r
+import java.util.Collections;\r
+import java.util.Comparator;\r
+import java.util.List;\r
+\r
+import org.simantics.browsing.ui.BuiltinKeys;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.model.browsecontexts.BrowseContext;\r
+import org.simantics.browsing.ui.model.sorters.Sorter;\r
+import org.simantics.browsing.ui.model.sorters.SorterRule;\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.ResourceRead;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.RuntimeDatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.tests.modelled.ontology.TestsResource;\r
+import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
+\r
+public class STSSuiteSorterRule implements SorterRule, Sorter {\r
+\r
+       @Override\r
+       public boolean isCompatible(Class<?> contentType) {\r
+               return contentType.equals(Resource.class);\r
+       }\r
+\r
+       @Override\r
+       public Sorter getSorter(ReadGraph graph, Object content) throws DatabaseException {\r
+               return this;\r
+       }\r
+       \r
+       @Override\r
+       public void sort(ReadGraph graph, BrowseContext context, List<NodeContext> nodes) throws DatabaseException \r
+       {\r
+               try {\r
+                       STSTestComparator stc = new STSTestComparator();\r
+                       stc.graph = graph;\r
+                       Collections.sort(nodes, stc);\r
+               } catch (RuntimeDatabaseException e) {\r
+                       if (e.getCause()!=null && e.getCause() instanceof DatabaseException) throw (DatabaseException) e.getCause();\r
+                       throw e;\r
+               }\r
+       }\r
+       \r
+       static class STSTestQuery extends ResourceRead<Pair<Integer, String>> {\r
+\r
+               public STSTestQuery(Resource resource) {\r
+                       super(resource);\r
+               }\r
+\r
+               @Override\r
+               public Pair<Integer, String> perform(ReadGraph graph) throws DatabaseException {\r
+                       Layer0 L0 = Layer0.getInstance(graph);\r
+                       TestsResource TESTS = TestsResource.getInstance(graph);\r
+                       \r
+                       String name = graph.getRelatedValue2(resource, L0.HasName, Bindings.STRING);\r
+               Integer priority = graph.getRelatedValue2(resource, TESTS.STSTest_executionPriority, Bindings.INTEGER);\r
+\r
+               return new Pair<Integer, String>(priority, name);\r
+           }\r
+\r
+       }\r
+       \r
+       static class STSTestComparator implements Comparator<NodeContext> {\r
+               ReadGraph graph;\r
+\r
+               @Override\r
+               public int compare(NodeContext nc1, NodeContext nc2) {\r
+                       Resource r1 = (Resource) nc1.getConstant(BuiltinKeys.INPUT);\r
+                       Resource r2 = (Resource) nc2.getConstant(BuiltinKeys.INPUT);\r
+                       \r
+                       try {\r
+                               Pair<Integer, String> test1 = graph.sync(new STSTestQuery(r1));\r
+                               Pair<Integer, String> test2 = graph.sync(new STSTestQuery(r2));\r
+\r
+                if (test1.first < test2.first)\r
+                    return -1;\r
+                else if (test1.first > test2.first)\r
+                    return 1;\r
+                else return AlphanumComparator.COMPARATOR.compare(test1.second, test2.second);\r
+                \r
+                       } catch (DatabaseException e) {\r
+                               throw new RuntimeDatabaseException(e);\r
+                       }\r
+               }\r
+       }\r
+}\r
index 188574e545d4d329a0fde8de1a9623bf7a6e0cb5..ad1e2953157a023bc41085f61e85d846cc9dba8f 100644 (file)
@@ -30,6 +30,7 @@ import org.simantics.scl.compiler.runtime.RuntimeModule;
 import org.simantics.scl.osgi.SCLOsgi;\r
 import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler;\r
 import org.simantics.tests.modelled.ontology.TestsResource;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
 \r
 public class STSTestSuiteModel {\r
 \r
@@ -435,9 +436,9 @@ public class STSTestSuiteModel {
                         Collections.sort(tests, (o1, o2) -> {\r
                             if (o1.priority < o2.priority)\r
                                 return -1;\r
-                            if (o1.priority > o2.priority)\r
+                            else if (o1.priority > o2.priority)\r
                                 return 1;\r
-                            return 0;\r
+                            else return AlphanumComparator.COMPARATOR.compare(o1.name, o2.name);\r
                         });\r
                         suite.children(tests.toArray(new STSTest[tests.size()]));\r
                     } else {\r
index c0a5ac342d4ec56a40146ed5f1164a7c62739c82..a86aa41d32c32ac087e7b30370abdc5eed70c31e 100644 (file)
@@ -63,6 +63,10 @@ public class RuntimeSTSTestRunner extends Runner {
         }\r
     }\r
 \r
+    public String getName() {\r
+       return name;\r
+    }\r
+    \r
     public Integer getPriority() {\r
         return priority;\r
     }\r
index 06b81687ec025f1cc17a1bbf5cbb0dbf8155589f..0ab31b3f01a8961ad652f36ca980d4a9a475e8b7 100644 (file)
@@ -18,6 +18,7 @@ import org.simantics.layer0.Layer0;
 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
@@ -60,10 +61,11 @@ public class RuntimeTestCollector {
                                 }\r
                                 \r
                                 testRunners.sort((test1, test2) -> {\r
-                                    if (test1.getPriority() <= test2.getPriority())\r
+                                    if (test1.getPriority() < test2.getPriority())\r
                                         return -1;\r
-                                    else\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