Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/camunda-community-hub/zeebe-worker-java-testutils
Utilities to test Zeebe workers implemented in Java
https://github.com/camunda-community-hub/zeebe-worker-java-testutils
camunda-8 zeebe
Last synced: about 2 months ago
JSON representation
Utilities to test Zeebe workers implemented in Java
- Host: GitHub
- URL: https://github.com/camunda-community-hub/zeebe-worker-java-testutils
- Owner: camunda-community-hub
- License: apache-2.0
- Created: 2021-05-18T08:15:56.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T17:46:31.000Z (about 1 year ago)
- Last Synced: 2024-07-31T20:31:59.084Z (6 months ago)
- Topics: camunda-8, zeebe
- Language: Java
- Size: 178 KB
- Stars: 10
- Watchers: 4
- Forks: 3
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-camunda-platform-8 - Zeebe Worker Java Testutils - Utilities to test Zeebe workers implemented in Java (Testing)
README
[![](https://img.shields.io/badge/Lifecycle-Stable-brightgreen)](https://github.com/Camunda-Community-Hub/community/blob/main/extension-lifecycle.md#stable-)
[![Community extension badge](https://img.shields.io/badge/Community%20Extension-An%20open%20source%20community%20maintained%20project-FF4700)](https://github.com/camunda-community-hub/community)
![Compatible with: Camunda Platform 8](https://img.shields.io/badge/Compatible%20with-Camunda%20Platform%208-0072Ce)
[![Maven Central](https://img.shields.io/maven-central/v/io.zeebe/zeebe-worker-java-testutils.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.zeebe%22%20AND%20a:%22zeebe-worker-java-testutils%22)# Zeebe Worker Java Test Utilities
Utilities to test Zeebe workers implemented in Java.
This library makes the implementation of unit tests for Zeebe workers easier:
```java
public class DivisionHandlerTest {private final DivisionHandler sutDivisionHandler = new DivisionHandler();
@Test
public void shouldDivideFourByTwo() {
// given
final var stubJobClient = new JobClientStub();
final var stubActivatedJob = stubJobClient.createActivatedJob();stubActivatedJob.setInputVariables(Map.of("a", 4L, "b", 2L));
// set other fields as required
// stubActivatedJob.setBpmnProcessId("division_process");
// stubActivatedJob.setRetries(5);
// stubActivatedJob.setWorker("division_worker");
// ...// when
sutDivisionHandler.handle(stubJobClient, stubActivatedJob);// then
assertThat(stubActivatedJob).completed().extractingOutput().containsOnly(entry("result", 2d));
}@Test
public void shouldThrowErrorWhenDividingByZero() {
// given
final var stubJobClient = new JobClientStub();
final var stubActivatedJob = stubJobClient.createActivatedJob();stubActivatedJob.setInputVariables(Map.of("a", 4L, "b", 0L));
// when
sutDivisionHandler.handle(stubJobClient, stubActivatedJob);// then
assertThat(stubActivatedJob)
.threwError()
.hasErrorCode("division-by-zero")
.extractingErrorMessage()
.containsIgnoringCase("cannot divide")
.containsIgnoringCase("by zero");
}@Test
public void shouldFailWhenInputInvalid() {
// given
final var stubJobClient = new JobClientStub();
final var stubActivatedJob = stubJobClient.createActivatedJob();stubActivatedJob.setInputVariables(Map.of("a", 4L, "b", "INVALID INPUT"));
// when
sutDivisionHandler.handle(stubJobClient, stubActivatedJob);// then
assertThat(stubActivatedJob).failed().hasRetries(0).hasErrorMessage("exception occurred");
}
}
```Look at `samples` package to see more examples.
## Things to Know
* calling `requestTimeout(...)` has no effect at all on any of the stubs
* Exceptions thrown by aim to be class-compatible with the original exceptions
* They won't, however, have the exact same messages as the real ones
* Likewise, they have a different caused-by chain very different stacktraces## Contributing
* [Code of Conduct](CODE_OF_CONDUCT.md)
* [Contribution Guide](CONTRIBUTING.md)