From ecb0aaeb3f4377621548a16be4996b92467561ee Mon Sep 17 00:00:00 2001 From: pihme Date: Fri, 16 Oct 2020 14:07:28 +0200 Subject: [PATCH] feat(zeebe-test-runner): Add option to parameterize the Zeebe image to use in the tests --- README.md | 105 +++++++++++++++++- .../bpmnspec/runner/zeebe/ZeebeEnvironment.kt | 7 +- 2 files changed, 102 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 55613a0..de0913d 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,13 @@ A tool to write tests for BPMN workflows. **Features** :sparkles: * business-friendly: the test spec is written in a text format, no coding is required -* vendor independent: the tests can run on any BPMN engine, available integrations: - * [Zeebe](https://github.com/zeebe-io/zeebe) +* vendor independent: the tests can run on any BPMN engine + +Available integrations: + +| Workflow Engine | Test Runner Dependency | +| --- | ---| +| [Zeebe](https://github.com/zeebe-io/zeebe) | `zeebe-test-runner` | ## Usage @@ -221,7 +226,73 @@ Check if the workflow instance has an incident in the given state. If the elemen The tests can be run by calling the [SpecRunner](/core/src/main/kotlin/io/zeebe/bpmnspec/SpecRunner.kt) directly in code, or by using the JUnit integration. -### JUnit Integration +### JUnit Integration (generic) + +1) Add the Maven dependencies: + +``` + + io.zeebe.bpmn-spec + junit-extension + ${bpmn-spec.version} + test + + + + + // test runner implementation for [engine] + +``` + +2) Put the spec and BPMN files in the resource folder (e.g. `/src/test/resources/`) + +3) Write a JUnit test class like the following (here in Kotlin): + +``` +package io.zeebe.bpmn.tck + +import io.zeebe.bpmnspec.junit.BpmnSpecRunner +import io.zeebe.bpmnspec.junit.BpmnSpecSource +import io.zeebe.bpmnspec.junit.BpmnSpecTestCase +import io.zeebe.bpmnspec.junit.SpecRunnerFactory +import io.zeebe.bpmnspec.runner.zeebe.ZeebeTestRunner +import org.assertj.core.api.Assertions +import org.junit.jupiter.params.ParameterizedTest + +@BpmnSpecRunner +class BpmnTest(factory: SpecRunnerFactory) { + + private val specRunner = factory.create(testRunner = MyEngineTestRunner()) + + @ParameterizedTest + @BpmnSpecSource(specResources = ["exclusive-gateway-spec.yaml"]) + fun `exclusive gateway`(spec: BpmnSpecTestCase) { + + val testResult = specRunner.runSingleTestCase(resources = spec.resources, testcase = spec.testCase) + + Assertions.assertThat(testResult.success) + .describedAs("%s%nDetails: %s", testResult.message, testResult.output) + .isTrue() + } + +} +``` + +* annotate the class with `@BpmnSpecRunner` +* create an instance of the `SpecRunner` with the test runner that corresponds to the engine you want to test + * the `SpecRunnerFactory` can be injected in the constructor, a `beforeEach`/`beforeAll` method, or the test method +* annotate the test method with `@ParameterizedTest` and `@BpmnSpecSource` + * the parameter `specResources` lists the spec files to run + * add a method parameter of the type `BpmnSpecTestCase` that holds the resources and the parsed spec +* run the test cases in the test method using `SpecRunner.runSingleTestCase()` and pass the parameter `BpmnSpecTestCase` in it +* verify the test results with the return value + +4) Run the JUnit test class + +![Junit test results](docs/bpmn-spec-junit.png) + + +### JUnit Integration (ZeebeTestRunner) This repository contains an integration for JUnit 5 using the extension API. @@ -244,9 +315,31 @@ This repository contains an integration for JUnit 5 using the extension API. ``` -2) Put the spec and BPMN files in the resource folder (e.g. `/src/test/resources/`) +2) Optionally, specify the image of Zeebe (with enabled Hazelcast exporter) to use for the tests. (if system properties are not set, then defaults will be used) +``` + + [...] + + + + org.apache.maven.plugins + maven-surefire-plugin + + + camunda/zeebe-with-hazelcast-exporter + 0.24.2-0.10.0-alpha1 + + + + + + [...] + +``` -3) Write a JUnit test class like the following (here in Kotlin): +3) Put the spec and BPMN files in the resource folder (e.g. `/src/test/resources/`) + +4) Write a JUnit test class like the following (here in Kotlin): ``` package io.zeebe.bpmn.tck @@ -279,7 +372,7 @@ class BpmnTest(factory: SpecRunnerFactory) { ``` * annotate the class with `@BpmnSpecRunner` -* create an instance of the `SpecRunner` with the test runner that you want to use +* create an instance of the `SpecRunner` with the `ZeebeTestRunner` * the `SpecRunnerFactory` can be injected in the constructor, a `beforeEach`/`beforeAll` method, or the test method * annotate the test method with `@ParameterizedTest` and `@BpmnSpecSource` * the parameter `specResources` lists the spec files to run diff --git a/zeebe-test-runner/src/main/kotlin/io/zeebe/bpmnspec/runner/zeebe/ZeebeEnvironment.kt b/zeebe-test-runner/src/main/kotlin/io/zeebe/bpmnspec/runner/zeebe/ZeebeEnvironment.kt index 9db5e70..aebe56c 100644 --- a/zeebe-test-runner/src/main/kotlin/io/zeebe/bpmnspec/runner/zeebe/ZeebeEnvironment.kt +++ b/zeebe-test-runner/src/main/kotlin/io/zeebe/bpmnspec/runner/zeebe/ZeebeEnvironment.kt @@ -10,13 +10,12 @@ import org.testcontainers.containers.GenericContainer import org.testcontainers.containers.Network import org.testcontainers.containers.wait.strategy.Wait -class ZeebeEnvironment { +class ZeebeEnvironment ( + val zeebeImage : String = System.getProperty("zeebeImage", "camunda/zeebe-with-hazelcast-exporter"), + val zeebeImageVersion : String = System.getProperty("zeebeImageVersion", "0.24.2-0.10.0-alpha1")) { private val logger = LoggerFactory.getLogger(ZeebeTestRunner::class.java) - val zeebeImage = "camunda/zeebe-with-hazelcast-exporter" - val zeebeImageVersion: String = "0.24.2-0.10.0-alpha1" - val zeeqsImage = "camunda/zeeqs" val zeeqsImageVersion: String = "1.0.0-alpha2"