Search in sources :

Example 1 with Mapping

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping in project legend-sdlc by finos.

the class LegendPureV1TestCase method executeLegend.

protected Result executeLegend(Lambda lambda, String mappingPath, InputStream inputStream) {
    LambdaFunction<?> pureLambda = HelperValueSpecificationBuilder.buildLambda(lambda, new CompileContext.Builder(this.pureModel).withElement(mappingPath).build());
    Mapping pureMapping = this.pureModel.getMapping(mappingPath);
    SingleExecutionPlan executionPlan = PlanGenerator.generateExecutionPlan(pureLambda, pureMapping, this.runtime, null, this.pureModel, null, PlanPlatform.JAVA, null, this.extensions, this.planTransformers);
    return this.planExecutor.execute(executionPlan, inputStream);
}
Also used : Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) CompileContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext)

Example 2 with Mapping

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping in project legend-sdlc by finos.

the class MappingTestCase method doRunTest.

@Override
protected void doRunTest() {
    RichMappingTestResult richMappingTestResult = this.mappingTestRunner.doRunTest();
    MappingTest mappingTest = this.mappingTestRunner.mappingTest;
    if (richMappingTestResult.getResult() == TestResult.FAILURE) {
        String message = "Test failure for mapping test '" + mappingTest.name + "' for Mapping '" + this.entity.getPath() + "'";
        Optional<String> expected = richMappingTestResult.getExpected();
        Optional<String> actual = richMappingTestResult.getActual();
        if (expected.isPresent() || actual.isPresent()) {
            assertEquals(message, expected.orElse(null), actual.orElse(null));
        }
        fail(message);
    } else if (richMappingTestResult.getResult() == TestResult.ERROR) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        richMappingTestResult.getException().printStackTrace(printWriter);
        String stackTraceString = stringWriter.toString();
        fail("Error running mapping test '" + mappingTest.name + "' for Mapping '" + this.entity.getPath() + "' with error stack trace: \n" + stackTraceString + "\n");
    }
}
Also used : StringWriter(java.io.StringWriter) RichMappingTestResult(org.finos.legend.engine.test.runner.mapping.RichMappingTestResult) MappingTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest) PrintWriter(java.io.PrintWriter)

Example 3 with Mapping

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping in project legend-sdlc by finos.

the class MappingTestCase method collectTestCases.

@LegendSDLCTestCaseCollector(collectorClass = Mapping.class)
public static void collectTestCases(PureModel pureModel, PureModelContextData pureModelContextData, MutableList<PlanTransformer> planTransformers, RichIterable<? extends Root_meta_pure_router_extension_RouterExtension> extensions, String pureVersion, Entity entity, Consumer<? super LegendSDLCTestCase> testCaseConsumer) {
    Mapping mapping = findPackageableElement(pureModelContextData.getElementsOfType(Mapping.class), entity.getPath());
    Optional.ofNullable(mapping.tests).orElse(Collections.emptyList()).stream().map(test -> new MappingTestCase(pureModel, pureModelContextData, mapping, test, planTransformers, extensions, pureVersion)).forEach(testCaseConsumer);
}
Also used : PrintWriter(java.io.PrintWriter) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) MappingTestRunner(org.finos.legend.engine.test.runner.mapping.MappingTestRunner) Mapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping) StringWriter(java.io.StringWriter) MappingTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest) TestResult(org.finos.legend.engine.test.runner.shared.TestResult) MutableList(org.eclipse.collections.api.list.MutableList) Root_meta_pure_router_extension_RouterExtension(org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension) Consumer(java.util.function.Consumer) RichIterable(org.eclipse.collections.api.RichIterable) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) LegendSDLCTestCase(org.finos.legend.sdlc.test.junit.LegendSDLCTestCase) LegendSDLCTestCaseCollector(org.finos.legend.sdlc.test.junit.LegendSDLCTestCaseCollector) Optional(java.util.Optional) RichMappingTestResult(org.finos.legend.engine.test.runner.mapping.RichMappingTestResult) Collections(java.util.Collections) PlanTransformer(org.finos.legend.engine.plan.generation.transformers.PlanTransformer) Mapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping) LegendSDLCTestCaseCollector(org.finos.legend.sdlc.test.junit.LegendSDLCTestCaseCollector)

Example 4 with Mapping

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping in project legend-engine by finos.

the class TestRelationalExecutor method testPlanWitGMTTimeZoneConversionForDateTimeQueryConstant.

@Test
public void testPlanWitGMTTimeZoneConversionForDateTimeQueryConstant() throws IOException {
    String planWithTz = getTemplatePlanWithNoTz().replace("%timeZone%", ",\"timeZone\": \"GMT\"").replace("%templateFunctions%", getFreeMarkerAlloyDateFunction());
    String plan = planWithTz.replace("%dateTimeParam%", "testDateTime = '2014-12-04 15:22:23.123456789'");
    SingleExecutionPlan executionPlan = objectMapper.readValue(plan, SingleExecutionPlan.class);
    RelationalResult result = (RelationalResult) executionPlan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(executionPlan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("{\"builder\": {\"_type\":\"classBuilder\",\"mapping\":\"meta::relational::tests::milestoning::milestoningmap\",\"classMappings\":[{\"setImplementationId\":\"meta_relational_tests_milestoning_ProductSynonym\",\"properties\":[{\"property\":\"synonym\",\"type\":\"String\"},{\"property\":\"type\",\"type\":\"String\"},{\"property\":\"testDate\",\"type\":\"Date\"},{\"property\":\"testDateTime\",\"type\":\"DateTime\"}],\"class\":\"meta::relational::tests::milestoning::ProductSynonym\"}],\"class\":\"meta::relational::tests::milestoning::ProductSynonym\"}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".name as \\\"pk_0\\\", \\\"root\\\".synonym as \\\"pk_1\\\", \\\"root\\\".type as \\\"pk_2\\\", \\\"root\\\".synonym as \\\"synonym\\\", \\\"root\\\".type as \\\"type\\\", \\\"root\\\".testDate as \\\"testDate\\\", \\\"root\\\".testDateTime as \\\"testDateTime\\\", \\\"root\\\".from_z as \\\"k_businessDate\\\" from ProductSynonymTable as \\\"root\\\" where \\\"root\\\".testDateTime = '2014-12-04 15:22:23.123456789'\"}], \"result\" : {\"columns\" : [\"pk_0\",\"pk_1\",\"pk_2\",\"synonym\",\"type\",\"testDate\",\"testDateTime\",\"k_businessDate\"], \"rows\" : [{\"values\": [\"GS-ModA\",\"GS-Mod-S1\",\"STOCK\",\"GS-Mod-S1\",\"STOCK\",\"2015-06-26\",\"2014-12-04T15:22:23.123456789+0000\",\"2015-08-26T00:00:00.000000000+0000\"]}]}}", result.flush(new RelationalResultToJsonDefaultSerializer(result)));
}
Also used : ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) RelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult) RelationalResultToJsonDefaultSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToJsonDefaultSerializer) ExecutionNodeExecutor(org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor) RelationalStoreState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) Test(org.junit.Test)

Example 5 with Mapping

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping in project legend-engine by finos.

the class TestRelationalExecutor method testPlanTimeZoneConversionForDateTimeQueryConstant.

@Test
public void testPlanTimeZoneConversionForDateTimeQueryConstant() throws IOException {
    String planWithTz = getTemplatePlanWithNoTz().replace("%timeZone%", ",\"timeZone\": \"US/Arizona\"").replace("%templateFunctions%", getFreeMarkerAlloyDateFunction());
    String plan = planWithTz.replace("%dateTimeParam%", "testDateTime = '2014-12-04 15:22:23.123456789'");
    SingleExecutionPlan executionPlan = objectMapper.readValue(plan, SingleExecutionPlan.class);
    RelationalResult result = (RelationalResult) executionPlan.rootExecutionNode.accept(new ExecutionNodeExecutor(null, new ExecutionState(Maps.mutable.empty(), Lists.mutable.withAll(executionPlan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(serverPort))))));
    Assert.assertEquals("{\"builder\": {\"_type\":\"classBuilder\",\"mapping\":\"meta::relational::tests::milestoning::milestoningmap\",\"classMappings\":[{\"setImplementationId\":\"meta_relational_tests_milestoning_ProductSynonym\",\"properties\":[{\"property\":\"synonym\",\"type\":\"String\"},{\"property\":\"type\",\"type\":\"String\"},{\"property\":\"testDate\",\"type\":\"Date\"},{\"property\":\"testDateTime\",\"type\":\"DateTime\"}],\"class\":\"meta::relational::tests::milestoning::ProductSynonym\"}],\"class\":\"meta::relational::tests::milestoning::ProductSynonym\"}, \"activities\": [{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".name as \\\"pk_0\\\", \\\"root\\\".synonym as \\\"pk_1\\\", \\\"root\\\".type as \\\"pk_2\\\", \\\"root\\\".synonym as \\\"synonym\\\", \\\"root\\\".type as \\\"type\\\", \\\"root\\\".testDate as \\\"testDate\\\", \\\"root\\\".testDateTime as \\\"testDateTime\\\", \\\"root\\\".from_z as \\\"k_businessDate\\\" from ProductSynonymTable as \\\"root\\\" where \\\"root\\\".testDateTime = '2014-12-04 15:22:23.123456789'\"}], \"result\" : {\"columns\" : [\"pk_0\",\"pk_1\",\"pk_2\",\"synonym\",\"type\",\"testDate\",\"testDateTime\",\"k_businessDate\"], \"rows\" : [{\"values\": [\"GS-ModA\",\"GS-Mod-S1\",\"STOCK\",\"GS-Mod-S1\",\"STOCK\",\"2015-06-26\",\"2014-12-04T22:22:23.123456789+0000\",\"2015-08-26T07:00:00.000000000+0000\"]}]}}", result.flush(new RelationalResultToJsonDefaultSerializer(result)));
}
Also used : ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) RelationalResult(org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult) RelationalResultToJsonDefaultSerializer(org.finos.legend.engine.plan.execution.stores.relational.serialization.RelationalResultToJsonDefaultSerializer) ExecutionNodeExecutor(org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor) RelationalStoreState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)42 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)36 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)25 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)19 ListIterate (org.eclipse.collections.impl.utility.ListIterate)17 List (java.util.List)15 MutableList (org.eclipse.collections.api.list.MutableList)15 SingleExecutionPlan (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan)14 RichIterable (org.eclipse.collections.api.RichIterable)13 FastList (org.eclipse.collections.impl.list.mutable.FastList)13 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)13 ExecutionNodeExecutor (org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor)12 ExecutionState (org.finos.legend.engine.plan.execution.nodes.state.ExecutionState)12 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)12 MappingTest (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest)12 Lambda (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)12 ModelToSchemaGenerationTest (org.finos.legend.engine.external.shared.format.model.test.ModelToSchemaGenerationTest)11 Mapping (org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping)11 Lists (org.eclipse.collections.impl.factory.Lists)10 RelationalStoreExecutionState (org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState)9