camunda-community-hub / zeebe-spec

A tool to run tests for BPMN processes on Zeebe
Apache License 2.0
29 stars 5 forks source link

feat: JUnit extension injects Zeebe client #224

Closed saig0 closed 1 year ago

saig0 commented 1 year ago

If the test class has a field with the type of the Zeebe client then the JUnit extension injects a Zeebe client for the current test run.

The injection can be used to start an external job worker or a process application for the test run.

@BpmnSpecRunner
class BpmnSpecExtensionInjectionTest(private val specRunner: SpecRunner) {

    private lateinit var zeebeClient: ZeebeClient

    @BeforeEach
    fun `start external worker`() {
        zeebeClient.newWorker()
            .jobType("task-a")
            .handler { client, job ->
                client.newCompleteCommand(job.key)
                    .variables(mapOf("a" to 5))
                    .send()
                    .join()
            }
            .open()
    }

}