From c693a4267e88ee033331933a7483d14b7679d3f0 Mon Sep 17 00:00:00 2001 From: Mauricio Uyaguari Date: Mon, 25 Sep 2023 23:03:07 -0400 Subject: [PATCH] add compile phase to TestRelationalElementApi (#2307) --- .../pom.xml | 5 + .../test/TestRelationalElementApi.java | 13 ++- .../src/test/resources/expectedJson.json | 102 ++++++++++++++++++ .../src/test/resources/inputGrammar.pure | 4 + 4 files changed, 122 insertions(+), 2 deletions(-) diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/pom.xml b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/pom.xml index 3b19ddf9553..af9d43d3c45 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/pom.xml +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/pom.xml @@ -193,6 +193,11 @@ test-jar test + + org.finos.legend.engine + legend-engine-language-pure-modelManager + test + org.finos.legend.engine legend-engine-shared-core diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/java/org/finos/legend/engine/language/pure/relational/api/relationalElement/test/TestRelationalElementApi.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/java/org/finos/legend/engine/language/pure/relational/api/relationalElement/test/TestRelationalElementApi.java index 09fce618a0b..595c970b544 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/java/org/finos/legend/engine/language/pure/relational/api/relationalElement/test/TestRelationalElementApi.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/java/org/finos/legend/engine/language/pure/relational/api/relationalElement/test/TestRelationalElementApi.java @@ -14,13 +14,16 @@ package org.finos.legend.engine.language.pure.relational.api.relationalElement.test; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.io.IOUtils; import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParser; +import org.finos.legend.engine.language.pure.modelManager.ModelManager; import org.finos.legend.engine.language.pure.relational.api.relationalElement.RelationalElementAPI; import org.finos.legend.engine.language.pure.relational.api.relationalElement.input.DatabaseToModelGenerationInput; import org.finos.legend.engine.protocol.Protocol; import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer; +import org.finos.legend.engine.shared.core.ObjectMapperFactory; import org.finos.legend.engine.shared.core.deployment.DeploymentMode; import org.junit.Assert; import org.junit.Test; @@ -33,7 +36,10 @@ public class TestRelationalElementApi { - private static PureModelContextData compilePmcd(String model) + private final ObjectMapper objectMapper = ObjectMapperFactory.getNewStandardObjectMapperWithPureProtocolExtensionSupports(); + private final ModelManager testManager = new ModelManager(DeploymentMode.TEST); + + private static PureModelContextData buildPMCDFromString(String model) { return PureModelContextData.newBuilder() .withPureModelContextData(PureGrammarParser.newInstance().parseModel(model)) @@ -58,7 +64,7 @@ public void shouldGenerateModelsFromDatabaseSpecification() throws IOException String inputGrammar = loadFromFile("inputGrammar.pure"); Assert.assertNotNull(expectedJson); Assert.assertNotNull(inputGrammar); - PureModelContextData inputPmcd = compilePmcd(inputGrammar); + PureModelContextData inputPmcd = buildPMCDFromString(inputGrammar); String databasePath = "meta::relational::transform::autogen::tests::testDB"; DatabaseToModelGenerationInput inputJson = new DatabaseToModelGenerationInput(databasePath, inputPmcd, null); RelationalElementAPI relationalElementAPI = new RelationalElementAPI(DeploymentMode.PROD, null); @@ -66,5 +72,8 @@ public void shouldGenerateModelsFromDatabaseSpecification() throws IOException Assert.assertNotNull(response); String actualJson = response.getEntity().toString(); JsonAssert.assertJsonEquals(expectedJson, actualJson); + // compile generated model and input database + PureModelContextData pureModelContextData = objectMapper.readValue(actualJson, PureModelContextData.class).combine(inputPmcd); + testManager.loadModelAndData(pureModelContextData, pureModelContextData.serializer.version, null, null); } } diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/resources/expectedJson.json b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/resources/expectedJson.json index 68c813ce72d..71272afa9fd 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/resources/expectedJson.json +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/resources/expectedJson.json @@ -688,6 +688,76 @@ } } ] + }, + { + "mainTable": { + "schema": "SCHEMA3", + "database": "meta::relational::transform::autogen::tests::testDB", + "_type": "table", + "mainTableDb": "meta::relational::transform::autogen::tests::testDB", + "table": "Company" + }, + "root": true, + "propertyMappings": [ + { + "relationalOperation": { + "_type": "column", + "column": "name", + "tableAlias": "Company", + "table": { + "schema": "SCHEMA3", + "database": "meta::relational::transform::autogen::tests::testDB", + "_type": "table", + "mainTableDb": "meta::relational::transform::autogen::tests::testDB", + "table": "Company" + } + }, + "_type": "relationalPropertyMapping", + "property": { + "property": "name", + "class": "meta::relational::transform::autogen::tests::SCHEMA3::Company" + }, + "target": "" + }, + { + "relationalOperation": { + "_type": "column", + "column": "location", + "tableAlias": "Company", + "table": { + "schema": "SCHEMA3", + "database": "meta::relational::transform::autogen::tests::testDB", + "_type": "table", + "mainTableDb": "meta::relational::transform::autogen::tests::testDB", + "table": "Company" + } + }, + "_type": "relationalPropertyMapping", + "property": { + "property": "location", + "class": "meta::relational::transform::autogen::tests::SCHEMA3::Company" + }, + "target": "" + } + ], + "_type": "relational", + "distinct": false, + "id": "meta_relational_transform_autogen_tests_SCHEMA3_Company", + "class": "meta::relational::transform::autogen::tests::SCHEMA3::Company", + "primaryKey": [ + { + "_type": "column", + "column": "name", + "tableAlias": "Company", + "table": { + "schema": "SCHEMA3", + "database": "meta::relational::transform::autogen::tests::testDB", + "_type": "table", + "mainTableDb": "meta::relational::transform::autogen::tests::testDB", + "table": "Company" + } + } + ] } ] }, @@ -891,6 +961,38 @@ } ] }, + { + "taggedValues": [ + { + "tag": { + "profile": "meta::pure::profiles::doc", + "value": "doc" + }, + "value": "Generated Element" + } + ], + "package": "meta::relational::transform::autogen::tests::SCHEMA3", + "_type": "class", + "name": "Company", + "properties": [ + { + "multiplicity": { + "upperBound": 1, + "lowerBound": 1 + }, + "name": "name", + "type": "String" + }, + { + "multiplicity": { + "upperBound": 1, + "lowerBound": 1 + }, + "name": "location", + "type": "String" + } + ] + }, { "taggedValues": [ { diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/resources/inputGrammar.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/resources/inputGrammar.pure index 98b31fbec04..a2e48ecb384 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/resources/inputGrammar.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-api/src/test/resources/inputGrammar.pure @@ -13,6 +13,10 @@ Database meta::relational::transform::autogen::tests::testDB ( Table Company(name VARCHAR(200) PRIMARY KEY, location VARCHAR(200) NOT NULL) ) + Schema SCHEMA3 + ( + Table Company(name VARCHAR(200) PRIMARY KEY, location VARCHAR(200) NOT NULL) + ) Join CompanyEmployee(testSchema1.Company.location != 'Toronto' and testSchema1.Employee.fullname = 'John Doe' and testSchema1.Company.name = testSchema1.Employee.firmname) Join EmployeeCity(testSchema1.Employee.location = testSchema1.City.name) Join EmployeePassport(testSchema1.Employee.passportId = testSchema1.Passport.passportId)