Test client not created

I want to use Zeebe workflow engine in our Spring boot microservice based solution.

I’ve built a very simple test case (number generator, 1 decision step, common output step).
I was pleasantly surprised about JUnit support with native Zeebe rules, but when trying to follow the example at:
https://docs.zeebe.io/java-client/testing.html
with Zeebe 0.21.0, I am facing 2 issues:

  1. I cannot get the client from the rule, it is always null (see code below)
  2. I cannot connect to the broker (getting a “Connection refused: /0.0.0.0:25600”), because it is not started from the test, but according to the docs, it should:

Use the ZeebeTestRule in your test case to start an embedded broker. It contains a client which can be used to deploy a BPMN workflow or create an instance."

Only when I start it externally via docker-compose, I can connect, but my workflow does not progress (only 1st endpoint is called, but that’s a different issue).

Here’s my sample code:

@SpringBootTest.  // not really needed if using Java API to create client manually
@EnableZeebeClient  // probably also not needed
class WorkflowExampleApplicationTests {
    @Rule
    public static final ZeebeTestRule testRule = new ZeebeTestRule();

    @BeforeAll
public static void deploy() {
	//client = testRule.getClient(); // is always null
	final String broker = "0.0.0.0:26500";

	final ZeebeClientBuilder builder =
			ZeebeClient.newClientBuilder().brokerContactPoint(broker).usePlaintext();
	client = builder.build();  // <= this one works

Interestingly, the tests from the official Zeebe distribution work out of the box for me, but I couldn’t yet identify any differences beside them using JUnit 4 and me using JUnit 5 (it’s also hard to strip down to the bare minimum, as the project is quite complex).

Ok that was it, really has to be JUnit 4.x, now the broker works:)

2 Likes

@grexe great to hear that it is all working now, let us know if you find more issues.

Thanks @salaboy, however I’m still struggling to get a test case for the SpringBoot API right - seems to draw in JUnit 5 at some point, and only when I “manually” start the SpringApplication in my test setup method, the services to handle the workflow tasks are created, but still not called.
I’ll open a separate Thread for that later.

1 Like

My SpringBoot application is running the workflow as expected now, but I still cannot get the SpringBootTest to work.

I can either get Spring setting up the context correctly, or Zeebe, but not both.
Is there any example on using spring-zeebe (not the plain Java API) and spring-boot in a test?

I want to test my workflow in an integration test, e.g.:

  1. starting up my spring-boot application context which deploys my workflow, then
  2. injecting the bean into my test and calling an entry point with parameters to trigger workflow execution
  3. validating that the correct workflow steps were executed

An integration test should include zeebe running in the infrastructure not started by the test. Does that make sense? To do that you can use something like test containers framework to start up a zeebe broker using Docker.

HTH