Search in sources :

Example 1 with OperationParser

use of org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.OperationParser in project legend-pure by finos.

the class TestEmbeddedGrammar method testEmbeddedMappingWithIds.

@Test
public void testEmbeddedMappingWithIds() {
    Loader.parseM3("import other::*;\n" + "import meta::pure::mapping::*;\n" + "\n" + "Class other::Person\n" + "{\n" + "    name:String[1];\n" + "    firm:Firm[1];\n" + "    address:Address[0..1];\n" + "}\n" + "Class other::Firm\n" + "{\n" + "    legalName:String[1];\n" + "    employees:Person[1];\n" + "    address:Address[1];\n" + "}\n" + "Class other::Address\n" + "{\n" + "    line1:String[1];\n" + "}\n" + "   function meta::pure::router::operations::union(o:OperationSetImplementation[1]):SetImplementation[*]\n" + "   {\n" + "       $o.parameters.setImplementation;\n" + "   }\n" + "###Relational\n" + "Database mapping::db(\n" + "   Table employeeFirmDenormTable\n" + "   (\n" + "    id INT PRIMARY KEY,\n" + "    name VARCHAR(200),\n" + "    firmId INT,\n" + "    legalName VARCHAR(200),\n" + "    address VARCHAR(200)\n" + "   )\n" + "   Table employeeFirmDenormTable2\n" + "   (\n" + "    id INT PRIMARY KEY,\n" + "    name VARCHAR(200),\n" + "    firmId INT,\n" + "    legalName VARCHAR(200),\n" + "    address VARCHAR(200)\n" + "   )\n" + ")\n" + "###Mapping\n" + "import other::*;\n" + "import mapping::*;\n" + "Mapping mappingPackage::myMapping\n" + "(\n" + "    Person[per1]: Relational\n" + "    {\n" + "        name : [db]employeeFirmDenormTable.name,\n" + "        firm\n" + "        (\n" + "            ~primaryKey ([db]employeeFirmDenormTable.legalName)\n" + "            legalName : [db]employeeFirmDenormTable.legalName,\n" + "            address\n" + "            (\n" + "                line1: [db]employeeFirmDenormTable.address\n" + "            )\n" + "        ),\n" + "        address\n" + "        (\n" + "            line1: [db]employeeFirmDenormTable.address\n" + "        )\n" + "    }\n" + "    Person[per2]: Relational\n" + "    {\n" + "        name : [db]employeeFirmDenormTable2.name,\n" + "        firm\n" + "        (\n" + "            ~primaryKey ([db]employeeFirmDenormTable2.legalName)\n" + "            legalName : [db]employeeFirmDenormTable2.legalName,\n" + "            address\n" + "            (\n" + "                line1: [db]employeeFirmDenormTable2.address\n" + "            )\n" + "        ),\n" + "        address\n" + "        (\n" + "            line1: [db]employeeFirmDenormTable2.address\n" + "        )\n" + "    }\n" + "    *Person : Operation\n" + "    {\n" + "               meta::pure::router::operations::union_OperationSetImplementation_1__SetImplementation_MANY_( per1, per2 )   \n" + "    }\n" + ")\n", this.repository, new ParserLibrary(Lists.immutable.with(new M3AntlrParser(), new MappingParser(), new RelationalParser(), new OperationParser())), ValidationType.DEEP, VoidM3M4StateListener.VOID_M3_M4_STATE_LISTENER, this.context);
    this.runtime.compile();
    CoreInstance mapping = this.graphWalker.getMapping("mappingPackage::myMapping");
    assertNotNull(mapping);
    assertEquals(9, this.graphWalker.getClassMappings(mapping).size());
    CoreInstance personMapping = this.graphWalker.getClassMappingById(mapping, "per1");
    validatePersonMapping(personMapping, "employeeFirmDenormTable");
    CoreInstance personMapping2 = this.graphWalker.getClassMappingById(mapping, "per2");
    validatePersonMapping(personMapping2, "employeeFirmDenormTable2");
}
Also used : MappingParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.MappingParser) ParserLibrary(org.finos.legend.pure.m3.serialization.grammar.ParserLibrary) M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) RelationalParser(org.finos.legend.pure.m2.relational.serialization.grammar.v1.RelationalParser) OperationParser(org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.OperationParser) Test(org.junit.Test)

Aggregations

MappingParser (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.MappingParser)1 OperationParser (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.OperationParser)1 RelationalParser (org.finos.legend.pure.m2.relational.serialization.grammar.v1.RelationalParser)1 ParserLibrary (org.finos.legend.pure.m3.serialization.grammar.ParserLibrary)1 M3AntlrParser (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1 Test (org.junit.Test)1