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");
}
}
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();
}
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;
}
Aggregations