Search in sources :

Example 1 with PureExecutionException

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());
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 2 with PureExecutionException

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());
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 3 with PureExecutionException

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());
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) SourceInformation(org.finos.legend.pure.m4.coreinstance.SourceInformation)

Example 4 with PureExecutionException

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).");
    }
}
Also used : PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Test(org.junit.Test)

Example 5 with PureExecutionException

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.");
    }
}
Also used : PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) Test(org.junit.Test)

Aggregations

PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)111 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)78 Test (org.junit.Test)21 RichIterable (org.eclipse.collections.api.RichIterable)11 SourceInformation (org.finos.legend.pure.m4.coreinstance.SourceInformation)10 PureException (org.finos.legend.pure.m4.exception.PureException)10 JSONObject (org.json.simple.JSONObject)10 SQLException (java.sql.SQLException)9 ListIterable (org.eclipse.collections.api.list.ListIterable)9 Connection (java.sql.Connection)7 BigDecimal (java.math.BigDecimal)6 ConnectionWithDataSourceInfo (org.finos.legend.pure.runtime.java.extension.store.relational.shared.ConnectionWithDataSourceInfo)6 MapCoreInstance (org.finos.legend.pure.runtime.java.interpreted.natives.core.collection.map.MapCoreInstance)6 IOException (java.io.IOException)5 FastList (org.eclipse.collections.impl.list.mutable.FastList)5 PureAssertFailException (org.finos.legend.pure.m3.exception.PureAssertFailException)5 ParseException (org.json.simple.parser.ParseException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Method (java.lang.reflect.Method)4 BigInteger (java.math.BigInteger)4