]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/STSSuiteTestCollector.java
Simantics integration STS
[simantics/platform.git] / bundles / org.simantics.tests.modelled / src / org / simantics / tests / modelled / utils / STSSuiteTestCollector.java
index 56d43aec9ad47db272aea9905636ee30e9b20355..e04144f6d003e073cca780f33fb04bd37e6bf9f5 100644 (file)
@@ -7,6 +7,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.regex.Pattern;
 
 import org.simantics.Simantics;
@@ -15,7 +16,9 @@ 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.common.utils.CommonDBUtils;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.QueryIndexUtils;
 import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingUtils;
 import org.simantics.scl.compiler.commands.CommandSession;
@@ -52,7 +55,7 @@ public class STSSuiteTestCollector {
                 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);
+                    List<Resource> stsSuites = QueryIndexUtils.searchByType(graph, sharedOntology, TESTS.STSSuite);
                     for (Resource stsSuite : stsSuites) {
                         try {
                             Collection<Resource> tests = graph.syncRequest(new ObjectsWithType(stsSuite, L0.ConsistsOf, TESTS.STSTest));
@@ -76,7 +79,27 @@ public class STSSuiteTestCollector {
     }
     
 
+    public static void collectTestImports(ReadGraph graph, Resource resource, Set<String> imports) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        TestsResource TESTS = TestsResource.getInstance(graph);
+        if(graph.isInstanceOf(resource, TESTS.STSTest) || graph.isInstanceOf(resource, TESTS.STSSuite)) {
+            for(Resource module : CommonDBUtils.objectsWithType(graph, resource, L0.ConsistsOf, L0.SCLModule)) {
+                String uri = graph.getPossibleURI(module);
+                if(uri != null)
+                    imports.add(uri);
+            }
+            Resource parent = graph.getPossibleObject(resource, L0.PartOf);
+            if(parent != null)
+                collectTestImports(graph, parent, imports);
+        } else if(graph.isInstanceOf(resource, L0.IndexRoot)) {
+            Resource sclMain = CommonDBUtils.getPossibleChild(graph, resource, L0.SCLModule, "SCLMain");
+            if(sclMain != null)
+                imports.add(graph.getURI(sclMain));
+        }
+    }
+    
     public static ModelledSTSTest toModelledTest(ReadGraph graph, Resource test) throws DatabaseException {
+        
         Layer0 L0 = Layer0.getInstance(graph);
         TestsResource TESTS = TestsResource.getInstance(graph);
         String testName = graph.getRelatedValue(test, L0.HasName, Bindings.STRING);
@@ -88,13 +111,17 @@ public class STSSuiteTestCollector {
         String[] actualDeps = dependencies.isEmpty() ? new String[0] : dependencies.split(",");
         
         // collect variables
-        Collection<Resource> stsVariables = graph.getObjects(test, L0.ConsistsOf);
+        Collection<Resource> stsVariables = CommonDBUtils.objectsWithType(graph, test, L0.ConsistsOf, TESTS.STSVariable);
         Map<String, String> variables = new HashMap<>(stsVariables.size());
         for (Resource stsVariable : stsVariables) {
             String name = graph.getRelatedValue(stsVariable, L0.HasName, Bindings.STRING);
             String value = graph.getRelatedValue(stsVariable, TESTS.STSVariable_definition);
             variables.put(name, value);
         }
+        
+        Set<String> imports = new HashSet<>();
+        collectTestImports(graph, test, imports);
+        
         Resource parent = graph.getSingleObject(test, L0.PartOf);
         String parentName;
         String possibleURI = graph.getPossibleURI(parent);
@@ -102,7 +129,8 @@ public class STSSuiteTestCollector {
             parentName = possibleURI;
         else
             parentName = graph.getRelatedValue2(parent, L0.HasName, Bindings.STRING);
-        return new ModelledSTSTest(testName, parentName, code, priority != null ? priority : -1, ignored != null ? ignored : false, new HashSet<>(Arrays.asList(actualDeps)), variables);
+        return new ModelledSTSTest(testName, parentName, code, priority != null ? priority : -1, ignored != null ? ignored : false, imports, new HashSet<>(Arrays.asList(actualDeps)), variables);
+        
     }
 
     public static ModelledSTSSuite toModelledSuite(ReadGraph graph, Resource suite, List<ModelledSTSTest> children) throws DatabaseException {