Class JobHandler

java.lang.Object
org.camunda.community.bpmndt.api.JobHandler

public class JobHandler extends Object
Fluent API to handle jobs in form of service, script, send or business rule tasks as well as intermediate message throw or message end events.

Please note: a job is not completed by default. The application must run an appropriate worker, which completes relates jobs or throws a BPMN error. If a worker implementation is missing, complete(), throwBpmnError(String, String) or execute(BiConsumer) can be used to handle the job.
  • Constructor Details

  • Method Details

    • complete

      public void complete()
      Executes an action that completes the job, when the process instance is waiting at the corresponding element, using specified variables.
      See Also:
    • customize

      public JobHandler customize(Consumer<JobHandler> customizer)
      Customizes the handler, using the given Consumer function. This method can be used to apply a common customization needed for different test cases.
       tc.handleJob().customize(this::prepare);
       
      Parameters:
      customizer - A function that accepts a JobHandler.
      Returns:
      The handler.
    • execute

      public void execute(BiConsumer<io.camunda.zeebe.client.ZeebeClient,Long> action)
      Executes a custom action that handles the job, when the process instance is waiting at the corresponding element.
      Parameters:
      action - A specific action that accepts a ZeebeClient and the related job key.
      See Also:
      • JobClient.newCompleteCommand(long)
    • throwBpmnError

      public void throwBpmnError(String errorCode, String errorMessage)
      Throws an BPMN error using the given error code and message as well as the specified variables.

      This action can be used, if there is no related registered job worker yet.

      See Also:
    • verify

      public JobHandler verify(Consumer<io.camunda.zeebe.process.test.assertions.ProcessInstanceAssert> verifier)
      Verifies the job's waiting state.

      Please note: An application specific job worker may have already completed the related job and updated some variables.

      Parameters:
      verifier - Verifier that accepts an ProcessInstanceAssert instance.
      Returns:
      The handler.
    • verifyRetries

      public JobHandler verifyRetries(Integer expectedRetries)
      Verifies that the job has a specific number of retries.
      Parameters:
      expectedRetries - The expected retry count.
      Returns:
      The handler.
    • verifyRetries

      public JobHandler verifyRetries(Consumer<Integer> retriesConsumer)
      Verifies that the job has a specific number of retries, using a consumer.
      Parameters:
      retriesConsumer - A consumer asserting the retry count.
      Returns:
      The handler.
    • verifyRetriesExpression

      public JobHandler verifyRetriesExpression(Consumer<String> retriesExpressionConsumer)
      Verifies that the job has a specific "retries" FEEL expression (see "Task definition" section), using a consumer function.
      Parameters:
      retriesExpressionConsumer - A consumer asserting the "retries" expression.
      Returns:
      The handler.
    • verifyType

      public JobHandler verifyType(String expectedType)
      Verifies that the job is of the given type.
      Parameters:
      expectedType - The expected type.
      Returns:
      The handler.
    • verifyType

      public JobHandler verifyType(Consumer<String> typeConsumer)
      Verifies that the job is of the given type, using a consumer.
      Parameters:
      typeConsumer - A consumer asserting the type.
      Returns:
      The handler.
    • verifyTypeExpression

      public JobHandler verifyTypeExpression(Consumer<String> typeExpressionConsumer)
      Verifies that the job has a specific type FEEL expression (see "Task definition" section), using a consumer function.
      Parameters:
      typeExpressionConsumer - A consumer asserting the type expression.
      Returns:
      The handler.
    • waitForBoundaryEvent

      public void waitForBoundaryEvent()
      Applies no action at the wait state. This is required when waiting for events (e.g. message, signal or timer events) that are attached as boundary events on the element itself or on the surrounding scope (e.g. embedded subprocess).
    • withVariable

      public JobHandler withVariable(String name, Object value)
      Sets a variable that is used to complete the job.
      Parameters:
      name - The name of the variable.
      value - The variable's value.
      Returns:
      The handler.
      See Also:
    • withVariables

      public JobHandler withVariables(Object variables)
      Sets an object as variables that is used to complete the job.
      Parameters:
      variables - The variables as POJO.
      Returns:
      The handler.
      See Also:
    • withVariableMap

      public JobHandler withVariableMap(Map<String,Object> variableMap)
      Sets variables that are used to complete the job.
      Parameters:
      variableMap - A map of variables.
      Returns:
      The handler.
      See Also: