diff --git a/showcases/data/Store/Model Store/Mapping/service/basic/code.pure b/showcases/data/Store/Model Store/Mapping/service/basic/code.pure index e336b9946..9a904c3d6 100644 --- a/showcases/data/Store/Model Store/Mapping/service/basic/code.pure +++ b/showcases/data/Store/Model Store/Mapping/service/basic/code.pure @@ -251,7 +251,7 @@ Mapping mapping::ModelToModelMapping }# ]; }, - ExpectedToFail: + IBMData2: { doc: ''; data: @@ -275,7 +275,7 @@ Mapping mapping::ModelToModelMapping ExternalFormat #{ contentType: 'application/json'; - data: '{\n "employees" : [ {\n "fullName" : "John Smith"\n } ],\n "name" : "IBMWhoops",\n "myLegalName()" : "my name is: IBM"\n}'; + data: '{\n "employees" : [ {\n "fullName" : "John Smith"\n } ],\n "name" : "IBM",\n "myLegalName()" : "my name is: IBM"\n}'; }#; }# ]; diff --git a/showcases/pom.xml b/showcases/pom.xml index b1fb5094b..439cd6335 100644 --- a/showcases/pom.xml +++ b/showcases/pom.xml @@ -28,7 +28,33 @@ ${legend.engine.version} test + + org.finos.legend.engine + legend-engine-extensions-collection-execution + ${legend.engine.version} + test + + + + org.finos.legend.engine + legend-engine-test-runner-service + ${legend.engine.version} + test + + + org.finos.legend.engine + legend-engine-test-runner-mapping + ${legend.engine.version} + test + + + org.finos.legend.engine + legend-engine-configuration + ${legend.engine.version} + test + + junit junit diff --git a/showcases/src/test/java/org/example/ShowcaseCompilerTest.java b/showcases/src/test/java/org/example/ShowcaseCompilerTest.java index 2261fc86b..bbb32cf5e 100644 --- a/showcases/src/test/java/org/example/ShowcaseCompilerTest.java +++ b/showcases/src/test/java/org/example/ShowcaseCompilerTest.java @@ -3,12 +3,28 @@ import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.Sets; import org.finos.legend.engine.language.pure.compiler.Compiler; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParser; import org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer; import org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerContext; +import org.finos.legend.engine.language.pure.modelManager.ModelManager; +import org.finos.legend.engine.protocol.pure.v1.ProtocolToClassifierPathLoader; import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; +import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement; +import org.finos.legend.engine.protocol.pure.v1.model.test.assertion.status.AssertFail; +import org.finos.legend.engine.protocol.pure.v1.model.test.assertion.status.AssertionStatus; +import org.finos.legend.engine.protocol.pure.v1.model.test.assertion.status.EqualToJsonAssertFail; +import org.finos.legend.engine.protocol.pure.v1.model.test.result.TestError; +import org.finos.legend.engine.protocol.pure.v1.model.test.result.TestExecuted; +import org.finos.legend.engine.protocol.pure.v1.model.test.result.TestExecutionStatus; +import org.finos.legend.engine.protocol.pure.v1.model.test.result.TestResult; import org.finos.legend.engine.shared.core.api.grammar.RenderStyle; import org.finos.legend.engine.shared.core.deployment.DeploymentMode; +import org.finos.legend.engine.testable.TestableRunner; +import org.finos.legend.engine.testable.extension.TestableRunnerExtensionLoader; +import org.finos.legend.engine.testable.model.RunTestsResult; +import org.finos.legend.engine.testable.model.RunTestsTestableInput; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -16,16 +32,19 @@ import org.junit.runners.Parameterized.Parameters; import java.io.IOException; -import java.nio.file.FileSystems; -import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.PathMatcher; import java.nio.file.Paths; +import java.nio.file.PathMatcher; +import java.nio.file.Files; +import java.nio.file.FileSystems; +import java.util.Collections; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import static org.junit.Assume.assumeFalse; /** @@ -34,6 +53,8 @@ @RunWith(Parameterized.class) public class ShowcaseCompilerTest { + private final Set testableClassifiers = TestableRunnerExtensionLoader.getClassifierPathToTestableRunnerMap().keySet(); + private final Map, String> classifierPathMap = ProtocolToClassifierPathLoader.getProtocolClassToClassifierMap(); private static final PathMatcher PURE_FILE_MATCHER = FileSystems.getDefault().getPathMatcher("glob:*.pure"); @Parameter public Path showcasePath; @@ -89,17 +110,66 @@ public void processShowcaseFile() throws IOException assumeFalse(pureGrammar.isEmpty()); - /* - * TODO: - * - Run all testables within a showcase - */ PureModelContextData pureModelContextData = PureGrammarParser.newInstance().parseModel(pureGrammar, "", 0, 0, true); PureGrammarComposer grammarComposer = PureGrammarComposer.newInstance(PureGrammarComposerContext.Builder.newInstance().withRenderStyle(RenderStyle.PRETTY).build()); // compile - Compiler.compile(pureModelContextData, DeploymentMode.PROD, Lists.mutable.empty()); + PureModel puremodel = Compiler.compile(pureModelContextData, DeploymentMode.PROD, Lists.mutable.empty()); // Grammar composer adds a trailing newline assertEquals(pureGrammar + "\n", grammarComposer.renderPureModelContextData(pureModelContextData)); + + // run tests + runAllTests(puremodel, pureModelContextData); } + + + // TODO Move to legend-engine + public void runAllTests(PureModel puremodel, PureModelContextData data) + { + + for (PackageableElement packageableElement: data.getElements()) + { + Assert.assertTrue("Error getting classifier path for element '" + packageableElement.getPath() + "'", classifierPathMap.containsKey(packageableElement.getClass())); + String classifierPath = classifierPathMap.get(packageableElement.getClass()); + if(testableClassifiers.contains(classifierPath)) + { + TestableRunner runner = new TestableRunner(new ModelManager(DeploymentMode.PROD)); + RunTestsTestableInput runTestsTestableInput = new RunTestsTestableInput(); + runTestsTestableInput.testable = packageableElement.getPath(); + RunTestsResult testsResult = runner.doTests(Collections.singletonList(runTestsTestableInput), puremodel, data); + for (TestResult result: testsResult.results) + { + if (result instanceof TestError) + { + TestError testError = (TestError) result; + fail("Error running test '" + testError.atomicTestId + "' in suite " + testError.testSuiteId + " in testable " + testError.testable + " : " + testError.error); + } + if (result instanceof TestExecuted) { + TestExecuted testExecuted = (TestExecuted) result; + if (testExecuted.testExecutionStatus != TestExecutionStatus.PASS) + { + StringBuilder failMessage = new StringBuilder(); + failMessage.append("Error running test '" + result.atomicTestId + "' in suite " + result.testSuiteId + " in testable " + result.testable + "."); + for(AssertionStatus assertionStatus: testExecuted.assertStatuses) + { + if(assertionStatus instanceof AssertFail) + { + failMessage.append(assertionStatus.id).append(": FAILURE\n").append(((AssertFail) assertionStatus).message); + if (assertionStatus instanceof EqualToJsonAssertFail) + { + EqualToJsonAssertFail fail = (EqualToJsonAssertFail) assertionStatus; + failMessage.append("\nexpected: ").append(fail.expected); + failMessage.append("\nactual: ").append(fail.actual); + } + } + } + Assert.fail(failMessage.toString()); + } + } + } + } + } + } + }