Search in sources :

Example 1 with ServiceTest

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.ServiceTest in project legend-engine by finos.

the class ServiceParseTreeWalker method visitTest.

private ServiceTest visitTest(ServiceParserGrammar.ServiceTestContext ctx) {
    if (ctx.singleTest() != null) {
        ServiceParserGrammar.SingleTestContext singleTestContext = ctx.singleTest();
        SingleExecutionTest singleExecutionTest = new SingleExecutionTest();
        singleExecutionTest.sourceInformation = walkerSourceInformation.getSourceInformation(singleTestContext);
        // test data
        ServiceParserGrammar.TestDataContext testDataContext = PureGrammarParserUtility.validateAndExtractRequiredField(singleTestContext.testData(), "data", singleExecutionTest.sourceInformation);
        singleExecutionTest.data = PureGrammarParserUtility.fromGrammarString(testDataContext.STRING().getText(), true);
        // test asserts (optional)
        ServiceParserGrammar.TestAssertsContext assertsContext = PureGrammarParserUtility.validateAndExtractOptionalField(singleTestContext.testAsserts(), "asserts", singleExecutionTest.sourceInformation);
        singleExecutionTest.asserts = assertsContext != null ? ListIterate.collect(assertsContext.testAssert(), this::visitTestContainer) : new ArrayList<>();
        return singleExecutionTest;
    } else if (ctx.multiTest() != null) {
        ServiceParserGrammar.MultiTestContext multiTestContext = ctx.multiTest();
        MultiExecutionTest multiExecutionTest = new MultiExecutionTest();
        multiExecutionTest.sourceInformation = walkerSourceInformation.getSourceInformation(multiTestContext);
        // tests (indexed by execution key)
        multiExecutionTest.tests = ListIterate.collect(multiTestContext.multiTestElement(), this::visitKeyedSingleExecutionTest);
        return multiExecutionTest;
    }
    throw new UnsupportedOperationException();
}
Also used : MultiExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest) KeyedSingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedSingleExecutionTest) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) ArrayList(java.util.ArrayList) ServiceParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.ServiceParserGrammar)

Example 2 with ServiceTest

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.ServiceTest in project legend-engine by finos.

the class HelperServiceGrammarComposer method renderServiceTest.

public static String renderServiceTest(ServiceTest serviceTest, PureGrammarComposerContext context) {
    int baseIndentation = 1;
    if (serviceTest instanceof SingleExecutionTest) {
        SingleExecutionTest singleExecutionTest = (SingleExecutionTest) serviceTest;
        StringBuilder builder = new StringBuilder().append("Single\n");
        appendTabString(builder, baseIndentation).append("{\n");
        appendTabString(builder, baseIndentation + 1).append("data: ").append(convertString(singleExecutionTest.data, true)).append(";\n");
        appendTabString(builder, baseIndentation + 1).append("asserts:\n").append(renderTestContainers(singleExecutionTest.asserts, baseIndentation + 1, context)).append("\n");
        return builder.append(getTabString(baseIndentation)).append("}\n").toString();
    } else if (serviceTest instanceof MultiExecutionTest) {
        MultiExecutionTest multiExecutionTest = (MultiExecutionTest) serviceTest;
        StringBuilder builder = new StringBuilder().append("Multi\n");
        appendTabString(builder, baseIndentation).append("{\n");
        builder.append(LazyIterate.collect(multiExecutionTest.tests, test -> renderKeyedSingleExecution(test, context)).makeString("\n"));
        return builder.append("\n").append(getTabString(baseIndentation)).append("}\n").toString();
    }
    return unsupported(serviceTest.getClass());
}
Also used : PureGrammarComposerUtility.convertString(org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.convertString) KeyedExecutionParameter(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedExecutionParameter) KeyedSingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedSingleExecutionTest) MultiExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest) DEPRECATED_PureGrammarComposerCore(org.finos.legend.engine.language.pure.grammar.to.DEPRECATED_PureGrammarComposerCore) HelperRuntimeGrammarComposer(org.finos.legend.engine.language.pure.grammar.to.HelperRuntimeGrammarComposer) Runtime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime) PureGrammarComposerUtility.unsupported(org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.unsupported) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) ServiceTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.ServiceTest) List(java.util.List) PureMultiExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) PureGrammarComposerContext(org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerContext) PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) PureGrammarComposerUtility.getTabString(org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.getTabString) TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) PureGrammarComposerUtility.appendTabString(org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.appendTabString) Execution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Execution) MultiExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest) KeyedSingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedSingleExecutionTest) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest)

Aggregations

KeyedSingleExecutionTest (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedSingleExecutionTest)2 MultiExecutionTest (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest)2 SingleExecutionTest (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 LazyIterate (org.eclipse.collections.impl.utility.LazyIterate)1 ServiceParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.ServiceParserGrammar)1 DEPRECATED_PureGrammarComposerCore (org.finos.legend.engine.language.pure.grammar.to.DEPRECATED_PureGrammarComposerCore)1 HelperRuntimeGrammarComposer (org.finos.legend.engine.language.pure.grammar.to.HelperRuntimeGrammarComposer)1 PureGrammarComposerContext (org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerContext)1 PureGrammarComposerUtility.appendTabString (org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.appendTabString)1 PureGrammarComposerUtility.convertString (org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.convertString)1 PureGrammarComposerUtility.getTabString (org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.getTabString)1 PureGrammarComposerUtility.unsupported (org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility.unsupported)1 EngineRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime)1 LegacyRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)1 Runtime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime)1 RuntimePointer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer)1 Execution (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Execution)1 KeyedExecutionParameter (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedExecutionParameter)1