X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2FTestsGraphUtils.java;h=846261938c090de6f4eefc1724c6ed17a7e06eb3;hb=refs%2Fchanges%2F87%2F3887%2F5;hp=e9ce7d06ff24d775992a896969cb71ccb034a0a7;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/TestsGraphUtils.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/TestsGraphUtils.java index e9ce7d06f..846261938 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/TestsGraphUtils.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/TestsGraphUtils.java @@ -3,12 +3,14 @@ package org.simantics.tests.modelled; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.regex.Pattern; import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.utils.NameUtils; @@ -27,34 +29,54 @@ import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.runtime.reporting.SCLReportingHandler; import org.simantics.tests.modelled.ontology.TestsResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class TestsGraphUtils { + private static final Logger LOGGER = LoggerFactory.getLogger(TestsGraphUtils.class); + private static final String STS_TEST_PREFIX = "STSTest"; private static final String STS_SUITE_PREFIX = "STSSuite"; - + private static final String STS_VARIABLE_PREFIX = "STSVariable"; + private TestsGraphUtils() {} - + + public static Resource createSTSVariable(WriteGraph graph, Resource parent) throws DatabaseException { + String name = NameUtils.findFreshEscapedName(graph, STS_VARIABLE_PREFIX, parent); + Resource stsVariable = graph.newResource(); + + Layer0 L0 = Layer0.getInstance(graph); + TestsResource TESTS = TestsResource.getInstance(graph); + + graph.claim(parent, L0.ConsistsOf, L0.PartOf, stsVariable); + graph.claim(stsVariable, L0.InstanceOf, TESTS.STSVariable); + graph.claimLiteral(stsVariable, L0.HasName, name, Bindings.STRING); + graph.claimLiteral(stsVariable, TESTS.STSVariable_definition, "", Bindings.STRING); + return stsVariable; + } + public static Resource createSTSTest(WriteGraph graph, Resource parent) throws DatabaseException { String name = NameUtils.findFreshEscapedName(graph, STS_TEST_PREFIX, parent); Resource stsTest = graph.newResource(); - + Layer0 L0 = Layer0.getInstance(graph); TestsResource TESTS = TestsResource.getInstance(graph); - + graph.claim(parent, L0.ConsistsOf, L0.PartOf, stsTest); graph.claim(stsTest, L0.InstanceOf, TESTS.STSTest); graph.claimLiteral(stsTest, L0.HasName, name, Bindings.STRING); graph.claimLiteral(stsTest, TESTS.STSTest_definition, "", Bindings.STRING); return stsTest; } - + public static Resource createSTSSuite(WriteGraph graph, Resource parent) throws DatabaseException { String name = NameUtils.findFreshEscapedName(graph, STS_SUITE_PREFIX, parent); Resource stsSuite = graph.newResource(); - + Layer0 L0 = Layer0.getInstance(graph); TestsResource TESTS = TestsResource.getInstance(graph); - + graph.claim(parent, L0.ConsistsOf, L0.PartOf, stsSuite); graph.claim(stsSuite, L0.InstanceOf, TESTS.STSSuite); graph.claimLiteral(stsSuite, L0.HasName, name, Bindings.STRING); @@ -62,11 +84,11 @@ public class TestsGraphUtils { } public static CombinedCoverage runSTSTestDefinition(String definition, List moduleNameFilters, SCLReportingHandler handler) throws IOException { - + // ModuleRepository repo = SCLOsgi.MODULE_REPOSITORY; ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY); repo.setAdvisor(new ModuleCompilationOptionsAdvisor() { - + @Override public ModuleCompilationOptions getOptions(String moduleName) { boolean coverage = false; @@ -79,13 +101,13 @@ public class TestsGraphUtils { return new ModuleCompilationOptions(coverage); } }); - + CommandSession session = new CommandSession(repo, handler); TestScriptExecutor executor = new TestScriptExecutor(session, new BufferedReader(new StringReader(definition)), handler); try { executor.execute(); } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("Failed to execute test definition:\n{}", definition, t); } Collection runtimeModules = session.getRuntimeEnvironment().getRuntimeModules(); List modules = new ArrayList<>(runtimeModules.size()); @@ -95,4 +117,11 @@ public class TestsGraphUtils { CombinedCoverage coverage = CoverageUtils.getCoverage(modules); return coverage; } + + public static byte[] stsTestContentDump(ReadGraph graph, Resource test) throws DatabaseException { + TestsResource TESTS = TestsResource.getInstance(graph); + String def = graph.getRelatedValue(test, TESTS.STSTest_definition, Bindings.STRING); + return def.getBytes(StandardCharsets.UTF_8); + } + }