use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Any in project legend-pure by finos.
the class TestPureRuntimeClassMapping method testMilestoningMappingUnbindStability.
@Test
public void testMilestoningMappingUnbindStability() {
String modelTrade = "Class my::Trade{\n" + " id:Integer[1];\n" + " product:my::Product[1];\n" + "}";
String modelProduct = "Class my::Product{\n" + " id:Integer[1];\n" + "}";
String modelProductTemporal = "Class <<temporal.businesstemporal>> my::Product{\n" + " id:Integer[1];\n" + "}";
String storeAndMapping = "###Mapping\n" + "import meta::relational::tests::*;\n" + "import my::*;\n" + "\n" + "Mapping myMapping\n" + "(\n" + " Trade : Relational {id : [myDB] tradeTable.ID, product : [myDB] @trade_product} \n" + " Product : Relational { id : [myDB] productTable.ID}\n" + ")\n" + "###Relational\n" + "Database myDB\n" + "(\n" + " Table tradeTable(ID INT PRIMARY KEY, PRODID INT)\n" + " Table productTable(ID INT PRIMARY KEY)\n" + " \n" + " Join trade_product(tradeTable.PRODID = productTable.ID)\n" + ")";
String f = "function f():Any[0..1]{let m = myMapping}";
RuntimeVerifier.verifyOperationIsStable(new RuntimeTestScriptBuilder().createInMemorySource("modelTrade.pure", modelTrade).createInMemorySource("modelProductTemporal.pure", modelProductTemporal).createInMemorySource("storeAndMapping.pure", storeAndMapping).createInMemorySource("f.pure", f).compile(), new RuntimeTestScriptBuilder().deleteSource("modelProductTemporal.pure").createInMemorySource("modelProduct.pure", modelProduct).compile().deleteSource("modelProduct.pure").createInMemorySource("modelProductTemporal.pure", modelProductTemporal).compile(), this.runtime, this.functionExecution, this.getAdditionalVerifiers());
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Any in project legend-pure by finos.
the class AbstractTestFromJson method multiplicityIsInRange_Association.
@Test
public void multiplicityIsInRange_Association() {
String[] rawAssociationSource = { "import meta::json::*;", "import meta::pure::functions::json::tests::*;", "Association meta::pure::functions::json::tests::Employment", "{", "employer : Firm[1];", "employees : Person[7];", "}", "Class meta::pure::functions::json::tests::Person {}", "Class meta::pure::functions::json::tests::Firm {}", "function Association():Any[*]", "{", // this json describes a Firm with one employee, but the association states all Firms must have exactly 7 employees.
"let json = '{\"employees\":[{\"employer\":{\"employees\":[{}]}}]}';", "$json -> fromJson(Firm, ^meta::json::JSONDeserializationConfig(typeKeyName='@type', failOnUnknownProperties=false));", "}" };
String associationSource = StringUtils.join(rawAssociationSource, "\n") + "\n";
try {
this.compileTestSource("fromString.pure", associationSource);
CoreInstance func = this.runtime.getFunction("Association():Any[*]");
this.functionExecution.start(func, FastList.<CoreInstance>newList());
Assert.fail("Expected exception evaluating: \n" + associationSource);
} catch (PureExecutionException e) {
this.assertException(e, "Error populating property 'employees' on class 'meta::pure::functions::json::tests::Firm': \nExpected value(s) of multiplicity [7], found 1 value(s).");
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Any in project legend-pure by finos.
the class AbstractTestFromJson method testDeserializeNonOneExponentInJsonThrowsError.
@Test
public void testDeserializeNonOneExponentInJsonThrowsError() {
String massDefinition = "Measure pkg::Mass\n" + "{\n" + " *Gram: x -> $x;\n" + " Kilogram: x -> $x*1000;\n" + " Pound: x -> $x*453.59;\n" + "}";
String testSourceStr = "import pkg::*;\n" + massDefinition + "Class A\n" + "{\n" + "myWeight : Mass~Kilogram[1];\n" + "}\n" + "function testUnitToJsonWithType():Any[*]\n" + "{\n" + " let res ='{\"__TYPE\":\"A\",\"myWeight\":{\"unit\":[{\"unitId\":\"pkg::Mass~Kilogram\",\"exponentValue\":3}],\"value\":5}}'->meta::json::fromJson(A, ^meta::json::JSONDeserializationConfig(typeKeyName='@type', failOnUnknownProperties=false));\n" + "}\n";
try {
this.compileTestSource("fromString.pure", testSourceStr);
CoreInstance func = this.runtime.getFunction("testUnitToJsonWithType():Any[*]");
this.functionExecution.start(func, FastList.<CoreInstance>newList());
Assert.fail("Expected exception evaluating: \n" + testSourceStr);
} catch (PureExecutionException e) {
this.assertException(e, "Error populating property 'myWeight' on class 'A': \n" + "Currently non-one exponent for unit is not supported. Got: 3.");
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Any in project legend-pure by finos.
the class AbstractTestFromJson method testFromJsonThrowsValidationErrors_ConstraintOnProperty.
@Test
public void testFromJsonThrowsValidationErrors_ConstraintOnProperty() {
try {
String[] source = { "import meta::json::*;", "Class meta::pure::functions::json::tests::A", "[ TEST_CONTROL: $this.a == 'dave' ]", "{ a:String[1]; }", "Class meta::pure::functions::json::tests::B", "{ b:meta::pure::functions::json::tests::A[1]; }", "function go():Any[*]", "{ let json='{ \"b\": {\"a\": \"fred\" } }'->meta::json::fromJson(meta::pure::functions::json::tests::B, ^meta::json::JSONDeserializationConfig(typeKeyName='@type', failOnUnknownProperties=false));", " assert(!$json->isEmpty(), |''); ", " assert(\'fred\' == $json.b.a, |''); ", "}" };
this.compileTestSource("fromString.pure", StringUtils.join(source, "\n") + "\n");
CoreInstance func = this.runtime.getFunction("go():Any[*]");
this.functionExecution.start(func, FastList.<CoreInstance>newList());
Assert.fail("Expected exception evaluating: \n" + source);
} catch (PureExecutionException e) {
this.assertException(e, "Error populating property 'b' on class 'meta::pure::functions::json::tests::B': \nCould not create new instance of meta::pure::functions::json::tests::A: \nConstraint :[TEST_CONTROL] violated in the Class A");
}
}
use of org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Any in project legend-pure by finos.
the class AbstractTestFromJson method failOnMissingField.
@Test
public void failOnMissingField() {
String[] rawSource = { "import meta::json::*;\nimport meta::pure::functions::json::tests::*;", "Class meta::pure::functions::json::tests::MissingData", "{\n missing : Integer[1];\n}", "function missing():Any[*]", "{\n let json = '{}';", " $json -> fromJson(MissingData, ^meta::json::JSONDeserializationConfig(typeKeyName='@type', failOnUnknownProperties=false));\n}" };
String source = StringUtils.join(rawSource, "\n") + "\n";
try {
this.compileTestSource("fromString.pure", source);
CoreInstance func = this.runtime.getFunction("missing():Any[*]");
this.functionExecution.start(func, FastList.<CoreInstance>newList());
Assert.fail("Expected exception evaluating: \n" + source);
} catch (PureExecutionException e) {
this.assertException(e, "Error populating property 'missing' on class 'meta::pure::functions::json::tests::MissingData': \nExpected value(s) of multiplicity [1], found 0 value(s).");
}
}
Aggregations