Search in sources :

Example 1 with RichServiceTestResult

use of org.finos.legend.engine.test.runner.service.RichServiceTestResult in project legend-engine by finos.

the class ServiceModeling method executeTests.

private static TestRun executeTests(Service service, Root_meta_legend_service_metamodel_Service pureService, Pair<PureModelContextData, PureModel> pureModelPairs, String pureVersion, String metricsContext) throws IOException, JavaCompileException {
    MutableList<PlanGeneratorExtension> extensions = Lists.mutable.withAll(ServiceLoader.load(PlanGeneratorExtension.class));
    RichIterable<? extends Root_meta_pure_router_extension_RouterExtension> routerExtensions = extensions.flatCollect(e -> e.getExtraRouterExtensions(pureModelPairs.getTwo()));
    MutableList<PlanTransformer> planTransformers = extensions.flatCollect(PlanGeneratorExtension::getExtraPlanTransformers);
    ServiceTestRunner runner = new ServiceTestRunner(service, pureService, pureModelPairs.getOne(), pureModelPairs.getTwo(), objectMapper, planExecutor, routerExtensions, planTransformers, pureVersion, metricsContext);
    RichServiceTestResult richServiceTestResult = runner.executeTests().get(0);
    Map<String, Boolean> results = Maps.mutable.empty();
    for (Map.Entry<String, org.finos.legend.engine.test.runner.shared.TestResult> entry : richServiceTestResult.getResults().entrySet()) {
        Boolean testResult = entry.getValue().equals(org.finos.legend.engine.test.runner.shared.TestResult.SUCCESS);
        results.put(entry.getKey(), testResult);
    }
    return new SingleTestRun(richServiceTestResult.getExecutionPlan(), new JavaCode(richServiceTestResult.getJavaCodeString()), results);
}
Also used : PlanTransformer(org.finos.legend.engine.plan.generation.transformers.PlanTransformer) ServiceTestRunner(org.finos.legend.engine.test.runner.service.ServiceTestRunner) JavaCode(org.finos.legend.engine.plan.execution.service.test.JavaCode) RichServiceTestResult(org.finos.legend.engine.test.runner.service.RichServiceTestResult) TestResult(org.finos.legend.engine.plan.execution.service.test.TestResult) RichServiceTestResult(org.finos.legend.engine.test.runner.service.RichServiceTestResult) PlanGeneratorExtension(org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension) Map(java.util.Map) SingleTestRun(org.finos.legend.engine.plan.execution.service.test.SingleTestRun)

Example 2 with RichServiceTestResult

use of org.finos.legend.engine.test.runner.service.RichServiceTestResult in project legend-sdlc by finos.

the class ServiceTestCase method handleResults.

private void handleResults(List<RichServiceTestResult> testRun) {
    Set<String> failedAsserts = getFailedServiceAssertIndices(testRun);
    Map<String, Exception> erroringAssertsWithExceptions = getErroringServiceAssertIndicesWithException(testRun);
    if (!failedAsserts.isEmpty() || !erroringAssertsWithExceptions.isEmpty()) {
        fail(failedAsserts.stream().sorted().collect(Collectors.joining(", ", "Failures for " + this.entity.getPath() + ": ", ".\n")).concat(erroringAssertsWithExceptions.entrySet().stream().sorted(Map.Entry.comparingByKey()).map(keyValue -> {
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            keyValue.getValue().printStackTrace(printWriter);
            String stackTraceString = stringWriter.toString();
            return "Errors for " + this.entity.getPath() + ": " + keyValue.getKey() + " with error stack trace: \n" + stackTraceString + "\n";
        }).collect(Collectors.joining("\n", "", ""))));
    }
}
Also used : RichServiceTestResult(org.finos.legend.engine.test.runner.service.RichServiceTestResult) MultiExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest) MutableList(org.eclipse.collections.api.list.MutableList) RichIterable(org.eclipse.collections.api.RichIterable) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Map(java.util.Map) Tuples(org.eclipse.collections.impl.tuple.Tuples) LegendSDLCTestCaseCollector(org.finos.legend.sdlc.test.junit.LegendSDLCTestCaseCollector) PlanTransformer(org.finos.legend.engine.plan.generation.transformers.PlanTransformer) PrintWriter(java.io.PrintWriter) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) StringWriter(java.io.StringWriter) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Root_meta_pure_router_extension_RouterExtension(org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension) Objects(java.util.Objects) Consumer(java.util.function.Consumer) ServiceTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.ServiceTest) List(java.util.List) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) ServiceTestRunner(org.finos.legend.engine.test.runner.service.ServiceTestRunner) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) LegendSDLCTestCase(org.finos.legend.sdlc.test.junit.LegendSDLCTestCase) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Aggregations

Map (java.util.Map)2 PlanTransformer (org.finos.legend.engine.plan.generation.transformers.PlanTransformer)2 RichServiceTestResult (org.finos.legend.engine.test.runner.service.RichServiceTestResult)2 ServiceTestRunner (org.finos.legend.engine.test.runner.service.ServiceTestRunner)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 RichIterable (org.eclipse.collections.api.RichIterable)1 MutableList (org.eclipse.collections.api.list.MutableList)1 Tuples (org.eclipse.collections.impl.tuple.Tuples)1 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)1 JavaCode (org.finos.legend.engine.plan.execution.service.test.JavaCode)1 SingleTestRun (org.finos.legend.engine.plan.execution.service.test.SingleTestRun)1 TestResult (org.finos.legend.engine.plan.execution.service.test.TestResult)1 PlanGeneratorExtension (org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension)1