Class ExternalTaskHandler

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

public class ExternalTaskHandler extends Object
Fluent API to handle external tasks.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExternalTaskHandler(org.camunda.bpm.engine.ProcessEngine processEngine, String activityId, String topicName)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    apply(org.camunda.bpm.engine.runtime.ProcessInstance pi)
     
    void
    Completes the external task, which is locked for 60 seconds by calling complete, using the specified variables and local variables, when the process instance is waiting at the corresponding activity.
    protected void
    complete(org.camunda.bpm.engine.externaltask.ExternalTask task)
     
    Customizes the handler, using the given Consumer function.
    void
    Executes a custom action that handles the external task, when the process instance is waiting at the corresponding activity.
    void
    executeExternalTask(Consumer<org.camunda.bpm.engine.externaltask.ExternalTask> action)
    Executes a custom action that handles the external task, which has been queried (by process instance ID, activity ID and topic name) and locked before, when the process instance is waiting at the corresponding activity.
    void
    executeLockedExternalTask(Consumer<org.camunda.bpm.engine.externaltask.LockedExternalTask> action)
    Executes a custom action that handles the external task, which has been queried (by process instance ID, activity ID and topic name) and locked before, when the process instance is waiting at the corresponding activity.
    void
    handleBpmnError(String errorCode, String errorMessage)
    Continues the execution with an action that calls handleBpmnError using the given error code and message as well as the specified variables.
    protected void
    handleBpmnError(org.camunda.bpm.engine.externaltask.ExternalTask task)
     
    boolean
    Determines if the external task is waiting for a boundary message, signal or timer event.
    verify(BiConsumer<org.camunda.bpm.engine.test.assertions.bpmn.ProcessInstanceAssert,String> verifier)
    Verifies the external task's waiting state.
    verifyTask(BiConsumer<org.camunda.bpm.engine.test.assertions.bpmn.ExternalTaskAssert,Map<String,Object>> taskVerifier)
    Verifies the external task's waiting state.
    void
    Applies no action at the external task's wait state.
    withErrorMessage(String errorMessage)
    Sets the error message, which is used when the next activity is an error boundary event - in this case the handler's action is handleBpmnError.
    Sets a local variable, which is passed to the execution when the default behavior is used.
    Sets local variables, which are passed to the execution when the default behavior is used.
    withLocalVariableTyped(String name, org.camunda.bpm.engine.variable.value.TypedValue value)
    Sets a typed local variable, which is passed to the execution when the default behavior is used.
    withVariable(String name, Object value)
    Sets a variable, which is passed to the execution when a predefined behavior is used.
    Sets variables, which are passed to the execution when a predefined behavior is used.
    withVariableTyped(String name, org.camunda.bpm.engine.variable.value.TypedValue value)
    Sets a typed variable, which is passed to the execution when a predefined behavior is used.
    withWorkerId(String workerId)
    Sets a custom worker ID, which is used for lock, complete and handleBpmnError ExternalTaskService calls.
    protected org.camunda.bpm.engine.externaltask.LockedExternalTask
    wrap(org.camunda.bpm.engine.externaltask.ExternalTask task)
    Wraps the given ExternalTask into a LockedExternalTask.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ExternalTaskHandler

      public ExternalTaskHandler(org.camunda.bpm.engine.ProcessEngine processEngine, String activityId, String topicName)
  • Method Details

    • apply

      protected void apply(org.camunda.bpm.engine.runtime.ProcessInstance pi)
    • complete

      public void complete()
      Completes the external task, which is locked for 60 seconds by calling complete, using the specified variables and local variables, when the process instance is waiting at the corresponding activity. Please note: this is the default behavior.
      See Also:
      • ExternalTaskService.complete(String, String, java.util.Map, java.util.Map)
    • complete

      protected void complete(org.camunda.bpm.engine.externaltask.ExternalTask task)
    • customize

      public ExternalTaskHandler customize(Consumer<ExternalTaskHandler> 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.handleExternalTask().customize(this::prepareExternalTask);
       
      Parameters:
      customizer - A function that accepts a ExternalTaskHandler.
      Returns:
      The handler.
    • execute

      public void execute(Consumer<String> action)
      Executes a custom action that handles the external task, when the process instance is waiting at the corresponding activity.
      Parameters:
      action - A specific action that accepts the related topic name (String).
    • executeExternalTask

      public void executeExternalTask(Consumer<org.camunda.bpm.engine.externaltask.ExternalTask> action)
      Executes a custom action that handles the external task, which has been queried (by process instance ID, activity ID and topic name) and locked before, when the process instance is waiting at the corresponding activity.
      Parameters:
      action - A specific action that accepts an ExternalTask.
      See Also:
      • ExternalTaskService.lock(String, String, long)
    • executeLockedExternalTask

      public void executeLockedExternalTask(Consumer<org.camunda.bpm.engine.externaltask.LockedExternalTask> action)
      Executes a custom action that handles the external task, which has been queried (by process instance ID, activity ID and topic name) and locked before, when the process instance is waiting at the corresponding activity.
      Parameters:
      action - A specific action that accepts an LockedExternalTask.
      See Also:
      • ExternalTaskService.lock(String, String, long)
    • handleBpmnError

      public void handleBpmnError(String errorCode, String errorMessage)
      Continues the execution with an action that calls handleBpmnError using the given error code and message as well as the specified variables.
      Parameters:
      errorCode - The error code of the attached boundary error event.
      errorMessage - An error message or null.
      See Also:
      • ExternalTaskService.handleBpmnError(String, String, String, String, java.util.Map)
    • handleBpmnError

      protected void handleBpmnError(org.camunda.bpm.engine.externaltask.ExternalTask task)
    • isWaitingForBoundaryEvent

      public boolean isWaitingForBoundaryEvent()
      Determines if the external task is waiting for a boundary message, signal or timer event.
      Returns:
      true, if it is waiting for a boundary event. false, if not.
    • verify

      public ExternalTaskHandler verify(BiConsumer<org.camunda.bpm.engine.test.assertions.bpmn.ProcessInstanceAssert,String> verifier)
      Verifies the external task's waiting state.
      Parameters:
      verifier - Verifier that accepts an ProcessInstanceAssert instance and the related topic name (String).
      Returns:
      The handler.
    • verifyTask

      public ExternalTaskHandler verifyTask(BiConsumer<org.camunda.bpm.engine.test.assertions.bpmn.ExternalTaskAssert,Map<String,Object>> taskVerifier)
      Verifies the external task's waiting state.
      Parameters:
      taskVerifier - Verifier that accepts an ExternalTaskAssert instance and the task's local variables.
      Returns:
      The handler.
    • waitForBoundaryEvent

      public void waitForBoundaryEvent()
      Applies no action at the external task's wait state. This is required to wait for events (e.g. message, signal or timer events) that are attached as boundary events on the activity itself or on the surrounding scope (e.g. embedded subprocess).
    • withErrorMessage

      public ExternalTaskHandler withErrorMessage(String errorMessage)
      Sets the error message, which is used when the next activity is an error boundary event - in this case the handler's action is handleBpmnError.
      Parameters:
      errorMessage - An error message or null.
      Returns:
      The handler.
      See Also:
    • withLocalVariable

      public ExternalTaskHandler withLocalVariable(String name, Object value)
      Sets a local variable, which is passed to the execution when the default behavior is used.
      Parameters:
      name - The name of the local variable.
      value - The local variable's value.
      Returns:
      The handler.
      See Also:
    • withLocalVariables

      public ExternalTaskHandler withLocalVariables(Map<String,Object> localVariables)
      Sets local variables, which are passed to the execution when the default behavior is used.
      Parameters:
      localVariables - A map of local variables to set.
      Returns:
      The handler.
      See Also:
    • withLocalVariableTyped

      public ExternalTaskHandler withLocalVariableTyped(String name, org.camunda.bpm.engine.variable.value.TypedValue value)
      Sets a typed local variable, which is passed to the execution when the default behavior is used.
      Parameters:
      name - The name of the local variable.
      value - The local variable's typed value.
      Returns:
      The handler.
      See Also:
    • withVariable

      public ExternalTaskHandler withVariable(String name, Object value)
      Sets a variable, which is passed to the execution when a predefined behavior is used.
      Parameters:
      name - The name of the variable.
      value - The variable's value.
      Returns:
      The handler.
      See Also:
    • withVariables

      public ExternalTaskHandler withVariables(Map<String,Object> variables)
      Sets variables, which are passed to the execution when a predefined behavior is used.
      Parameters:
      variables - A map of variables to set.
      Returns:
      The handler.
      See Also:
    • withVariableTyped

      public ExternalTaskHandler withVariableTyped(String name, org.camunda.bpm.engine.variable.value.TypedValue value)
      Sets a typed variable, which is passed to the execution when a predefined behavior is used.
      Parameters:
      name - The name of the variable.
      value - The variable's typed value.
      Returns:
      The handler.
      See Also:
    • withWorkerId

      public ExternalTaskHandler withWorkerId(String workerId)
      Sets a custom worker ID, which is used for lock, complete and handleBpmnError ExternalTaskService calls. If not set, the default value "bpmndt-worker" is used.
      Parameters:
      workerId - A specific worker ID to use.
      Returns:
      The handler.
    • wrap

      protected org.camunda.bpm.engine.externaltask.LockedExternalTask wrap(org.camunda.bpm.engine.externaltask.ExternalTask task)
      Wraps the given ExternalTask into a LockedExternalTask.
      Parameters:
      task - An external task that has been queried by the handler.
      Returns:
      The wrapped task.