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