Search in sources :

Example 1 with MappingTest

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest in project legend-sdlc by finos.

the class MappingTestCase method doRunTest.

@Override
protected void doRunTest() {
    RichMappingTestResult richMappingTestResult = this.mappingTestRunner.doRunTest();
    MappingTest mappingTest = this.mappingTestRunner.mappingTest;
    if (richMappingTestResult.getResult() == TestResult.FAILURE) {
        String message = "Test failure for mapping test '" + mappingTest.name + "' for Mapping '" + this.entity.getPath() + "'";
        Optional<String> expected = richMappingTestResult.getExpected();
        Optional<String> actual = richMappingTestResult.getActual();
        if (expected.isPresent() || actual.isPresent()) {
            assertEquals(message, expected.orElse(null), actual.orElse(null));
        }
        fail(message);
    } else if (richMappingTestResult.getResult() == TestResult.ERROR) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        richMappingTestResult.getException().printStackTrace(printWriter);
        String stackTraceString = stringWriter.toString();
        fail("Error running mapping test '" + mappingTest.name + "' for Mapping '" + this.entity.getPath() + "' with error stack trace: \n" + stackTraceString + "\n");
    }
}
Also used : StringWriter(java.io.StringWriter) RichMappingTestResult(org.finos.legend.engine.test.runner.mapping.RichMappingTestResult) MappingTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest) PrintWriter(java.io.PrintWriter)

Example 2 with MappingTest

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest in project legend-engine by finos.

the class TestMappingTestRunner method runTest.

private RichMappingTestResult runTest(PureModelContextData pureModelContextData, PureModel pureModel) {
    Mapping mapping = pureModelContextData.getElementsOfType(Mapping.class).get(0);
    MappingTest mappingTest = mapping.tests.get(0);
    MappingTestRunner mappingTestRunner = new MappingTestRunner(pureModel, mapping.getPath(), mappingTest, planExecutor, core_relational_relational_router_router_extension.Root_meta_pure_router_extension_defaultRelationalExtensions__RouterExtension_MANY_(pureModel.getExecutionSupport()), LegendPlanTransformers.transformers, "vX_X_X");
    return mappingTestRunner.setupAndRunTest();
}
Also used : MappingTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest) Mapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping)

Example 3 with MappingTest

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest in project legend-engine by finos.

the class MappingParseTreeWalker method visitMappingTest.

private MappingTest visitMappingTest(MappingParserGrammar.TestContext ctx, Mapping mapping) {
    MappingTest mappingTest = new MappingTest();
    mappingTest.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
    mappingTest.name = ctx.testName().getText();
    // query
    MappingParserGrammar.TestQueryContext testQueryContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.testQuery(), "query", mappingTest.sourceInformation);
    if (testQueryContext.combinedExpression() != null) {
        mappingTest.query = this.visitMappingTestQuery(testQueryContext.combinedExpression(), mapping);
    }
    // input data
    MappingParserGrammar.TestInputDataContext inputDataContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.testInputData(), "data", mappingTest.sourceInformation);
    mappingTest.inputData = inputDataContext.testInput() != null && inputDataContext.testInput().testInputElement() != null ? ListIterate.collect(inputDataContext.testInput().testInputElement(), this::visitMappingTestInputData) : Lists.mutable.empty();
    // assert
    MappingParserGrammar.TestAssertContext testAssertContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.testAssert(), "assert", mappingTest.sourceInformation);
    // NOTE: it's important to have `STRING` before `combinedExpression` since the latter matches the former
    if (testAssertContext.STRING() != null) {
        ExpectedOutputMappingTestAssert expectedOutputMappingTestAssert = new ExpectedOutputMappingTestAssert();
        expectedOutputMappingTestAssert.expectedOutput = PureGrammarParserUtility.fromGrammarString(testAssertContext.STRING().getText(), false);
        expectedOutputMappingTestAssert.sourceInformation = this.walkerSourceInformation.getSourceInformation(testAssertContext);
        mappingTest._assert = expectedOutputMappingTestAssert;
    } else if (testAssertContext.combinedExpression() != null) {
        throw new EngineException("Mapping test currently only support string assertion", this.walkerSourceInformation.getSourceInformation(testAssertContext), EngineErrorType.PARSER);
    }
    return mappingTest;
}
Also used : ExpectedOutputMappingTestAssert(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.ExpectedOutputMappingTestAssert) MappingTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest) MappingParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.mapping.MappingParserGrammar) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)

Aggregations

MappingTest (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.MappingTest)3 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 MappingParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.mapping.MappingParserGrammar)1 Mapping (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping)1 ExpectedOutputMappingTestAssert (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.mappingTest.ExpectedOutputMappingTestAssert)1 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)1 RichMappingTestResult (org.finos.legend.engine.test.runner.mapping.RichMappingTestResult)1