Package org.camunda.community.bpmndt.api
Class ExternalTaskHandler<T extends ExternalTaskHandler<?>>
java.lang.Object
org.camunda.community.bpmndt.api.ExternalTaskHandler<T>
- Type Parameters:
T- The handler implementation.
- Direct Known Subclasses:
ExternalTaskClientHandler
Fluent API to handle external tasks.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected final org.camunda.bpm.engine.ProcessEngineprotected static final String -
Constructor Summary
ConstructorsConstructorDescriptionExternalTaskHandler(org.camunda.bpm.engine.ProcessEngine processEngine, String activityId, String topicName) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapply(org.camunda.bpm.engine.runtime.ProcessInstance pi) voidcomplete()Completes the locked external task by callingcomplete, using the specified variables and local variables, when the process instance is waiting at the corresponding activity.protected voidcomplete(org.camunda.bpm.engine.externaltask.LockedExternalTask task) Customizes the handler, using the givenConsumerfunction.voidExecutes a custom action that handles the external task, when the process instance is waiting at the corresponding activity.voidexecuteExternalTask(Consumer<org.camunda.bpm.engine.externaltask.ExternalTask> taskAction) 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.voidexecuteLockedExternalTask(Consumer<org.camunda.bpm.engine.externaltask.LockedExternalTask> taskAction) 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.voidhandleBpmnError(String errorCode, String errorMessage) Continues the execution with an action that callshandleBpmnErrorusing the given error code and message as well as the specified variables.protected voidhandleBpmnError(org.camunda.bpm.engine.externaltask.LockedExternalTask task) booleanDetermines 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.voidApplies 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 ishandleBpmnError.withFetchExtensionProperties(boolean fetchExtensionProperties) Specifies if extension properties should be included when an external task is fetched - default:falsewithFetchLocalVariablesOnly(boolean fetchLocalVariablesOnly) Specifies if only local variables should be fetched when an external task is fetched - default:falsewithLocalVariable(String name, Object value) Sets a local variable, which is passed to the execution when the default behavior is used.withLocalVariables(Map<String, Object> localVariables) 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.withLockDuration(long lockDuration) Sets the duration in milliseconds for which the external task should be locked - default:20_000withVariable(String name, Object value) Sets a variable, which is passed to the execution when a predefined behavior is used.withVariables(Map<String, Object> variables) 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 forlock,completeandhandleBpmnErrorExternalTaskServicecalls.
-
Field Details
-
WORKER_ID
- See Also:
-
processEngine
protected final org.camunda.bpm.engine.ProcessEngine processEngine -
fetchExtensionProperties
protected boolean fetchExtensionProperties -
fetchLocalVariablesOnly
protected boolean fetchLocalVariablesOnly
-
-
Constructor Details
-
ExternalTaskHandler
-
-
Method Details
-
apply
protected void apply(org.camunda.bpm.engine.runtime.ProcessInstance pi) -
complete
public void complete()Completes the locked external task by callingcomplete, 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:
-
complete
protected void complete(org.camunda.bpm.engine.externaltask.LockedExternalTask task) -
customize
Customizes the handler, using the givenConsumerfunction. 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 aExternalTaskHandler.- Returns:
- The handler.
-
execute
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> taskAction) 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:
taskAction- A specific action that accepts anExternalTask.- See Also:
-
executeLockedExternalTask
public void executeLockedExternalTask(Consumer<org.camunda.bpm.engine.externaltask.LockedExternalTask> taskAction) 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:
taskAction- A specific action that accepts anLockedExternalTask.- See Also:
-
handleBpmnError
Continues the execution with an action that callshandleBpmnErrorusing 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 ornull.- See Also:
-
handleBpmnError
protected void handleBpmnError(org.camunda.bpm.engine.externaltask.LockedExternalTask 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 T verify(BiConsumer<org.camunda.bpm.engine.test.assertions.bpmn.ProcessInstanceAssert, String> verifier) Verifies the external task's waiting state.- Parameters:
verifier- Verifier that accepts anProcessInstanceAssertinstance and the related topic name (String).- Returns:
- The handler.
-
verifyTask
public T 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 anExternalTaskAssertinstance 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
Sets the error message, which is used when the next activity is an error boundary event - in this case the handler's action ishandleBpmnError.- Parameters:
errorMessage- An error message ornull.- Returns:
- The handler.
- See Also:
-
withFetchExtensionProperties
Specifies if extension properties should be included when an external task is fetched - default:false- Parameters:
fetchExtensionProperties- Include extension properties, if available, or not.- Returns:
- The handler.
- See Also:
-
withFetchLocalVariablesOnly
Specifies if only local variables should be fetched when an external task is fetched - default:false- Parameters:
fetchLocalVariablesOnly- Include only variables of the external task itself, but no variables of parent scopes.- Returns:
- The handler.
- See Also:
-
withLocalVariable
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
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 T 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:
-
withLockDuration
Sets the duration in milliseconds for which the external task should be locked - default:20_000- Parameters:
lockDuration- The lock duration to use, when fetching and locking an external task.- Returns:
- The handler.
- See Also:
-
withVariable
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
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
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
Sets a custom worker ID, which is used forlock,completeandhandleBpmnErrorExternalTaskServicecalls. If not set, the default value "bpmndt-worker" is used.- Parameters:
workerId- A specific worker ID to use.- Returns:
- The handler.
-