use of org.finos.legend.pure.m3.exception.PureExecutionException in project legend-pure by finos.
the class AbstractTestCast method checkInvalidCastWithTypeParametersErrorMessage.
public void checkInvalidCastWithTypeParametersErrorMessage(Exception e) {
PureException pe = PureException.findPureException(e);
Assert.assertNotNull(pe);
Assert.assertTrue(pe instanceof PureExecutionException);
Assert.assertEquals("Cast exception: List<X> cannot be cast to List<Y>", pe.getInfo());
SourceInformation sourceInfo = pe.getSourceInformation();
Assert.assertNotNull(sourceInfo);
Assert.assertEquals(3, sourceInfo.getLine());
Assert.assertEquals(49, sourceInfo.getColumn());
}
use of org.finos.legend.pure.m3.exception.PureExecutionException in project legend-pure by finos.
the class AbstractTestCast method checkCastErrorMessage.
public void checkCastErrorMessage(Exception e) {
PureException pe = PureException.findPureException(e);
Assert.assertNotNull(pe);
Assert.assertTrue(pe instanceof PureExecutionException);
PureException originalPE = pe.getOriginatingPureException();
Assert.assertNotNull(originalPE);
Assert.assertTrue(originalPE instanceof PureExecutionException);
Assert.assertEquals("Cast exception: A cannot be cast to C", originalPE.getInfo());
SourceInformation sourceInfo = originalPE.getSourceInformation();
Assert.assertNotNull(sourceInfo);
Assert.assertEquals(7, sourceInfo.getLine());
Assert.assertEquals(25, sourceInfo.getColumn());
}
use of org.finos.legend.pure.m3.exception.PureExecutionException in project legend-pure by finos.
the class AbstractTestCast method checkInvalidTypeCastErrorMessage.
public void checkInvalidTypeCastErrorMessage(Exception e, String message, int line, int column) {
PureException pe = PureException.findPureException(e);
Assert.assertNotNull(pe);
Assert.assertTrue(pe instanceof PureExecutionException);
Assert.assertEquals(message, pe.getInfo());
SourceInformation sourceInfo = pe.getSourceInformation();
Assert.assertNotNull(sourceInfo);
Assert.assertEquals(line, sourceInfo.getLine());
Assert.assertEquals(column, sourceInfo.getColumn());
}
use of org.finos.legend.pure.m3.exception.PureExecutionException 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.exception.PureExecutionException 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.");
}
}
Aggregations