use of org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_SingleExecutionTest 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