Skip to content

Commit

Permalink
add compile phase to TestRelationalElementApi (finos#2307)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari authored Sep 26, 2023
1 parent 367d5db commit c693a42
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-language-pure-modelManager</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-shared-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand All @@ -58,13 +64,16 @@ 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);
Response response = relationalElementAPI.generateModelsFromDatabaseSpecification(inputJson, null);
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}
]
},
Expand Down Expand Up @@ -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": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c693a42

Please sign in to comment.