use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest 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.MultiExecutionTest 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());
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest in project legend-engine by finos.
the class ServiceTestRunner method executeTests.
public List<RichServiceTestResult> executeTests() throws IOException, JavaCompileException {
Execution serviceExecution = this.service.execution;
if (serviceExecution instanceof PureMultiExecution) {
List<RichServiceTestResult> results = Lists.mutable.empty();
try (Scope scope = GlobalTracer.get().buildSpan("Generate Tests And Run For MultiExecution Service").startActive(true)) {
MutableMap<String, KeyedExecutionParameter> executionsByKey = Iterate.groupByUniqueKey(((PureMultiExecution) serviceExecution).executionParameters, e -> e.key);
for (KeyedSingleExecutionTest es : ((MultiExecutionTest) service.test).tests) {
List<TestContainer> asserts = es.asserts;
KeyedExecutionParameter e = executionsByKey.get(es.key);
PureMultiExecution pureExecution = (PureMultiExecution) service.execution;
PureSingleExecution pureSingleExecution = new PureSingleExecution();
pureSingleExecution.func = pureExecution.func;
pureSingleExecution.mapping = e.mapping;
pureSingleExecution.runtime = e.runtime;
pureSingleExecution.executionOptions = e.executionOptions;
String noAssertMessage = "No test assert found for key - " + es.key + "!!";
RichServiceTestResult richServiceTestResult = executeSingleExecutionTest(pureSingleExecution, es.data, asserts, noAssertMessage, pureModelContextData, pureModel, scope);
richServiceTestResult.setOptionalMultiExecutionKey(es.key);
results.add(richServiceTestResult);
}
return results;
}
} else if (serviceExecution instanceof PureSingleExecution) {
try (Scope scope = GlobalTracer.get().buildSpan("Generate Single Pure Tests And Run").startActive(true)) {
List<TestContainer> asserts = ((SingleExecutionTest) service.test).asserts;
String noAssertMessage = "No test assert found !!";
return Collections.singletonList(executeSingleExecutionTest((PureSingleExecution) service.execution, ((SingleExecutionTest) service.test).data, asserts, noAssertMessage, pureModelContextData, pureModel, scope));
}
} else {
try (Scope scope = GlobalTracer.get().buildSpan("Generate Extra Service Execution Tests and Run").startActive(true)) {
MutableList<ServiceExecutionExtension> serviceExecutionExtensions = Lists.mutable.withAll(ServiceLoader.load(ServiceExecutionExtension.class));
Pair<ExecutionPlan, RichIterable<? extends String>> testExecutor = getExtraServiceExecutionPlan(serviceExecutionExtensions, serviceExecution, ((Root_meta_legend_service_metamodel_SingleExecutionTest) this.pureService._test())._data());
ExecutionPlan executionPlan = testExecutor.getOne();
Assert.assertTrue(executionPlan instanceof SingleExecutionPlan, () -> "Only Single Execution Plan supported");
List<TestContainer> containers = getExtraServiceTestContainers(serviceExecutionExtensions, service.test);
return Collections.singletonList(executeTestAsserts((SingleExecutionPlan) executionPlan, containers, testExecutor.getTwo(), scope));
}
}
}
Aggregations